From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbwjG-0006W2-7g for qemu-devel@nongnu.org; Fri, 23 Nov 2012 12:07:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbwjF-0006QV-3T for qemu-devel@nongnu.org; Fri, 23 Nov 2012 12:07:50 -0500 Received: from cantor2.suse.de ([195.135.220.15]:53939 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbwjE-0006QP-Qb for qemu-devel@nongnu.org; Fri, 23 Nov 2012 12:07:49 -0500 Message-ID: <50AFAD61.4040907@suse.de> Date: Fri, 23 Nov 2012 18:07:45 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1353660436-8897-1-git-send-email-pbonzini@redhat.com> <1353660436-8897-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1353660436-8897-5-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, qemu-devel@nongnu.org, Liu Ping Fan Am 23.11.2012 09:47, schrieb Paolo Bonzini: > All conditional deallocation can now be done with object_delete. > Remove the @qom_allocated and @glib_allocated fields; replace the latte= r > with a direct assignment of the @free function pointer. >=20 > Signed-off-by: Paolo Bonzini I am grateful for your suggestion to clean up this mess! However... > --- > hw/pci.c | 2 +- > hw/qdev-core.h | 5 ----- > hw/qdev.c | 10 +--------- > hw/sysbus.c | 2 +- > 4 files changed, 3 insertions(+), 16 deletions(-) >=20 > diff --git a/hw/pci.c b/hw/pci.c > index 9841e39..97a0cd7 100644 > --- a/hw/pci.c > +++ b/hw/pci.c > @@ -301,9 +301,9 @@ PCIBus *pci_bus_new(DeviceState *parent, const char= *name, > PCIBus *bus; > =20 > bus =3D g_malloc0(sizeof(*bus)); > - bus->qbus.glib_allocated =3D true; > pci_bus_new_inplace(bus, parent, name, address_space_mem, > address_space_io, devfn_min); > + OBJECT(bus)->free =3D g_free; Anthony asked not to use the macros like this, but in this case to have Object *obj; to assign it after g_malloc0() and use obj->free =3D g_free; here. > return bus; > } > =20 > diff --git a/hw/qdev-core.h b/hw/qdev-core.h > index fce9e22..fff7f0f 100644 > --- a/hw/qdev-core.h > +++ b/hw/qdev-core.h > @@ -106,17 +106,12 @@ typedef struct BusChild { > =20 > /** > * BusState: > - * @qom_allocated: Indicates whether the object was allocated by QOM. > - * @glib_allocated: Indicates whether the object was initialized in-pl= ace > - * yet is expected to be freed with g_free(). > */ > struct BusState { > Object obj; > DeviceState *parent; > const char *name; > int allow_hotplug; > - bool qom_allocated; > - bool glib_allocated; > int max_index; > QTAILQ_HEAD(ChildrenHead, BusChild) children; > QLIST_ENTRY(BusState) sibling; > diff --git a/hw/qdev.c b/hw/qdev.c > index f43717b..788b4da 100644 > --- a/hw/qdev.c > +++ b/hw/qdev.c > @@ -454,7 +454,6 @@ BusState *qbus_create(const char *typename, DeviceS= tate *parent, const char *nam > BusState *bus; > =20 > bus =3D BUS(object_new(typename)); > - bus->qom_allocated =3D true; > =20 > bus->parent =3D parent; > bus->name =3D name ? g_strdup(name) : NULL; > @@ -465,14 +464,7 @@ BusState *qbus_create(const char *typename, Device= State *parent, const char *nam > =20 > void qbus_free(BusState *bus) > { > - if (bus->qom_allocated) { > - object_delete(OBJECT(bus)); > - } else { > - object_finalize(OBJECT(bus)); > - if (bus->glib_allocated) { > - g_free(bus); > - } > - } > + object_delete(OBJECT(bus)); In this case ("free") I have no objection to using "delete" for simplification. ;) > } > =20 > static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) > diff --git a/hw/sysbus.c b/hw/sysbus.c > index 4969f06..ef8ffb6 100644 > --- a/hw/sysbus.c > +++ b/hw/sysbus.c > @@ -274,7 +274,7 @@ static void main_system_bus_create(void) > main_system_bus =3D g_malloc0(system_bus_info.instance_size); > qbus_create_inplace(main_system_bus, TYPE_SYSTEM_BUS, NULL, > "main-system-bus"); > - main_system_bus->glib_allocated =3D true; > + OBJECT(main_system_bus)->free =3D g_free; Same here. > object_property_add_child(container_get(qdev_get_machine(), > "/unattached"), > "sysbus", OBJECT(main_system_bus), NULL)= ; >=20 Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg