From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFLMP-0003qC-8a for qemu-devel@nongnu.org; Mon, 17 Feb 2014 05:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFLMJ-0006xa-9q for qemu-devel@nongnu.org; Mon, 17 Feb 2014 05:23:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56023) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFLMJ-0006xV-0W for qemu-devel@nongnu.org; Mon, 17 Feb 2014 05:23:31 -0500 Date: Mon, 17 Feb 2014 18:23:24 +0800 From: Amos Kong Message-ID: <20140217102324.GA1925@amosk.info> References: <1388624531-13439-1-git-send-email-akong@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1388624531-13439-1-git-send-email-akong@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2] qdev: add the device to the QOM tree before using it to set a link List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, afaerber@suse.de, aliguori@amazon.com, hutao@cn.fujitsu.com On Thu, Jan 02, 2014 at 09:02:11AM +0800, Amos Kong wrote: > 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 > --- > V2: fix bz by adjust the initialization order (Paolo) Hi Anthony, other maintainer The V2 already reviewed and tested by Markus. Can you help to review & apply it? Thanks, Amos > --- > 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); > -- > 1.8.4.2 >