1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-13 17:18:01 +03:00

util: Resolve Coverity FORWARD_NULL

Convert virPCIFile to return the buffer allocated (or not) and make the
appropriate check in the caller.

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2015-06-30 15:23:31 -04:00
parent 302146b16d
commit d7ddb4c2f0

View File

@ -226,14 +226,13 @@ virPCIDriverFile(char **buffer, const char *driver, const char *file)
} }
static int static char *
virPCIFile(char **buffer, const char *device, const char *file) virPCIFile(const char *device, const char *file)
{ {
VIR_FREE(*buffer); char *buffer;
if (virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file) < 0) ignore_value(virAsprintf(&buffer, PCI_SYSFS "devices/%s/%s", device, file));
return -1; return buffer;
return 0;
} }
@ -252,7 +251,7 @@ virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name)
*path = *name = NULL; *path = *name = NULL;
/* drvlink = "/sys/bus/pci/dddd:bb:ss.ff/driver" */ /* drvlink = "/sys/bus/pci/dddd:bb:ss.ff/driver" */
if (virPCIFile(&drvlink, dev->name, "driver") < 0) if (!(drvlink = virPCIFile(dev->name, "driver")))
goto cleanup; goto cleanup;
if (!virFileExists(drvlink)) { if (!virFileExists(drvlink)) {
@ -375,7 +374,7 @@ virPCIDeviceReadClass(virPCIDevicePtr dev, uint16_t *device_class)
int ret = -1; int ret = -1;
unsigned int value; unsigned int value;
if (virPCIFile(&path, dev->name, "class") < 0) if (!(path = virPCIFile(dev->name, "class")))
return ret; return ret;
/* class string is '0xNNNNNN\n' ... i.e. 9 bytes */ /* class string is '0xNNNNNN\n' ... i.e. 9 bytes */
@ -1055,7 +1054,7 @@ virPCIDeviceUnbind(virPCIDevicePtr dev, bool reprobe)
goto cleanup; goto cleanup;
} }
if (virPCIFile(&path, dev->name, "driver/unbind") < 0) if (!(path = virPCIFile(dev->name, "driver/unbind")))
goto cleanup; goto cleanup;
if (virFileExists(path)) { if (virFileExists(path)) {
@ -1190,7 +1189,7 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev,
virErrorPtr err = NULL; virErrorPtr err = NULL;
if (virPCIDriverDir(&stubDriverPath, stubDriverName) < 0 || if (virPCIDriverDir(&stubDriverPath, stubDriverName) < 0 ||
virPCIFile(&driverLink, dev->name, "driver") < 0 || !(driverLink = virPCIFile(dev->name, "driver")) ||
VIR_STRDUP(newDriverName, stubDriverName) < 0) VIR_STRDUP(newDriverName, stubDriverName) < 0)
goto cleanup; goto cleanup;
@ -1501,7 +1500,7 @@ virPCIDeviceReadID(virPCIDevicePtr dev, const char *id_name)
char *path = NULL; char *path = NULL;
char *id_str; char *id_str;
if (virPCIFile(&path, dev->name, id_name) < 0) if (!(path = virPCIFile(dev->name, id_name)))
return NULL; return NULL;
/* ID string is '0xNNNN\n' ... i.e. 7 bytes */ /* ID string is '0xNNNN\n' ... i.e. 7 bytes */
@ -2167,7 +2166,7 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr)
addr->bus, addr->slot, addr->function) < 0) addr->bus, addr->slot, addr->function) < 0)
goto cleanup; goto cleanup;
if (virPCIFile(&devPath, devName, "iommu_group") < 0) if (!(devPath = virPCIFile(devName, "iommu_group")))
goto cleanup; goto cleanup;
if (virFileIsLink(devPath) != 1) { if (virFileIsLink(devPath) != 1) {
ret = -2; ret = -2;
@ -2209,7 +2208,7 @@ virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev)
char *groupPath = NULL; char *groupPath = NULL;
char *groupDev = NULL; char *groupDev = NULL;
if (virPCIFile(&devPath, dev->name, "iommu_group") < 0) if (!(devPath = virPCIFile(dev->name, "iommu_group")))
goto cleanup; goto cleanup;
if (virFileIsLink(devPath) != 1) { if (virFileIsLink(devPath) != 1) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,