qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: hutao@cn.fujitsu.com, pbonzini@redhat.com, armbru@redhat.com,
	aliguori@amazon.com, afaerber@suse.de
Subject: [Qemu-devel] [PCTCH v4] qdev: set properties after device's parent is assigned
Date: Mon,  3 Mar 2014 23:55:24 +0800	[thread overview]
Message-ID: <1393862124-26806-1-git-send-email-akong@redhat.com> (raw)

Test steps:
 (qemu) device_add e1000,addr=adsf
  Property 'e1000.addr' doesn't take value 'adsf'
 (qemu) info qtree
  Then qemu crashed.

Currently we set a link to the new device for qdev parent bus, but the
device hasn't been added to QOM tree. When it fails to set properties,
object_unparent() can't cleanup the device.

Delay device property setting until device's parent is assigned. This
way when property setting fails, object_unparent() can cleanup failed
device properly.

Signed-off-by: Amos Kong <akong@redhat.com>
Reviewed-By: Igor Mammedov <imammedo@redhat.com>
---
V2: fix bz by adjust the initialization order (Paolo)
V3: fix bug without making it differs with legacy devices
    creation (Andreas)
V4: update subject and commitlog
---
 qdev-monitor.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 6673e3c..9268c87 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -522,7 +522,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
-    /* create device, set properties */
+    /* create device */
     dev = DEVICE(object_new(driver));
 
     if (bus) {
@@ -533,11 +533,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     if (id) {
         dev->id = id;
     }
-    if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {
-        object_unparent(OBJECT(dev));
-        object_unref(OBJECT(dev));
-        return NULL;
-    }
+
     if (dev->id) {
         object_property_add_child(qdev_get_peripheral(), dev->id,
                                   OBJECT(dev), NULL);
@@ -549,6 +545,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         g_free(name);
     }
 
+    /* set properties */
+    if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {
+        object_unparent(OBJECT(dev));
+        object_unref(OBJECT(dev));
+        return NULL;
+    }
+
     dev->opts = opts;
     object_property_set_bool(OBJECT(dev), true, "realized", &err);
     if (err != NULL) {
-- 
1.8.5.3

             reply	other threads:[~2014-03-03 15:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-03 15:55 Amos Kong [this message]
2014-03-03 16:01 ` [Qemu-devel] [PCTCH v4] qdev: set properties after device's parent is assigned Andreas Färber
2014-03-03 16:15   ` Amos Kong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393862124-26806-1-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=hutao@cn.fujitsu.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).