Re: [PATCH 1/2] hostdev: Fix index error in loop after remove an element

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 31, 2015 at 10:34:57AM +0200, Martin Kletzander wrote:
On Thu, Mar 26, 2015 at 10:23:46PM +0800, Huanle Han wrote:
'virPCIDeviceList' is actually an array. Removing one element makes the
rest of the element move.

Use while loop, increase index only when not virPCIDeviceListDel(pcidevs, dev)

Signed-off-by: Huanle Han <hanxueluo@xxxxxxxxx>
---
src/util/virhostdev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 23365a3..83f567d 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -785,7 +785,8 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
    * them and reset all the devices before re-attach.
    * Attach mac and port profile parameters to devices
    */
-    for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+    i = 0;
+    while (i < virPCIDeviceListCount(pcidevs)) {
       virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
       virPCIDevicePtr activeDev = NULL;

@@ -806,6 +807,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
       }

       virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, dev);
+        i++;

'i--;' before that 'continue;' that's not in the index would be
shorter, but I guess this is more readable.  Or maybe:

for (i = virPCIDeviceListCount(pcidevs); i > 0; i--) {
  size_t dev_index = i - 1;

would just deal with this.

Anyway, this works just as it is, ACK if you don't want to change it.


Pushed now as it's after release.

Attachment: pgpR1Ay0gyzRy.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]