[PATCH 2/7] util: Resolve Coverity FORWARD_NULL

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

 



Convert virPCIDriverFile 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 | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index ad08570..5d86c89 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 = NULL;
 
-    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 "
-- 
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]