From e3939e86bae2ecdd08ac2ff65bd035ab4462dc0d Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 30 Jun 2015 15:49:05 -0400 Subject: [PATCH] util: Resolve Coverity FORWARD_NULL Convert virPCIDriverFile to return the buffer allocated (or not) and make the appropriate check in the caller. Signed-off-by: John Ferlan --- src/util/virpci.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 5790ec2335..28cee9d9b0 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -215,14 +215,13 @@ virPCIDriverDir(char **buffer, const char *driver) } -static int -virPCIDriverFile(char **buffer, const char *driver, const char *file) +static char * +virPCIDriverFile(const char *driver, const char *file) { - VIR_FREE(*buffer); + char *buffer; - if (virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file) < 0) - return -1; - return 0; + ignore_value(virAsprintf(&buffer, PCI_SYSFS "drivers/%s/%s", driver, file)); + return buffer; } @@ -1126,7 +1125,7 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev) goto reprobe; /* Xen's pciback.ko wants you to use remove_slot on the specific device */ - if (virPCIDriverFile(&path, driver, "remove_slot") < 0) + if (!(path = virPCIDriverFile(driver, "remove_slot"))) goto cleanup; if (virFileExists(path) && virFileWriteStr(path, dev->name, 0) < 0) { @@ -1148,7 +1147,8 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev) * available, then re-probing would just cause the device to be * re-bound to the stub. */ - if (driver && virPCIDriverFile(&path, driver, "remove_id") < 0) + VIR_FREE(path); + if (driver && !(path = virPCIDriverFile(driver, "remove_id"))) goto cleanup; if (!driver || !virFileExists(drvdir) || virFileExists(path)) { @@ -1212,7 +1212,7 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, * is triggered for such a device, it will also be immediately * bound by the stub. */ - if (virPCIDriverFile(&path, stubDriverName, "new_id") < 0) + if (!(path = virPCIDriverFile(stubDriverName, "new_id"))) goto cleanup; if (virFileWriteStr(path, dev->id, 0) < 0) { @@ -1239,7 +1239,8 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, */ if (!virFileLinkPointsTo(driverLink, stubDriverPath)) { /* Xen's pciback.ko wants you to use new_slot first */ - if (virPCIDriverFile(&path, stubDriverName, "new_slot") < 0) + VIR_FREE(path); + if (!(path = virPCIDriverFile(stubDriverName, "new_slot"))) goto remove_id; if (virFileExists(path) && virFileWriteStr(path, dev->name, 0) < 0) { @@ -1251,7 +1252,8 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, } dev->remove_slot = true; - if (virPCIDriverFile(&path, stubDriverName, "bind") < 0) + VIR_FREE(path); + if (!(path = virPCIDriverFile(stubDriverName, "bind"))) goto remove_id; if (virFileWriteStr(path, dev->name, 0) < 0) { @@ -1271,7 +1273,8 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, /* If 'remove_id' exists, remove the device id from pci-stub's dynamic * ID table so that 'drivers_probe' works below. */ - if (virPCIDriverFile(&path, stubDriverName, "remove_id") < 0) { + VIR_FREE(path); + if (!(path = virPCIDriverFile(stubDriverName, "remove_id"))) { /* We do not remove PCI ID from pci-stub, and we cannot reprobe it */ if (dev->reprobe) { VIR_WARN("Could not remove PCI ID '%s' from %s, and the device " -- GitLab