Skip to contentSkip to conversation

qdev: Check if unplug handler exists before calling it

PATCH In review Amit Shah 2 participants 2 messages Nov 2, 2009

lore
Share & tools
lore

Amit Shah

author
#0 lore raw

PATCH 1/1 qdev: Check if unplug handler exists before calling it

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

---
 hw/qdev.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/qdev.c +5 -0
index 374d2d0..1a9eb2e 100644
@@ -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);
 }
 
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 3 lines · Amit Shah

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.

Quoted 1 line

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

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

cheers,
Gerd