Skip to content

Commit

Permalink
qdev-monitor: Inline qdev_init() for device_add
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
afaerber committed Nov 5, 2013
1 parent 2bcb0c6 commit 852e2c5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qdev-monitor.c
Expand Up @@ -458,6 +458,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) {
Expand Down Expand Up @@ -540,7 +541,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;
Expand Down

0 comments on commit 852e2c5

Please sign in to comment.