Patchwork [PULL,50/58] qdev-monitor: Inline qdev_init() for device_add

login
register
mail settings
Submitter Andreas Färber
Date Oct. 8, 2013, 5:44 p.m.
Message ID <1381254296-3203-51-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/281577/
State New
Headers show

Comments

Andreas Färber - Oct. 8, 2013, 5:44 p.m.
For historic reasons, qdev_init() unparents the device on failure.
Inline this to make the error paths clearer and consistent.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 qdev-monitor.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Patch

diff --git a/qdev-monitor.c b/qdev-monitor.c
index f259e07..b7daab7 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -449,6 +449,7 @@  DeviceState *qdev_device_add(QemuOpts *opts)
     const char *driver, *path, *id;
     DeviceState *dev;
     BusState *bus = NULL;
+    Error *err = NULL;
 
     driver = qemu_opt_get(opts, "driver");
     if (!driver) {
@@ -531,7 +532,11 @@  DeviceState *qdev_device_add(QemuOpts *opts)
                                   OBJECT(dev), NULL);
         g_free(name);
     }
-    if (qdev_init(dev) < 0) {
+    object_property_set_bool(OBJECT(dev), true, "realized", &err);
+    if (err != NULL) {
+        qerror_report_err(err);
+        error_free(err);
+        object_unparent(OBJECT(dev));
         object_unref(OBJECT(dev));
         qerror_report(QERR_DEVICE_INIT_FAILED, driver);
         return NULL;