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