From patchwork Sun Aug 26 15:51:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 180103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9266D2C00D2 for ; Mon, 27 Aug 2012 09:36:40 +1000 (EST) Received: from localhost ([::1]:48680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5m6b-0008DD-4I for incoming@patchwork.ozlabs.org; Sun, 26 Aug 2012 19:18:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5m5J-0004uH-Ue for qemu-devel@nongnu.org; Sun, 26 Aug 2012 19:17:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T5m5H-0003eP-OU for qemu-devel@nongnu.org; Sun, 26 Aug 2012 19:17:37 -0400 Received: from cpe-70-123-140-180.austin.res.rr.com ([70.123.140.180]:50521 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5m5H-0003cZ-FI for qemu-devel@nongnu.org; Sun, 26 Aug 2012 19:17:35 -0400 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id q7QFpk3h005194; Sun, 26 Aug 2012 10:51:46 -0500 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q7QFpjMa005187; Sun, 26 Aug 2012 10:51:45 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sun, 26 Aug 2012 10:51:32 -0500 Message-Id: <1345996298-4892-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> References: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.140.180 Cc: Paolo Bonzini , Anthony Liguori , Liu Ping Fan , Andreas Faerber Subject: [Qemu-devel] [PATCH 3/9] qbus: remove glib_allocated/qom_allocated and use release hook to free memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Anthony Liguori Acked-by: Andreas Färber --- hw/pci.c | 7 ++++++- hw/qdev.c | 15 --------------- hw/qdev.h | 7 ------- hw/sysbus.c | 7 ++++++- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 4d95984..437af70 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -292,6 +292,11 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, vmstate_register(NULL, -1, &vmstate_pcibus, bus); } +static void pci_bus_release(Object *obj) +{ + g_free(obj); +} + PCIBus *pci_bus_new(DeviceState *parent, const char *name, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, @@ -300,9 +305,9 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name, PCIBus *bus; bus = g_malloc0(sizeof(*bus)); - bus->qbus.glib_allocated = true; pci_bus_new_inplace(bus, parent, name, address_space_mem, address_space_io, devfn_min); + object_set_release_func(OBJECT(bus), pci_bus_release); return bus; } diff --git a/hw/qdev.c b/hw/qdev.c index b5a52ac..6b61daa 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -459,8 +459,6 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam BusState *bus; bus = BUS(object_new(typename)); - bus->qom_allocated = true; - bus->parent = parent; bus->name = name ? g_strdup(name) : NULL; qbus_realize(bus); @@ -468,18 +466,6 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam return bus; } -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); - } - } -} - static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) { BusClass *bc = BUS_GET_CLASS(bus); @@ -698,7 +684,6 @@ static void device_finalize(Object *obj) if (dev->state == DEV_STATE_INITIALIZED) { while (dev->num_child_bus) { bus = QLIST_FIRST(&dev->child_bus); - qbus_free(bus); } if (qdev_get_vmsd(dev)) { vmstate_unregister(dev, qdev_get_vmsd(dev), dev); diff --git a/hw/qdev.h b/hw/qdev.h index d699194..3561e3a 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -106,17 +106,12 @@ typedef struct BusChild { /** * BusState: - * @qom_allocated: Indicates whether the object was allocated by QOM. - * @glib_allocated: Indicates whether the object was initialized in-place - * 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; @@ -201,8 +196,6 @@ int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn, void qdev_reset_all(DeviceState *dev); void qbus_reset_all_fn(void *opaque); -void qbus_free(BusState *bus); - #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) /* This should go away once we get rid of the NULL bus hack */ diff --git a/hw/sysbus.c b/hw/sysbus.c index 9d8b1ea..8305337 100644 --- a/hw/sysbus.c +++ b/hw/sysbus.c @@ -267,6 +267,11 @@ static TypeInfo sysbus_device_type_info = { /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ static BusState *main_system_bus; +static void main_system_bus_release(Object *obj) +{ + g_free(obj); +} + static void main_system_bus_create(void) { /* assign main_system_bus before qbus_create_inplace() @@ -274,7 +279,7 @@ static void main_system_bus_create(void) main_system_bus = 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 = true; + object_set_release_func(OBJECT(main_system_bus), main_system_bus_release); object_property_add_child(container_get(qdev_get_machine(), "/unattached"), "sysbus", OBJECT(main_system_bus), NULL);