From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5EGw-0001Qq-6c for qemu-devel@nongnu.org; Mon, 20 Jan 2014 07:48:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5EGn-0003mK-OO for qemu-devel@nongnu.org; Mon, 20 Jan 2014 07:48:10 -0500 Received: from mail-qc0-x22a.google.com ([2607:f8b0:400d:c01::22a]:50647) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5EGn-0003mG-JR for qemu-devel@nongnu.org; Mon, 20 Jan 2014 07:48:01 -0500 Received: by mail-qc0-f170.google.com with SMTP id e9so5990417qcy.29 for ; Mon, 20 Jan 2014 04:48:01 -0800 (PST) Sender: Paolo Bonzini Message-ID: <52DD1AFB.6030002@redhat.com> Date: Mon, 20 Jan 2014 13:47:55 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1388624531-13439-1-git-send-email-akong@redhat.com> In-Reply-To: <1388624531-13439-1-git-send-email-akong@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: Amos Kong Cc: hutao@cn.fujitsu.com, Markus Armbruster , qemu-devel@nongnu.org, aliguori@amazon.com, afaerber@suse.de 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 > --- > 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