@@ -502,13 +502,12 @@ static BusState *qbus_find(const char *path)
}
}
-BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
+void qbus_create_inplace(BusState *bus, BusInfo *info,
+ DeviceState *parent, const char *name)
{
- BusState *bus;
char *buf;
int i,len;
- bus = qemu_mallocz(info->size);
bus->info = info;
bus->parent = parent;
@@ -537,6 +536,16 @@ BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
parent->num_child_bus++;
}
+
+}
+
+BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
+{
+ BusState *bus;
+
+ bus = qemu_mallocz(info->size);
+ bus->qdev_allocated = 1;
+ qbus_create_inplace(bus, info, parent, name);
return bus;
}
@@ -47,6 +47,7 @@ struct BusState {
DeviceState *parent;
BusInfo *info;
const char *name;
+ int qdev_allocated;
QLIST_HEAD(, DeviceState) children;
QLIST_ENTRY(BusState) sibling;
};
@@ -144,6 +145,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev);
/*** BUS API. ***/
+void qbus_create_inplace(BusState *bus, BusInfo *info,
+ DeviceState *parent, const char *name);
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
A bus usually is instanciated by the parent device. The accociated bus state can usually be embeeded into the parent device state struct, there is no need for separate allocation and pointer indirection. This patch adds a non-allocating qbus_create variant. We keep track of whenever qdev allocated the struct or not. Will be needed later in this patch series when we'll fix bus unplugging. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/qdev.c | 15 ++++++++++++--- hw/qdev.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-)