From: Mark McLoughlin <[EMAIL PROTECTED]> Associate the AssignedDevice with the AssignedDevInfo as soon as we have allocated it and don't try and free it in init_assigned_device() if an error occurs.
This ensures that the mmio region is unmapped by free_assigned_device() if init_assigned_device() fails. Signed-off-by: Mark McLoughlin <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c index a4f784e..eaff09e 100644 --- a/qemu/hw/device-assignment.c +++ b/qemu/hw/device-assignment.c @@ -549,17 +549,19 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus) return NULL; } + adev->assigned_dev = dev; + if (get_real_device(dev, adev->bus, adev->dev, adev->func)) { fprintf(stderr, "%s: Error: Couldn't get real device (%s)!\n", __func__, adev->name); - goto out; + return NULL; } /* handle real device's MMIO/PIO BARs */ if (assigned_dev_register_regions(dev->real_device.regions, dev->real_device.region_number, dev)) - goto out; + return NULL; /* handle interrupt routing */ e_device = (dev->dev.devfn >> 3) & 0x1f; @@ -589,15 +591,10 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus) if (r < 0) { fprintf(stderr, "Failed to assign device \"%s\" : %s\n", adev->name, strerror(-r)); - goto out; + return NULL; } - adev->assigned_dev = dev; return &dev->dev; - -out: - pci_unregister_device(&dev->dev); - return NULL; } /* -- To unsubscribe from this list: send the line "unsubscribe kvm-commits" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html