mirror of https://gitee.com/openkylin/qemu.git
qdev: Drop misleading qdev_free() function
The qdev_free() function name is misleading since all the function does is unlink the device from its parent. The device is not necessarily freed. The device will be freed when its QObject refcount reaches zero. It is usual for the parent (bus) to hold the final reference but there are cases where something else holds a reference so "free" is a misleading name. Call object_unparent(obj) directly instead of having a qdev wrapper function. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
ee6abeb6ec
commit
02a5c4c974
|
@ -328,7 +328,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
|
||||||
if (pc->no_hotplug) {
|
if (pc->no_hotplug) {
|
||||||
slot_free = false;
|
slot_free = false;
|
||||||
} else {
|
} else {
|
||||||
qdev_free(qdev);
|
object_unparent(OBJECT(qdev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ int qdev_init(DeviceState *dev)
|
||||||
if (local_err != NULL) {
|
if (local_err != NULL) {
|
||||||
qerror_report_err(local_err);
|
qerror_report_err(local_err);
|
||||||
error_free(local_err);
|
error_free(local_err);
|
||||||
qdev_free(dev);
|
object_unparent(OBJECT(dev));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -258,7 +258,7 @@ void qbus_reset_all_fn(void *opaque)
|
||||||
int qdev_simple_unplug_cb(DeviceState *dev)
|
int qdev_simple_unplug_cb(DeviceState *dev)
|
||||||
{
|
{
|
||||||
/* just zap it */
|
/* just zap it */
|
||||||
qdev_free(dev);
|
object_unparent(OBJECT(dev));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,12 +280,6 @@ void qdev_init_nofail(DeviceState *dev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unlink device from bus and free the structure. */
|
|
||||||
void qdev_free(DeviceState *dev)
|
|
||||||
{
|
|
||||||
object_unparent(OBJECT(dev));
|
|
||||||
}
|
|
||||||
|
|
||||||
void qdev_machine_creation_done(void)
|
void qdev_machine_creation_done(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -458,7 +452,7 @@ static void bus_unparent(Object *obj)
|
||||||
|
|
||||||
while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
|
while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
|
||||||
DeviceState *dev = kid->child;
|
DeviceState *dev = kid->child;
|
||||||
qdev_free(dev);
|
object_unparent(OBJECT(dev));
|
||||||
}
|
}
|
||||||
if (bus->parent) {
|
if (bus->parent) {
|
||||||
QLIST_REMOVE(bus, sibling);
|
QLIST_REMOVE(bus, sibling);
|
||||||
|
|
|
@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
|
||||||
}
|
}
|
||||||
dev = pci_create(bus, devfn, "virtio-blk-pci");
|
dev = pci_create(bus, devfn, "virtio-blk-pci");
|
||||||
if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
|
if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
|
||||||
qdev_free(&dev->qdev);
|
object_unparent(OBJECT(dev));
|
||||||
dev = NULL;
|
dev = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
|
||||||
pci_bridge_region_cleanup(s, s->windows);
|
pci_bridge_region_cleanup(s, s->windows);
|
||||||
memory_region_destroy(&s->address_space_mem);
|
memory_region_destroy(&s->address_space_mem);
|
||||||
memory_region_destroy(&s->address_space_io);
|
memory_region_destroy(&s->address_space_io);
|
||||||
/* qbus_free() is called automatically by qdev_free() */
|
/* qbus_free() is called automatically during device deletion */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -251,7 +251,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
|
||||||
PCI_EXP_SLTSTA_PDS);
|
PCI_EXP_SLTSTA_PDS);
|
||||||
pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
|
pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
|
||||||
} else {
|
} else {
|
||||||
qdev_free(&pci_dev->qdev);
|
object_unparent(OBJECT(pci_dev));
|
||||||
pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
|
pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
|
||||||
PCI_EXP_SLTSTA_PDS);
|
PCI_EXP_SLTSTA_PDS);
|
||||||
pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
|
pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
|
||||||
|
|
|
@ -254,7 +254,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
|
||||||
++devfn) {
|
++devfn) {
|
||||||
PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
|
PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
|
||||||
if (affected_dev) {
|
if (affected_dev) {
|
||||||
qdev_free(&affected_dev->qdev);
|
object_unparent(OBJECT(affected_dev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1239,7 +1239,7 @@ static int virtio_ccw_busdev_unplug(DeviceState *dev)
|
||||||
|
|
||||||
css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
|
css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
|
||||||
|
|
||||||
qdev_free(dev);
|
object_unparent(OBJECT(dev));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ static int scsi_qdev_init(DeviceState *qdev)
|
||||||
d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
|
d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
|
||||||
assert(d);
|
assert(d);
|
||||||
if (d->lun == dev->lun && dev != d) {
|
if (d->lun == dev->lun && dev != d) {
|
||||||
qdev_free(&d->qdev);
|
object_unparent(OBJECT(d));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,13 +231,13 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
||||||
}
|
}
|
||||||
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
|
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
|
||||||
error_setg(errp, "Setting drive property failed");
|
error_setg(errp, "Setting drive property failed");
|
||||||
qdev_free(dev);
|
object_unparent(OBJECT(dev));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
object_property_set_bool(OBJECT(dev), true, "realized", &err);
|
object_property_set_bool(OBJECT(dev), true, "realized", &err);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
qdev_free(dev);
|
object_unparent(OBJECT(dev));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return SCSI_DEVICE(dev);
|
return SCSI_DEVICE(dev);
|
||||||
|
|
|
@ -356,8 +356,9 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
|
||||||
|
|
||||||
void usb_unregister_port(USBBus *bus, USBPort *port)
|
void usb_unregister_port(USBBus *bus, USBPort *port)
|
||||||
{
|
{
|
||||||
if (port->dev)
|
if (port->dev) {
|
||||||
qdev_free(&port->dev->qdev);
|
object_unparent(OBJECT(port->dev));
|
||||||
|
}
|
||||||
QTAILQ_REMOVE(&bus->free, port, next);
|
QTAILQ_REMOVE(&bus->free, port, next);
|
||||||
bus->nfree--;
|
bus->nfree--;
|
||||||
}
|
}
|
||||||
|
@ -505,7 +506,7 @@ int usb_device_delete_addr(int busnr, int addr)
|
||||||
return -1;
|
return -1;
|
||||||
dev = port->dev;
|
dev = port->dev;
|
||||||
|
|
||||||
qdev_free(&dev->qdev);
|
object_unparent(OBJECT(dev));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -703,7 +703,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
|
if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
|
||||||
qdev_free(&dev->qdev);
|
object_unparent(OBJECT(dev));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (qdev_init(&dev->qdev) < 0)
|
if (qdev_init(&dev->qdev) < 0)
|
||||||
|
|
|
@ -132,7 +132,7 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
|
||||||
return dev;
|
return dev;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
qdev_free(&dev->qdev);
|
object_unparent(OBJECT(dev));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,6 @@ void virtio_bus_reset(VirtioBusState *bus)
|
||||||
/* Destroy the VirtIODevice */
|
/* Destroy the VirtIODevice */
|
||||||
void virtio_bus_destroy_device(VirtioBusState *bus)
|
void virtio_bus_destroy_device(VirtioBusState *bus)
|
||||||
{
|
{
|
||||||
DeviceState *qdev;
|
|
||||||
BusState *qbus = BUS(bus);
|
BusState *qbus = BUS(bus);
|
||||||
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
|
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
|
||||||
DPRINTF("%s: remove device.\n", qbus->name);
|
DPRINTF("%s: remove device.\n", qbus->name);
|
||||||
|
@ -76,8 +75,7 @@ void virtio_bus_destroy_device(VirtioBusState *bus)
|
||||||
if (klass->device_unplug != NULL) {
|
if (klass->device_unplug != NULL) {
|
||||||
klass->device_unplug(qbus->parent);
|
klass->device_unplug(qbus->parent);
|
||||||
}
|
}
|
||||||
qdev = DEVICE(bus->vdev);
|
object_unparent(OBJECT(bus->vdev));
|
||||||
qdev_free(qdev);
|
|
||||||
bus->vdev = NULL;
|
bus->vdev = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
|
||||||
if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
|
if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
|
||||||
PCI_CLASS_NETWORK_ETHERNET
|
PCI_CLASS_NETWORK_ETHERNET
|
||||||
&& strcmp(d->name, "xen-pci-passthrough") != 0) {
|
&& strcmp(d->name, "xen-pci-passthrough") != 0) {
|
||||||
qdev_free(DEVICE(d));
|
object_unparent(OBJECT(d));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,6 @@ void qdev_init_nofail(DeviceState *dev);
|
||||||
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
|
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
|
||||||
int required_for_version);
|
int required_for_version);
|
||||||
void qdev_unplug(DeviceState *dev, Error **errp);
|
void qdev_unplug(DeviceState *dev, Error **errp);
|
||||||
void qdev_free(DeviceState *dev);
|
|
||||||
int qdev_simple_unplug_cb(DeviceState *dev);
|
int qdev_simple_unplug_cb(DeviceState *dev);
|
||||||
void qdev_machine_creation_done(void);
|
void qdev_machine_creation_done(void);
|
||||||
bool qdev_machine_modified(void);
|
bool qdev_machine_modified(void);
|
||||||
|
|
|
@ -526,7 +526,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
qdev->id = id;
|
qdev->id = id;
|
||||||
}
|
}
|
||||||
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
|
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
|
||||||
qdev_free(qdev);
|
object_unparent(OBJECT(qdev));
|
||||||
object_unref(OBJECT(qdev));
|
object_unref(OBJECT(qdev));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue