From 2ec4664b1ede97919f7ca56f8f909279b7a6e7f5 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Thu, 25 Feb 2016 19:04:30 +0100 Subject: [PATCH] hostdev: Rework resetvfnetconfig loop condition 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 098207e798..3906c4f399 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -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++) {