summary refs log tree commit diff stats
path: root/hw/qdev.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2009-10-07 01:15:56 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-07 08:54:53 -0500
commit18cfeb52d17825dddadfc74e99255530aa889136 (patch)
tree532b36d74abb74846aa9815a2bd07cc773808fd3 /hw/qdev.c
parent05a91699292dbb814c37d55da72fd35fa2a686a2 (diff)
downloadfocaccia-qemu-18cfeb52d17825dddadfc74e99255530aa889136.tar.gz
focaccia-qemu-18cfeb52d17825dddadfc74e99255530aa889136.zip
Make qdev_init() destroy the device on failure
Before, every caller had to do this.  Only two actually did.

Patchworks-ID: 35170
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev.c')
-rw-r--r--hw/qdev.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/hw/qdev.c b/hw/qdev.c
index 253e255647..8a62001068 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -216,7 +216,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
     if (qdev_init(qdev) != 0) {
         qemu_error("Error initializing device %s\n", driver);
-        qdev_free(qdev);
         return NULL;
     }
     qdev->opts = opts;
@@ -232,15 +231,19 @@ static void qdev_reset(void *opaque)
 
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
-   calling this function.  */
+   calling this function.
+   On failure, destroy the device and return negative value.
+   Return 0 on success.  */
 int qdev_init(DeviceState *dev)
 {
     int rc;
 
     assert(dev->state == DEV_STATE_CREATED);
     rc = dev->info->init(dev, dev->info);
-    if (rc < 0)
+    if (rc < 0) {
+        qdev_free(dev);
         return rc;
+    }
     qemu_register_reset(qdev_reset, dev);
     if (dev->info->vmsd)
         vmstate_register(-1, dev->info->vmsd, dev);