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

[libvirt] [PATCH 1/3] conf: Fix error flow in virDomainPCIAddressEnsureAddr()



This avoids setting 'ret' multiple times, which will result
in errors being masked if the first operation fails but the
second one succeeds.

Introduced-by: f183b87fc1dbcc6446ac3c1cef9cdd345b9725fb
Spotted-by: Coverity
Reported-by: John Ferlan <jferlan redhat com>
Signed-off-by: Andrea Bolognani <abologna redhat com>
---
 src/conf/domain_addr.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 3e1d767e4f..cc9ea82a33 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -940,15 +940,21 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr addrs,
                                          addrStr, flags, true))
             goto cleanup;
 
-        ret = virDomainPCIAddressReserveAddrInternal(addrs, &dev->addr.pci,
-                                                     flags, dev->isolationGroup,
-                                                     true);
+        if (virDomainPCIAddressReserveAddrInternal(addrs, &dev->addr.pci,
+                                                   flags, dev->isolationGroup,
+                                                   true) < 0) {
+            goto cleanup;
+        }
     } else {
-        ret = virDomainPCIAddressReserveNextAddr(addrs, dev, flags, -1);
+        if (virDomainPCIAddressReserveNextAddr(addrs, dev, flags, -1) < 0)
+            goto cleanup;
     }
 
     dev->addr.pci.extFlags = dev->pciAddrExtFlags;
-    ret = virDomainPCIAddressExtensionEnsureAddr(addrs, &dev->addr.pci);
+    if (virDomainPCIAddressExtensionEnsureAddr(addrs, &dev->addr.pci) < 0)
+        goto cleanup;
+
+    ret = 0;
 
  cleanup:
     VIR_FREE(addrStr);
-- 
2.19.1


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