Patchwork qdev: Check if unplug handler exists before calling it

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

Comments

Amit Shah - Nov. 2, 2009, 6:27 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 checking if the callback is valid

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/qdev.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Gerd Hoffmann - Nov. 2, 2009, 9:18 a.m.
On 11/02/09 07:27, 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.

Which would be a clear bug in the bus implementation.

> +    if (!dev->info->unplug) {

assert(dev->info->unplug != NULL) ?

cheers,
   Gerd

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 374d2d0..1a9eb2e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -258,6 +258,11 @@  int qdev_unplug(DeviceState *dev)
                    dev->parent_bus->name);
         return -1;
     }
+    if (!dev->info->unplug) {
+        qemu_error("Unplug event for bus %s not defined\n",
+                   dev->parent_bus->name);
+        return -1;
+    }
     return dev->info->unplug(dev);
 }