void vfio_put_group(VFIOGroup *group)
{
- if (!QLIST_EMPTY(&group->device_list)) {
+ if (!group || !QLIST_EMPTY(&group->device_list)) {
return;
}
void vfio_put_base_device(VFIODevice *vbasedev)
{
+ if (!vbasedev->group) {
+ return;
+ }
QLIST_REMOVE(vbasedev, next);
vbasedev->group = NULL;
trace_vfio_put_base_device(vbasedev->fd);
ret = vfio_populate_device(vdev);
if (ret) {
- goto out_put;
+ return ret;
}
/* Get a copy of config space */
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
ret = ret < 0 ? -errno : -EFAULT;
error_report("vfio: Failed to read device config space");
- goto out_put;
+ return ret;
}
/* vfio emulates a lot for us, but some bits need extra love */
ret = vfio_early_setup_msix(vdev);
if (ret) {
- goto out_put;
+ return ret;
}
vfio_map_bars(vdev);
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
vfio_teardown_msi(vdev);
vfio_unmap_bars(vdev);
-out_put:
+ return ret;
+}
+
+static void vfio_instance_finalize(Object *obj)
+{
+ PCIDevice *pci_dev = PCI_DEVICE(obj);
+ VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pci_dev);
+ VFIOGroup *group = vdev->vbasedev.group;
+
g_free(vdev->emulated_config_bits);
+ g_free(vdev->rom);
vfio_put_device(vdev);
vfio_put_group(group);
- return ret;
}
static void vfio_exitfn(PCIDevice *pdev)
{
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
- VFIOGroup *group = vdev->vbasedev.group;
vfio_unregister_err_notifier(vdev);
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
}
vfio_teardown_msi(vdev);
vfio_unmap_bars(vdev);
- g_free(vdev->emulated_config_bits);
- g_free(vdev->rom);
- vfio_put_device(vdev);
- vfio_put_group(group);
}
static void vfio_pci_reset(DeviceState *dev)
.instance_size = sizeof(VFIOPCIDevice),
.class_init = vfio_pci_dev_class_init,
.instance_init = vfio_instance_init,
+ .instance_finalize = vfio_instance_finalize,
};
static void register_vfio_pci_dev_type(void)