]> git.proxmox.com Git - qemu.git/commitdiff
Make qdev_init() destroy the device on failure
authorMarkus Armbruster <armbru@redhat.com>
Tue, 6 Oct 2009 23:15:56 +0000 (01:15 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 7 Oct 2009 13:54:53 +0000 (08:54 -0500)
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>
hw/isa-bus.c
hw/qdev.c

index 4ecc0f839967056d76838a0d82334e8395eb8211..fb90be4e50ab089c3d27adde6567d4b5b4df2bcb 100644 (file)
@@ -127,7 +127,6 @@ ISADevice *isa_create_simple(const char *name)
 
     dev = isa_create(name);
     if (qdev_init(&dev->qdev) != 0) {
-        qdev_free(&dev->qdev);
         return NULL;
     }
     return dev;
index 253e255647a797dbfbc225451ba2055fdc04c1e4..8a620010681b979ef19a37b047136978c617994d 100644 (file)
--- 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);