]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Resolve Coverity FORWARD_NULL
authorJohn Ferlan <jferlan@redhat.com>
Tue, 30 Jun 2015 19:23:31 +0000 (15:23 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 1 Jul 2015 16:15:08 +0000 (12:15 -0400)
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>
src/util/virpci.c

index cf2a253b862224aaecde332ce250cb31bd5a1857..5790ec2335636e4a27378af8416b92961188f62c 100644 (file)
@@ -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,