[PATCH 1/3] getNewStyleBlockDevice: Adjust formatting

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

 



Instead of initializing return value to zero (success) and overwriting
it on every failure just before the control jumps onto 'out' label,
let's initialize to an error value and set to zero only when we are
sure about the success. Just follow the pattern we have in the rest of
the code.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/storage/storage_backend_scsi.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index e6c8bb5..3c1bae6 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -255,44 +255,41 @@ getNewStyleBlockDevice(const char *lun_path,
     char *block_path = NULL;
     DIR *block_dir = NULL;
     struct dirent *block_dirent = NULL;
-    int retval = 0;
+    int retval = -1;
     int direrr;
 
     if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
-        goto out;
+        goto cleanup;
 
     VIR_DEBUG("Looking for block device in '%s'", block_path);
 
-    block_dir = opendir(block_path);
-    if (block_dir == NULL) {
+    if (!(block_dir = opendir(block_path))) {
         virReportSystemError(errno,
                              _("Failed to opendir sysfs path '%s'"),
                              block_path);
-        retval = -1;
-        goto out;
+        goto cleanup;
     }
 
     while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
-
         if (STREQLEN(block_dirent->d_name, ".", 1))
             continue;
 
-        if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0) {
-            closedir(block_dir);
-            retval = -1;
-            goto out;
-        }
+        if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0)
+            goto cleanup;
 
         VIR_DEBUG("Block device is '%s'", *block_device);
 
         break;
     }
+
     if (direrr < 0)
-        retval = -1;
+        goto cleanup;
 
-    closedir(block_dir);
+    retval = 0;
 
- out:
+ cleanup:
+    if (block_dir)
+        closedir(block_dir);
     VIR_FREE(block_path);
     return retval;
 }
-- 
2.3.6

--
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]