]> xenbits.xensource.com Git - libvirt.git/commitdiff
pci: fix pciDeviceListSteal on multiple devices
authorShradha Shah <sshah@solarflare.com>
Wed, 24 Aug 2011 15:30:51 +0000 (16:30 +0100)
committerEric Blake <eblake@redhat.com>
Wed, 24 Aug 2011 16:31:29 +0000 (10:31 -0600)
pciDeviceListSteal(pcidevs, dev) removes dev from pcidevs reducing
the length of pcidevs, so moving onto what was the next dev is wrong.

Instead callers should pop entry 0 repeatedly until pcidevs is empty.

Signed-off-by: Steve Hodgson <shodgson@solarflare.com>
Signed-off-by: Shradha Shah <sshah@solarflare.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
AUTHORS
src/qemu/qemu_hostdev.c

diff --git a/AUTHORS b/AUTHORS
index 2f8529bb30f3154ddc648401eaf0cf7c17973f87..de22100ea8cdfdabf733f1ec89dd31edde0d5273 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -190,6 +190,7 @@ Patches have also been contributed by:
   Wieland Hoffmann     <themineo@googlemail.com>
   Douglas Schilling Landgraf <dougsland@redhat.com>
   Tom Vijlbrief        <tom.vijlbrief@xs4all.nl>
+  Shradha Shah         <sshah@solarflare.com>
 
   [....send patches to get your name here....]
 
index 7f5ad516ed1c45327f055d907afe3000a26b39f4..6f77717dd8c62652e8d124048cd468b6149da30c 100644 (file)
@@ -74,7 +74,6 @@ int qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
                                 virDomainDefPtr def)
 {
     pciDeviceList *pcidevs;
-    int i;
     int ret = -1;
 
     if (!def->nhostdevs)
@@ -83,8 +82,8 @@ int qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
     if (!(pcidevs = qemuGetPciHostDeviceList(def->hostdevs, def->nhostdevs)))
         return -1;
 
-    for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
-        pciDevice *dev = pciDeviceListGet(pcidevs, i);
+    while (pciDeviceListCount(pcidevs) > 0) {
+        pciDevice *dev = pciDeviceListGet(pcidevs, 0);
         pciDeviceListSteal(pcidevs, dev);
         if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
             pciFreeDevice(dev);
@@ -152,8 +151,8 @@ int qemuPrepareHostdevPCIDevices(struct qemud_driver *driver,
     }
 
     /* Now steal all the devices from pcidevs */
-    for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
-        pciDevice *dev = pciDeviceListGet(pcidevs, i);
+    while (pciDeviceListCount(pcidevs) > 0) {
+        pciDevice *dev = pciDeviceListGet(pcidevs, 0);
         pciDeviceListSteal(pcidevs, dev);
     }
 
@@ -164,8 +163,8 @@ inactivedevs:
     /* Only steal all the devices from driver->activePciHostdevs. We will
      * free them in pciDeviceListFree().
      */
-    for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
-        pciDevice *dev = pciDeviceListGet(pcidevs, i);
+    while (pciDeviceListCount(pcidevs) > 0) {
+        pciDevice *dev = pciDeviceListGet(pcidevs, 0);
         pciDeviceListSteal(driver->activePciHostdevs, dev);
     }