[libvirt] [PATCH 1/3] pci: Fix callers of pciDeviceListSteal() when there's more than one device

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> --- src/qemu/qemu_hostdev.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 7f5ad51..6f77717 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -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); } -- 1.7.4.4

On 08/24/2011 09:30 AM, Shradha Shah wrote: long subject line; I've shortened it to fit in more typical commit length: pci: fix pciDeviceListSteal on multiple devices
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> --- src/qemu/qemu_hostdev.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
ACK and pushed. Thanks for the first-time contribution. Shradha, I added you to AUTHORS, given the git authorship; let me know if I also need to add Steve (due to the Signed-off-by contribution), or adjust any spellings. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Shradha Shah