From: Paolo Bonzini <pbonzini@redhat.com>
To: Amos Kong <akong@redhat.com>
Cc: hutao@cn.fujitsu.com, Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org, aliguori@amazon.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH v2] qdev: add the device to the QOM tree before using it to set a link
Date: Mon, 20 Jan 2014 13:47:55 +0100 [thread overview]
Message-ID: <52DD1AFB.6030002@redhat.com> (raw)
In-Reply-To: <1388624531-13439-1-git-send-email-akong@redhat.com>
Il 02/01/2014 02:02, Amos Kong ha scritto:
> 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.
>
> This patch moves qdev_set_parent_bus() back to object_property_add_child(),
> we only needs to unref the object if setting properties fails.
>
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
> V2: fix bz by adjust the initialization order (Paolo)
> ---
> qdev-monitor.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index dc37a43..4070b0a 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -518,16 +518,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> /* create device, set properties */
> dev = DEVICE(object_new(driver));
>
> - if (bus) {
> - qdev_set_parent_bus(dev, bus);
> - }
> -
> id = qemu_opts_id(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;
> }
> @@ -541,6 +536,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> OBJECT(dev), NULL);
> g_free(name);
> }
> +
> + if (bus) {
> + qdev_set_parent_bus(dev, bus);
> + }
> +
> object_property_set_bool(OBJECT(dev), true, "realized", &err);
> if (err != NULL) {
> qerror_report_err(err);
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
next prev parent reply other threads:[~2014-01-20 12:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-02 1:02 [Qemu-devel] [PATCH v2] qdev: add the device to the QOM tree before using it to set a link Amos Kong
2014-01-20 12:47 ` Paolo Bonzini [this message]
2014-01-20 13:12 ` Markus Armbruster
2014-02-17 10:23 ` Amos Kong
2014-02-17 11:44 ` Andreas Färber
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=52DD1AFB.6030002@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=akong@redhat.com \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=hutao@cn.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.