[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/6] Make qdev_init() destroy the device on failure
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 2/6] Make qdev_init() destroy the device on failure |
Date: |
Fri, 11 Sep 2009 22:19:17 +0200 |
Before, every caller had to do this. Only two actually did.
Signed-off-by: Markus Armbruster <address@hidden>
---
hw/isa-bus.c | 1 -
hw/qdev.c | 11 +++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 4ecc0f8..fb90be4 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -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;
diff --git a/hw/qdev.c b/hw/qdev.c
index 6451b8a..107acd8 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -202,8 +202,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
qdev_free(qdev);
return NULL;
}
- if (qdev_init(qdev) != 0) {
- qdev_free(qdev);
+ if (qdev_init(qdev) < 0) {
return NULL;
}
return qdev;
@@ -211,14 +210,18 @@ DeviceState *qdev_device_add(QemuOpts *opts)
/* 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;
rc = dev->info->init(dev, dev->info);
- if (rc < 0)
+ if (rc < 0) {
+ qdev_free(dev);
return rc;
+ }
if (dev->info->reset)
qemu_register_reset(dev->info->reset, dev);
if (dev->info->vmsd)
--
1.6.2.5
- [Qemu-devel] [PATCH 0/6] Clean up use of qdev_init(), Markus Armbruster, 2009/09/11
- [Qemu-devel] [PATCH 4/6] New qdev_init_nofail(), Markus Armbruster, 2009/09/11
- [Qemu-devel] [PATCH 6/6] Warn if value of qdev_init() isn't checked, Markus Armbruster, 2009/09/11
- [Qemu-devel] [PATCH 3/6] Check return value of qdev_init(), Markus Armbruster, 2009/09/11
- [Qemu-devel] [PATCH 2/6] Make qdev_init() destroy the device on failure,
Markus Armbruster <=
- [Qemu-devel] [PATCH 5/6] Make isa_create() terminate program on failure, Markus Armbruster, 2009/09/11
- [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Markus Armbruster, 2009/09/11
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Blue Swirl, 2009/09/12
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Edgar E. Iglesias, 2009/09/12
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Gerd Hoffmann, 2009/09/14
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Edgar E. Iglesias, 2009/09/14
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Blue Swirl, 2009/09/14
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Markus Armbruster, 2009/09/14
- Re: [Qemu-devel] [PATCH 1/6] Move function definitions out of xilinx.h, Blue Swirl, 2009/09/14
Re: [Qemu-devel] [PATCH 0/6] Clean up use of qdev_init(), Gerd Hoffmann, 2009/09/14