From c0f025b8ba7ef28080432d2d89a5c60a17f559f7 Mon Sep 17 00:00:00 2001 From: Shradha Shah Date: Wed, 24 Aug 2011 16:30:51 +0100 Subject: [PATCH] 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 Signed-off-by: Shradha Shah Signed-off-by: Eric Blake --- AUTHORS | 1 + src/qemu/qemu_hostdev.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2f8529bb30..de22100ea8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -190,6 +190,7 @@ Patches have also been contributed by: Wieland Hoffmann Douglas Schilling Landgraf Tom Vijlbrief + Shradha Shah [....send patches to get your name here....] diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 7f5ad516ed..6f77717dd8 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); } -- GitLab