[PATCH 1/7] util: Resolve Coverity FORWARD_NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/util/virpci.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index cf2a253..ad08570 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -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 = NULL;
 
-    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,
-- 
2.1.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]