Received: from eggs.gnu.org ([208.118.235.92]:37968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUy-0001gn-Lk for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgcUg-0003ZN-FC for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:08 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53291 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUg-0003Yy-6M for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:50 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 18 Jun 2012 15:59:12 +0200 Message-Id: <1340027954-19045-21-git-send-email-afaerber@suse.de> In-Reply-To: <1340027954-19045-1-git-send-email-afaerber@suse.de> References: <1340027954-19045-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 20/22] qbus: Initialize in standard way List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori From: Anthony Liguori Move code to an initfn and finalizer. Replace do_qbus_create_inplace() with qbus_realize(). Signed-off-by: Anthony Liguori Signed-off-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- hw/qdev.c | 80 ++++++++++++++++++++++++++++++++++++-------------------= ----- 1 files changed, 48 insertions(+), 32 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index fc79b24..38ca581 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -410,40 +410,35 @@ DeviceState *qdev_find_recursive(BusState *bus, con= st char *id) return NULL; } =20 -/* FIXME move this logic into instance_init */ -static void do_qbus_create_inplace(BusState *bus, const char *typename, - DeviceState *parent, const char *name= ) +static void qbus_realize(BusState *bus) { + const char *typename =3D object_get_typename(OBJECT(bus)); char *buf; int i,len; =20 - bus->parent =3D parent; - - if (name) { + if (bus->name) { /* use supplied name */ - bus->name =3D g_strdup(name); - } else if (parent && parent->id) { + } else if (bus->parent && bus->parent->id) { /* parent device has id -> use it for bus name */ - len =3D strlen(parent->id) + 16; + len =3D strlen(bus->parent->id) + 16; buf =3D g_malloc(len); - snprintf(buf, len, "%s.%d", parent->id, parent->num_child_bus); + snprintf(buf, len, "%s.%d", bus->parent->id, bus->parent->num_ch= ild_bus); bus->name =3D buf; } else { /* no id -> use lowercase bus type for bus name */ len =3D strlen(typename) + 16; buf =3D g_malloc(len); len =3D snprintf(buf, len, "%s.%d", typename, - parent ? parent->num_child_bus : 0); + bus->parent ? bus->parent->num_child_bus : 0); for (i =3D 0; i < len; i++) buf[i] =3D qemu_tolower(buf[i]); bus->name =3D buf; } =20 - QTAILQ_INIT(&bus->children); - if (parent) { - QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling); - parent->num_child_bus++; - object_property_add_child(OBJECT(parent), bus->name, OBJECT(bus)= , NULL); + if (bus->parent) { + QLIST_INSERT_HEAD(&bus->parent->child_bus, bus, sibling); + bus->parent->num_child_bus++; + object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT= (bus), NULL); } else if (bus !=3D sysbus_get_default()) { /* TODO: once all bus devices are qdevified, only reset handler for main_system_bus should be registered h= ere. */ @@ -455,7 +450,10 @@ void qbus_create_inplace(BusState *bus, const char *= typename, DeviceState *parent, const char *name) { object_initialize(bus, typename); - do_qbus_create_inplace(bus, typename, parent, name); + + bus->parent =3D parent; + bus->name =3D name ? g_strdup(name) : NULL; + qbus_realize(bus); } =20 BusState *qbus_create(const char *typename, DeviceState *parent, const c= har *name) @@ -464,26 +462,16 @@ BusState *qbus_create(const char *typename, DeviceS= tate *parent, const char *nam =20 bus =3D BUS(object_new(typename)); bus->qom_allocated =3D true; - do_qbus_create_inplace(bus, typename, parent, name); + + bus->parent =3D parent; + bus->name =3D name ? g_strdup(name) : NULL; + qbus_realize(bus); + return bus; } =20 void qbus_free(BusState *bus) { - BusChild *kid; - - while ((kid =3D QTAILQ_FIRST(&bus->children)) !=3D NULL) { - DeviceState *dev =3D kid->child; - qdev_free(dev); - } - if (bus->parent) { - QLIST_REMOVE(bus, sibling); - bus->parent->num_child_bus--; - } else { - assert(bus !=3D sysbus_get_default()); /* main_system_bus is nev= er freed */ - qemu_unregister_reset(qbus_reset_all_fn, bus); - } - g_free((void*)bus->name); if (bus->qom_allocated) { object_delete(OBJECT(bus)); } else { @@ -770,12 +758,40 @@ static TypeInfo device_type_info =3D { .class_size =3D sizeof(DeviceClass), }; =20 +static void qbus_initfn(Object *obj) +{ + BusState *bus =3D BUS(obj); + + QTAILQ_INIT(&bus->children); +} + +static void qbus_finalize(Object *obj) +{ + BusState *bus =3D BUS(obj); + BusChild *kid; + + while ((kid =3D QTAILQ_FIRST(&bus->children)) !=3D NULL) { + DeviceState *dev =3D kid->child; + qdev_free(dev); + } + if (bus->parent) { + QLIST_REMOVE(bus, sibling); + bus->parent->num_child_bus--; + } else { + assert(bus !=3D sysbus_get_default()); /* main_system_bus is nev= er freed */ + qemu_unregister_reset(qbus_reset_all_fn, bus); + } + g_free((char *)bus->name); +} + static const TypeInfo bus_info =3D { .name =3D TYPE_BUS, .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(BusState), .abstract =3D true, .class_size =3D sizeof(BusClass), + .instance_init =3D qbus_initfn, + .instance_finalize =3D qbus_finalize, }; =20 static void qdev_register_types(void) --=20 1.7.7