Skip to content

Commit 163f384

Browse files
committed
qdev: Make DeviceState.id independent of QemuOpts
DeviceState.id is a pointer to a string that is stored in the QemuOpts object DeviceState.opts and freed together with it. We want to create devices without going through QemuOpts in the future, so make this a separately allocated string. Signed-off-by: Kevin Wolf <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Message-Id: <[email protected]> Reviewed-by: Damien Hedde <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Tested-by: Peter Krempa <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent c34efec commit 163f384

File tree

7 files changed

+9
-7
lines changed

7 files changed

+9
-7
lines changed

hw/arm/virt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ static void create_platform_bus(VirtMachineState *vms)
14591459
MemoryRegion *sysmem = get_system_memory();
14601460

14611461
dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE);
1462-
dev->id = TYPE_PLATFORM_BUS_DEVICE;
1462+
dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE);
14631463
qdev_prop_set_uint32(dev, "num_irqs", PLATFORM_BUS_NUM_IRQS);
14641464
qdev_prop_set_uint32(dev, "mmio_size", vms->memmap[VIRT_PLATFORM_BUS].size);
14651465
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);

hw/core/qdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ static void device_finalize(Object *obj)
956956
}
957957

958958
qemu_opts_del(dev->opts);
959+
g_free(dev->id);
959960
}
960961

961962
static void device_class_base_init(ObjectClass *class, void *data)

hw/pci-bridge/pci_expander_bridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
245245
} else {
246246
bus = pci_root_bus_new(ds, "pxb-internal", NULL, NULL, 0, TYPE_PXB_BUS);
247247
bds = qdev_new("pci-bridge");
248-
bds->id = dev_name;
248+
bds->id = g_strdup(dev_name);
249249
qdev_prop_set_uint8(bds, PCI_BRIDGE_DEV_PROP_CHASSIS_NR, pxb->bus_nr);
250250
qdev_prop_set_bit(bds, PCI_BRIDGE_DEV_PROP_SHPC, false);
251251
}

hw/ppc/e500.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ void ppce500_init(MachineState *machine)
10061006
/* Platform Bus Device */
10071007
if (pmc->has_platform_bus) {
10081008
dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE);
1009-
dev->id = TYPE_PLATFORM_BUS_DEVICE;
1009+
dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE);
10101010
qdev_prop_set_uint32(dev, "num_irqs", pmc->platform_bus_num_irqs);
10111011
qdev_prop_set_uint32(dev, "mmio_size", pmc->platform_bus_size);
10121012
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);

include/hw/qdev-core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct DeviceState {
176176
Object parent_obj;
177177
/*< public >*/
178178

179-
const char *id;
179+
char *id;
180180
char *canonical_path;
181181
bool realized;
182182
bool pending_deleted_event;

include/monitor/qdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
99

1010
int qdev_device_help(QemuOpts *opts);
1111
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
12-
void qdev_set_id(DeviceState *dev, const char *id);
12+
void qdev_set_id(DeviceState *dev, char *id);
1313

1414
#endif

softmmu/qdev-monitor.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ static BusState *qbus_find(const char *path, Error **errp)
592592
return bus;
593593
}
594594

595-
void qdev_set_id(DeviceState *dev, const char *id)
595+
/* Takes ownership of @id, will be freed when deleting the device */
596+
void qdev_set_id(DeviceState *dev, char *id)
596597
{
597598
if (id) {
598599
dev->id = id;
@@ -690,7 +691,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
690691
}
691692
}
692693

693-
qdev_set_id(dev, qemu_opts_id(opts));
694+
qdev_set_id(dev, g_strdup(qemu_opts_id(opts)));
694695

695696
/* set properties */
696697
if (qemu_opt_foreach(opts, set_property, dev, errp)) {

0 commit comments

Comments
 (0)