[libvirt] [PATCH 11/24] hostdev: Remove redundant check
John Ferlan
jferlan at redhat.com
Thu Mar 10 17:01:42 UTC 2016
On 03/07/2016 12:24 PM, Andrea Bolognani wrote:
> 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.
>
> Hence, the first check is completely redundant and can be safely
> removed.
> ---
> src/util/virhostdev.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
Premise understood; however, Coverity has an issue...
> diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
> index 098207e..f08502b 100644
> --- a/src/util/virhostdev.c
> +++ b/src/util/virhostdev.c
Way back here:
507 virPCIDeviceListPtr pcidevs = NULL;
(1) Event var_tested_neg: Assigning: "last_processed_hostdev_vf" = a negative value.
Also see events: [negative_returns]
508 int last_processed_hostdev_vf = -1;
Eventually we enter this loop:
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
if (!virHostdevIsPCINetDevice(hostdev))
continue;
if (virHostdevNetConfigReplace(hostdev, uuid,
mgr->stateDir) < 0) {
goto resetvfnetconfig;
}
last_processed_hostdev_vf = i;
}
If for some reason we "continue" (or not) and eventually "goto resetvfnetconfig;"
before ever setting last_processed_hostdev_vf, then we get to the goto.,..
> @@ -718,8 +718,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
> }
>
> resetvfnetconfig:
> - for (i = 0;
> - last_processed_hostdev_vf != -1 && i <= last_processed_hostdev_vf; i++)
and last_processed_hostdev_vf still == -1
So that check needs to be there - perhaps just add an:
if (last_processed_hostdev_vf > -1) {
}
John
> + for (i = 0; i <= last_processed_hostdev_vf; i++)
> virHostdevNetConfigRestore(hostdevs[i], hostdev_mgr->stateDir, NULL);
>
> reattachdevs:
>
More information about the libvir-list
mailing list