]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_hotplug: Don't free the PCI device structure after hot-unplug
authorPeter Krempa <pkrempa@redhat.com>
Mon, 21 May 2012 14:31:53 +0000 (16:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 22 May 2012 16:21:29 +0000 (18:21 +0200)
The pciDevice structure corresponding to the device being hot-unplugged
was freed after it was "stolen" from activeList. The pointer was still
used for eg-inactive list. This patch removes the free of the structure
and frees it only if reset fails on the device.

src/qemu/qemu_hotplug.c

index dfca7e2efc4cfd715dee555a5e0074b9f42684ac..51b89158a7b358062851da8e17b4cae026204a18 100644 (file)
@@ -2004,13 +2004,16 @@ qemuDomainDetachHostPciDevice(struct qemud_driver *driver,
                        subsys->u.pci.slot,   subsys->u.pci.function);
     if (pci) {
         activePci = pciDeviceListSteal(driver->activePciHostdevs, pci);
-        if (pciResetDevice(activePci, driver->activePciHostdevs,
-                           driver->inactivePciHostdevs) == 0)
+        if (activePci &&
+            pciResetDevice(activePci, driver->activePciHostdevs,
+                           driver->inactivePciHostdevs) == 0) {
             qemuReattachPciDevice(activePci, driver);
-        else
+        } else {
+            /* reset of the device failed, treat it as if it was returned */
+            pciFreeDevice(activePci);
             ret = -1;
+        }
         pciFreeDevice(pci);
-        pciFreeDevice(activePci);
     } else {
         ret = -1;
     }