[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 07/13] qdev: move deletion of children from final
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v4 07/13] qdev: move deletion of children from finalize to unparent |
Date: |
Fri, 25 Jan 2013 14:12:33 +0100 |
A device will never be finalized as long as it has a reference from
other devices that sit on its buses. To ensure that the references
go away, deassociate a bus from its children in the unparent callback
for the bus.
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/qdev.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 9a8b8c1..3c1ec7d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -433,6 +433,25 @@ static void qbus_realize(BusState *bus, DeviceState
*parent, const char *name)
}
}
+static void bus_unparent(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--;
+ bus->parent = NULL;
+ } else {
+ assert(bus != sysbus_get_default()); /* main_system_bus is never freed
*/
+ qemu_unregister_reset(qbus_reset_all_fn, bus);
+ }
+}
+
void qbus_create_inplace(void *bus, const char *typename,
DeviceState *parent, const char *name)
{
@@ -805,22 +824,15 @@ static void qbus_initfn(Object *obj)
QTAILQ_INIT(&bus->children);
}
+static void bus_class_init(ObjectClass *class, void *data)
+{
+ class->unparent = bus_unparent;
+}
+
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);
- }
g_free((char *)bus->name);
}
@@ -832,6 +844,7 @@ static const TypeInfo bus_info = {
.class_size = sizeof(BusClass),
.instance_init = qbus_initfn,
.instance_finalize = qbus_finalize,
+ .class_init = bus_class_init,
};
static void qdev_register_types(void)
--
1.8.1
- [Qemu-devel] [PATCH v4 01/13] qdev: remove duplication between qbus_create and qbus_create_inplace, (continued)
- [Qemu-devel] [PATCH v4 01/13] qdev: remove duplication between qbus_create and qbus_create_inplace, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 04/13] qom: preserve object while unparenting it, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 02/13] qdev: change first argument of qbus_create_inplace to void *, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 05/13] qom: document reference counting of link properties, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 08/13] qdev: move unrealization of devices from finalize to unparent, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 09/13] qdev: add reference for the bus while it is referred to by the DeviceState, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 11/13] qdev: drop extra references at creation time, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 12/13] cpu: do not use object_delete, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 10/13] qdev: inline object_delete into qbus_free/qdev_free, Paolo Bonzini, 2013/01/25
- [Qemu-devel] [PATCH v4 07/13] qdev: move deletion of children from finalize to unparent,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v4 13/13] qom: remove object_delete, Paolo Bonzini, 2013/01/25