From: Laine Stump Date: Sun, 6 Dec 2020 21:05:03 +0000 (-0500) Subject: util: simplify calling of virPCIDeviceDetectFunctionLevelReset() X-Git-Tag: v7.0.0-rc1~219 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47ccca4fd3d37e47e0cc304e963980c5b6cb15a5;p=thirdparty%2Flibvirt.git util: simplify calling of virPCIDeviceDetectFunctionLevelReset() This function returned an int, and that int was being checked for < 0 in its solitary caller, but within the function it would only ever return 0 or 1. Change the function itself to return a bool, and the caller to just directly set the flag in the virPCIDevice. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- diff --git a/src/util/virpci.c b/src/util/virpci.c index b63abac8cc..403ef1ec8e 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -549,7 +549,7 @@ virPCIDeviceFindExtendedCapabilityOffset(virPCIDevicePtr dev, /* detects whether this device has FLR. Returns 0 if the device does * not have FLR, 1 if it does, and -1 on error */ -static int +static bool virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) { uint32_t caps; @@ -567,7 +567,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) caps = virPCIDeviceRead32(dev, cfgfd, dev->pcie_cap_pos + PCI_EXP_DEVCAP); if (caps & PCI_EXP_DEVCAP_FLR) { VIR_DEBUG("%s %s: detected PCIe FLR capability", dev->id, dev->name); - return 1; + return true; } } @@ -580,7 +580,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) caps = virPCIDeviceRead16(dev, cfgfd, pos + PCI_AF_CAP); if (caps & PCI_AF_CAP_FLR) { VIR_DEBUG("%s %s: detected PCI FLR capability", dev->id, dev->name); - return 1; + return true; } } @@ -596,12 +596,12 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) if (found) { VIR_DEBUG("%s %s: buggy device didn't advertise FLR, but is a VF; forcing flr on", dev->id, dev->name); - return 1; + return true; } VIR_DEBUG("%s %s: no FLR capability found", dev->id, dev->name); - return 0; + return false; } /* Require the device has the PCI Power Management capability @@ -885,15 +885,10 @@ virPCIDeviceTryPowerManagementReset(virPCIDevicePtr dev, int cfgfd) static int virPCIDeviceInit(virPCIDevicePtr dev, int cfgfd) { - int flr; - dev->pcie_cap_pos = virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_EXP); dev->pci_pm_cap_pos = virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_PM); - flr = virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); - if (flr < 0) - return flr; - dev->has_flr = !!flr; - dev->has_pm_reset = !!virPCIDeviceDetectPowerManagementReset(dev, cfgfd); + dev->has_flr = virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); + dev->has_pm_reset = !!virPCIDeviceDetectPowerManagementReset(dev, cfgfd); return 0; }