]> xenbits.xensource.com Git - libvirt.git/commitdiff
hostdev: Rework resetvfnetconfig loop condition
authorAndrea Bolognani <abologna@redhat.com>
Thu, 25 Feb 2016 18:04:30 +0000 (19:04 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 14 Mar 2016 13:55:47 +0000 (14:55 +0100)
If 'last_processed_hostdev_vf != -1' is false then, since the
loop counter 'i' starts at 0, 'i <= last_processed_hostdev_vf'
can't possibly be true and the loop body will never be executed.

However, since 'i' is unsigned and 'last_processed_hostdev_vf'
is signed, we can't just get rid of the check completely; what
we can do is move it outside of the loop to avoid checking its
value on every iteration and cluttering the actual loop
condition.

src/util/virhostdev.c

index 098207e798f1a1ba0326145f5cde0ff9315f244a..3906c4f3997f000fc10a33390e5f549b8c1a8a54 100644 (file)
@@ -718,9 +718,10 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
     }
 
  resetvfnetconfig:
-    for (i = 0;
-         last_processed_hostdev_vf != -1 && i <= last_processed_hostdev_vf; i++)
-        virHostdevNetConfigRestore(hostdevs[i], hostdev_mgr->stateDir, NULL);
+    if (last_processed_hostdev_vf >= 0) {
+        for (i = 0; i <= last_processed_hostdev_vf; i++)
+            virHostdevNetConfigRestore(hostdevs[i], hostdev_mgr->stateDir, NULL);
+    }
 
  reattachdevs:
     for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {