From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4vJO-0002wF-Mc for qemu-devel@nongnu.org; Fri, 24 Aug 2012 10:56:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4vJH-0006tN-T5 for qemu-devel@nongnu.org; Fri, 24 Aug 2012 10:56:38 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:51256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4vJH-0006tF-ME for qemu-devel@nongnu.org; Fri, 24 Aug 2012 10:56:31 -0400 Received: by eaac13 with SMTP id c13so615004eaa.4 for ; Fri, 24 Aug 2012 07:56:30 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <5037949E.9080606@redhat.com> Date: Fri, 24 Aug 2012 16:50:06 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1345801763-24227-1-git-send-email-qemulist@gmail.com> <1345801763-24227-6-git-send-email-qemulist@gmail.com> In-Reply-To: <1345801763-24227-6-git-send-email-qemulist@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 05/10] qdev: finalize of qbus, qdev will not the right place to free children List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: Liu Ping Fan , qemu-devel@nongnu.org, Anthony Liguori , Avi Kivity Il 24/08/2012 11:49, Liu Ping Fan ha scritto: > From: Liu Ping Fan > > When breaking big lock, the child object can be hold by mmio-dispatch, > and it is not right to free them when their parent gone. > We will isolate and release the children by qdev_delete_subtree(), > and let each object manage its own life cycle. I think this makes sense, but is it already working at this point of the series? That is, before patch 7 starts using qdev_delete_subtree()? Paolo > Signed-off-by: Liu Ping Fan > --- > hw/qdev.c | 30 ++++++++++++------------------ > 1 files changed, 12 insertions(+), 18 deletions(-) > > diff --git a/hw/qdev.c b/hw/qdev.c > index 570f0bf..d6c8130 100644 > --- a/hw/qdev.c > +++ b/hw/qdev.c > @@ -756,10 +756,8 @@ static void device_finalize(Object *obj) > DeviceClass *dc = DEVICE_GET_CLASS(dev); > > if (dev->state == DEV_STATE_INITIALIZED) { > - while (dev->num_child_bus) { > - bus = QLIST_FIRST(&dev->child_bus); > - qbus_free(bus); > - } > + > + g_assert(QLIST_EMPTY(&dev->child_bus)); > if (qdev_get_vmsd(dev)) { > vmstate_unregister(dev, qdev_get_vmsd(dev), dev); > } > @@ -770,9 +768,8 @@ static void device_finalize(Object *obj) > qemu_opts_del(dev->opts); > } > } > - if (dev->parent_bus) { > - bus_remove_child(dev->parent_bus, dev); > - } > + > + g_assert((dev->parent_bus == NULL)); > } > > static void device_class_base_init(ObjectClass *class, void *data) > @@ -826,19 +823,16 @@ static void qbus_initfn(Object *obj) > static void qbus_finalize(Object *obj) > { > BusState *bus = BUS(obj); > - BusChild *kid; > > - while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) { > - DeviceState *dev = kid->child; > - qdev_free(dev); > - } > - if (bus->parent) { > - QLIST_REMOVE(bus, sibling); > - bus->parent->num_child_bus--; > - } else { > - assert(bus != sysbus_get_default()); /* main_system_bus is never freed */ > - qemu_unregister_reset(qbus_reset_all_fn, bus); > + assert(bus != sysbus_get_default()); /* main_system_bus is never freed */ > + /* just blind check, since bus->parent has been set to NULL */ > + qemu_unregister_reset(qbus_reset_all_fn, bus); > + if (bus->overlap != NULL) { > + object_unref(OBJECT(bus->overlap)); > } > + assert(QTAILQ_EMPTY(&bus->children)); > + /* have reset it to NULL, to prevent reader */ > + assert((bus->parent == NULL)); > g_free((char *)bus->name); > } > >