Patchwork qdev: Check if unplug handler exists before calling it

login
register
mail settings
Submitter Amit Shah
Date Nov. 2, 2009, 9:26 a.m.
Message ID <1257154001-15403-1-git-send-email-amit.shah@redhat.com>
Download mbox | patch
Permalink /patch/37401/
State New
Headers show

Comments

Amit Shah - Nov. 2, 2009, 9:26 a.m.
A bus may have hotplugging enabled but not have the 'unplug'
callback defined, which would lead to a crash on trying to
unplug a device on the bus.

Fix by introducing an assert to check if the callback is valid.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/qdev.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Gerd Hoffmann - Nov. 2, 2009, 9:58 a.m.
On 11/02/09 10:26, Amit Shah wrote:
> A bus may have hotplugging enabled but not have the 'unplug'
> callback defined, which would lead to a crash on trying to
> unplug a device on the bus.
>
> Fix by introducing an assert to check if the callback is valid.
>
> Signed-off-by: Amit Shah<amit.shah@redhat.com>

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
   Gerd

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index c7884d0..d19d531 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -258,6 +258,8 @@  int qdev_unplug(DeviceState *dev)
                    dev->parent_bus->name);
         return -1;
     }
+    assert(dev->info->unplug != NULL);
+
     return dev->info->unplug(dev);
 }