]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remove unnecessary cleanup labels and unused return variables
authorLaine Stump <laine@redhat.com>
Tue, 27 Oct 2020 21:49:11 +0000 (17:49 -0400)
committerLaine Stump <laine@redhat.com>
Tue, 3 Nov 2020 03:01:36 +0000 (22:01 -0500)
After converting all DIR* to g_autoptr(DIR), many cleanup: labels
ended up just having "return ret", and every place that set ret would
just immediately goto cleanup. Remove the cleanup label and its
return, and just return the set value immediately, thus eliminating
the need for the return variable itself.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
15 files changed:
src/conf/virnetworkobj.c
src/qemu/qemu_interop_config.c
src/storage/storage_util.c
src/util/vircgroup.c
src/util/vircommand.c
src/util/virdevmapper.c
src/util/virfile.c
src/util/virnetdev.c
src/util/virnuma.c
src/util/virpci.c
src/util/virresctrl.c
src/util/virscsi.c
src/util/virutil.c
src/util/virvhba.c
tests/testutilsqemu.c

index acf1442f88d56188a1c0f4ec120e46c64a005b93..8b3eb0f41c42f90f6b771945d4bde9fc02c7cbf2 100644 (file)
@@ -1091,12 +1091,11 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets,
         if (obj &&
             virNetworkObjLoadAllPorts(obj, stateDir) < 0) {
             virNetworkObjEndAPI(&obj);
-            goto cleanup;
+            return -1;
         }
         virNetworkObjEndAPI(&obj);
     }
 
- cleanup:
     return ret;
 }
 
@@ -1708,15 +1707,12 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
     g_autoptr(DIR) dh = NULL;
     struct dirent *de;
     int rc;
-    int ret = -1;
 
     if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir)))
-        goto cleanup;
+        return -1;
 
-    if ((rc = virDirOpenIfExists(&dh, dir)) <= 0) {
-        ret = rc;
-        goto cleanup;
-    }
+    if ((rc = virDirOpenIfExists(&dh, dir)) <= 0)
+        return rc;
 
     while ((rc = virDirRead(dh, &de, dir)) > 0) {
         char *file = NULL;
@@ -1733,10 +1729,7 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
     }
 
     virHashRemoveAll(net->ports);
-
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -1862,18 +1855,15 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
     g_autofree char *dir = NULL;
     g_autoptr(DIR) dh = NULL;
     struct dirent *de;
-    int ret = -1;
     int rc;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     g_autoptr(virNetworkPortDef) portdef = NULL;
 
     if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir)))
-        goto cleanup;
+        return -1;
 
-    if ((rc = virDirOpenIfExists(&dh, dir)) <= 0) {
-        ret = rc;
-        goto cleanup;
-    }
+    if ((rc = virDirOpenIfExists(&dh, dir)) <= 0)
+        return rc;
 
     while ((rc = virDirRead(dh, &de, dir)) > 0) {
         g_autofree char *file = NULL;
@@ -1891,12 +1881,10 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
 
         virUUIDFormat(portdef->uuid, uuidstr);
         if (virHashAddEntry(net->ports, uuidstr, portdef) < 0)
-            goto cleanup;
+            return -1;
 
         portdef = NULL;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
index f2d83eae93eadc0345e6e43e3e99f3099dbd4459..e1c20aff1180dbb55543471a610fd6d134547fc8 100644 (file)
@@ -40,7 +40,6 @@ qemuBuildFileList(virHashTablePtr files, const char *dir)
     g_autoptr(DIR) dirp = NULL;
     struct dirent *ent = NULL;
     int rc;
-    int ret = -1;
 
     if ((rc = virDirOpenIfExists(&dirp, dir)) < 0)
         return -1;
@@ -62,24 +61,22 @@ qemuBuildFileList(virHashTablePtr files, const char *dir)
 
         if (stat(path, &sb) < 0) {
             virReportSystemError(errno, _("Unable to access %s"), path);
-            goto cleanup;
+            return -1;
         }
 
         if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
             continue;
 
         if (virHashUpdateEntry(files, filename, path) < 0)
-            goto cleanup;
+            return -1;
 
         path = NULL;
     }
 
     if (rc < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
index 5a5e517b152c005f6766f2d9008b35ec87b32931..cf1f33f1775a24451063e44798b02d5f0a97370a 100644 (file)
@@ -3507,13 +3507,12 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
     struct statvfs sb;
     struct stat statbuf;
     int direrr;
-    int ret = -1;
     g_autoptr(virStorageVolDef) vol = NULL;
     VIR_AUTOCLOSE fd = -1;
     g_autoptr(virStorageSource) target = NULL;
 
     if (virDirOpen(&dir, def->target.path) < 0)
-        goto cleanup;
+        return -1;
 
     while ((direrr = virDirRead(dir, &ent, def->target.path)) > 0) {
         int err;
@@ -3541,15 +3540,15 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
                 vol = NULL;
                 continue;
             }
-            goto cleanup;
+            return -1;
         }
 
         if (virStoragePoolObjAddVol(pool, vol) < 0)
-            goto cleanup;
+            return -1;
         vol = NULL;
     }
     if (direrr < 0)
-        goto cleanup;
+        return -1;
 
     target = virStorageSourceNew();
 
@@ -3557,25 +3556,25 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
         virReportSystemError(errno,
                              _("cannot open path '%s'"),
                              def->target.path);
-        goto cleanup;
+        return -1;
     }
 
     if (fstat(fd, &statbuf) < 0) {
         virReportSystemError(errno,
                              _("cannot stat path '%s'"),
                              def->target.path);
-        goto cleanup;
+        return -1;
     }
 
     if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &statbuf) < 0)
-        goto cleanup;
+        return -1;
 
     /* VolTargetInfoFD doesn't update capacity correctly for the pool case */
     if (statvfs(def->target.path, &sb) < 0) {
         virReportSystemError(errno,
                              _("cannot statvfs path '%s'"),
                              def->target.path);
-        goto cleanup;
+        return -1;
     }
 
     def->capacity = ((unsigned long long)sb.f_frsize *
@@ -3590,9 +3589,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
     VIR_FREE(def->target.perms.label);
     def->target.perms.label = g_strdup(target->perms->label);
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -3724,7 +3721,6 @@ getNewStyleBlockDevice(const char *lun_path,
 {
     g_autoptr(DIR) block_dir = NULL;
     struct dirent *block_dirent = NULL;
-    int retval = -1;
     int direrr;
     g_autofree char *block_path = NULL;
 
@@ -3733,7 +3729,7 @@ getNewStyleBlockDevice(const char *lun_path,
     VIR_DEBUG("Looking for block device in '%s'", block_path);
 
     if (virDirOpen(&block_dir, block_path) < 0)
-        goto cleanup;
+        return -1;
 
     while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
         *block_device = g_strdup(block_dirent->d_name);
@@ -3744,12 +3740,9 @@ getNewStyleBlockDevice(const char *lun_path,
     }
 
     if (direrr < 0)
-        goto cleanup;
-
-    retval = 0;
+        return -1;
 
- cleanup:
-    return retval;
+    return 0;
 }
 
 
@@ -3796,7 +3789,6 @@ getBlockDevice(uint32_t host,
 {
     g_autoptr(DIR) lun_dir = NULL;
     struct dirent *lun_dirent = NULL;
-    int retval = -1;
     int direrr;
     g_autofree char *lun_path = NULL;
 
@@ -3806,7 +3798,7 @@ getBlockDevice(uint32_t host,
                                target, lun);
 
     if (virDirOpen(&lun_dir, lun_path) < 0)
-        goto cleanup;
+        return -1;
 
     while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
         if (STRPREFIX(lun_dirent->d_name, "block")) {
@@ -3814,27 +3806,23 @@ getBlockDevice(uint32_t host,
                 if (getNewStyleBlockDevice(lun_path,
                                            lun_dirent->d_name,
                                            block_device) < 0)
-                    goto cleanup;
+                    return -1;
             } else {
                 if (getOldStyleBlockDevice(lun_path,
                                            lun_dirent->d_name,
                                            block_device) < 0)
-                    goto cleanup;
+                    return -1;
             }
             break;
         }
     }
     if (direrr < 0)
-        goto cleanup;
-    if (!*block_device) {
-        retval = -2;
-        goto cleanup;
-    }
+        return -1;
 
-    retval = 0;
+    if (!*block_device)
+        return -2;
 
- cleanup:
-    return retval;
+    return 0;
 }
 
 
index 6ba030bf9bbd0bf94cec48b4473628816f72bbbe..e3c45e93cb12c8acaecdc9a3dd4732d76b5ef3e2 100644 (file)
@@ -2465,7 +2465,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
                                const char *taskFile,
                                bool dormdir)
 {
-    int ret = -1;
     int rc;
     bool killedAny = false;
     g_autofree char *keypath = NULL;
@@ -2480,14 +2479,14 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
 
     if ((rc = virCgroupKillInternal(group, signum, pids,
                                     controller, taskFile)) < 0) {
-        goto cleanup;
+        return -1;
     }
     if (rc == 1)
         killedAny = true;
 
     VIR_DEBUG("Iterate over children of %s (killedAny=%d)", keypath, killedAny);
     if ((rc = virDirOpenIfExists(&dp, keypath)) < 0)
-        goto cleanup;
+        return -1;
 
     if (rc == 0) {
         VIR_DEBUG("Path %s does not exist, assuming done", keypath);
@@ -2504,11 +2503,11 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
         VIR_DEBUG("Process subdir %s", ent->d_name);
 
         if (virCgroupNew(-1, ent->d_name, group, -1, &subgroup) < 0)
-            goto cleanup;
+            return -1;
 
         if ((rc = virCgroupKillRecursiveInternal(subgroup, signum, pids,
                                                  controller, taskFile, true)) < 0)
-            goto cleanup;
+            return -1;
         if (rc == 1)
             killedAny = true;
 
@@ -2516,13 +2515,10 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
             virCgroupRemove(subgroup);
     }
     if (direrr < 0)
-        goto cleanup;
+        return -1;
 
  done:
-    ret = killedAny ? 1 : 0;
-
- cleanup:
-    return ret;
+    return killedAny ? 1 : 0;
 }
 
 
index 5ae2ad9ef985e928a9fb0338f567f2808c5cc2f0..9a4f3d7f32d23d95da793590e3da0d84a6e4e1ec 100644 (file)
@@ -456,7 +456,6 @@ virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC_UNUSED,
     struct dirent *entry;
     const char *dirName = "/proc/self/fd";
     int rc;
-    int ret = -1;
 
     if (virDirOpen(&dp, dirName) < 0)
         return -1;
@@ -468,18 +467,16 @@ virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC_UNUSED,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unable to parse FD: %s"),
                            entry->d_name);
-            goto cleanup;
+            return -1;
         }
 
         ignore_value(virBitmapSetBit(fds, fd));
     }
 
     if (rc < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 # else /* !__linux__ */
index 323102d36e53e98eac2b114dadf09448b2916451..6c39a2a44db59e70cb8ce868f2c84869b9896f72 100644 (file)
@@ -171,7 +171,6 @@ virDMSanitizepath(const char *path)
     struct stat sb[2];
     g_autoptr(DIR) dh = NULL;
     const char *p;
-    char *ret = NULL;
 
     /* If a path is NOT provided then assume it's DM name */
     p = strrchr(path, '/');
@@ -206,12 +205,11 @@ virDMSanitizepath(const char *path)
 
         if (stat(tmp, &sb[1]) == 0 &&
             sb[0].st_rdev == sb[0].st_rdev) {
-            ret = g_steal_pointer(&tmp);
-            break;
+            return g_steal_pointer(&tmp);
         }
     }
 
-    return ret;
+    return NULL;
 }
 
 
index fc0021036ab4cf5ad1ce84a4c587f4be192e1a11..9a7dcfc9a66dac3aa8bcfd9e0048f9a1acb081c9 100644 (file)
@@ -836,7 +836,6 @@ static char *
 virFileNBDDeviceFindUnused(void)
 {
     g_autoptr(DIR) dh = NULL;
-    char *ret = NULL;
     struct dirent *de;
     int direrr;
 
@@ -846,21 +845,19 @@ virFileNBDDeviceFindUnused(void)
     while ((direrr = virDirRead(dh, &de, SYSFS_BLOCK_DIR)) > 0) {
         if (STRPREFIX(de->d_name, "nbd")) {
             int rv = virFileNBDDeviceIsBusy(de->d_name);
+
             if (rv < 0)
-                goto cleanup;
-            if (rv == 0) {
-                ret = g_strdup_printf("/dev/%s", de->d_name);
-                goto cleanup;
-            }
+                return NULL;
+
+            if (rv == 0)
+                return g_strdup_printf("/dev/%s", de->d_name);
         }
     }
     if (direrr < 0)
-        goto cleanup;
-    virReportSystemError(EBUSY, "%s",
-                         _("No free NBD devices"));
+        return NULL;
 
- cleanup:
-    return ret;
+    virReportSystemError(EBUSY, "%s", _("No free NBD devices"));
+    return NULL;
 }
 
 static bool
@@ -979,7 +976,6 @@ int virFileDeleteTree(const char *dir)
 {
     g_autoptr(DIR) dh = NULL;
     struct dirent *de;
-    int ret = -1;
     int direrr;
 
     /* Silently return 0 if passed NULL or directory doesn't exist */
@@ -998,35 +994,32 @@ int virFileDeleteTree(const char *dir)
         if (g_lstat(filepath, &sb) < 0) {
             virReportSystemError(errno, _("Cannot access '%s'"),
                                  filepath);
-            goto cleanup;
+            return -1;
         }
 
         if (S_ISDIR(sb.st_mode)) {
             if (virFileDeleteTree(filepath) < 0)
-                goto cleanup;
+                return -1;
         } else {
             if (unlink(filepath) < 0 && errno != ENOENT) {
                 virReportSystemError(errno,
                                      _("Cannot delete file '%s'"),
                                      filepath);
-                goto cleanup;
+                return -1;
             }
         }
     }
     if (direrr < 0)
-        goto cleanup;
+        return -1;
 
     if (rmdir(dir) < 0 && errno != ENOENT) {
         virReportSystemError(errno,
                              _("Cannot delete directory '%s'"),
                              dir);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 /* Like read(), but restarts after EINTR.  Doesn't play
@@ -2949,7 +2942,6 @@ int virFileChownFiles(const char *name,
                       gid_t gid)
 {
     struct dirent *ent;
-    int ret = -1;
     int direrr;
     g_autoptr(DIR) dir = NULL;
 
@@ -2969,17 +2961,14 @@ int virFileChownFiles(const char *name,
                                  _("cannot chown '%s' to (%u, %u)"),
                                  ent->d_name, (unsigned int) uid,
                                  (unsigned int) gid);
-            goto cleanup;
+            return -1;
         }
     }
 
     if (direrr < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 #else /* WIN32 */
index 256179c052fbf9c8b037ec38e199ce6999991957..5104bbe7c52d7f92d46334ad2ea7a37b21a0511f 100644 (file)
@@ -2900,7 +2900,6 @@ virNetDevRDMAFeature(const char *ifname,
     g_autofree char *eth_res_buf = NULL;
     g_autoptr(DIR) dirp = NULL;
     struct dirent *dp;
-    int ret = -1;
 
     if (!virFileExists(SYSFS_INFINIBAND_DIR))
         return 0;
@@ -2913,12 +2912,11 @@ virNetDevRDMAFeature(const char *ifname,
     /* If /sys/class/net/<ifname>/device/resource doesn't exist it is not a PCI
      * device and therefore it will not have RDMA. */
     if (!virFileExists(eth_devpath)) {
-        ret = 0;
-        goto cleanup;
+        return 0;
     }
 
     if (virFileReadAll(eth_devpath, RESOURCE_FILE_LEN, &eth_res_buf) < 0)
-        goto cleanup;
+        return -1;
 
     while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) {
         g_autofree char *ib_res_buf = NULL;
@@ -2931,10 +2929,8 @@ virNetDevRDMAFeature(const char *ifname,
             break;
         }
     }
-    ret = 0;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
index 51a5d6e8a65f7573b4f01b5eaadea1d35afad69d..a05e4ac72ca16804cffec19664084dc2e3f87334 100644 (file)
@@ -739,7 +739,6 @@ virNumaGetPages(int node,
                 unsigned long long **pages_free,
                 size_t *npages)
 {
-    int ret = -1;
     g_autoptr(DIR) dir = NULL;
     int direrr = 0;
     struct dirent *entry;
@@ -763,12 +762,12 @@ virNumaGetPages(int node,
      * slightly different information. So we take the total memory on a node
      * and subtract memory taken by the huge pages. */
     if (virNumaGetHugePageInfoDir(&path, node) < 0)
-        goto cleanup;
+        return -1;
 
     /* It's okay if the @path doesn't exist. Maybe we are running on
      * system without huge pages support where the path may not exist. */
     if (virDirOpenIfExists(&dir, path) < 0)
-        goto cleanup;
+        return -1;
 
     while (dir && (direrr = virDirRead(dir, &entry, path)) > 0) {
         const char *page_name = entry->d_name;
@@ -789,17 +788,17 @@ virNumaGetPages(int node,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unable to parse %s"),
                            entry->d_name);
-            goto cleanup;
+            return -1;
         }
 
         if (virNumaGetHugePageInfo(node, page_size,
                                    &page_avail, &page_free) < 0)
-            goto cleanup;
+            return -1;
 
         if (VIR_REALLOC_N(tmp_size, ntmp + 1) < 0 ||
             VIR_REALLOC_N(tmp_avail, ntmp + 1) < 0 ||
             VIR_REALLOC_N(tmp_free, ntmp + 1) < 0)
-            goto cleanup;
+            return -1;
 
         tmp_size[ntmp] = page_size;
         tmp_avail[ntmp] = page_avail;
@@ -812,17 +811,17 @@ virNumaGetPages(int node,
     }
 
     if (direrr < 0)
-        goto cleanup;
+        return -1;
 
     /* Now append the ordinary system pages */
     if (VIR_REALLOC_N(tmp_size, ntmp + 1) < 0 ||
         VIR_REALLOC_N(tmp_avail, ntmp + 1) < 0 ||
         VIR_REALLOC_N(tmp_free, ntmp + 1) < 0)
-        goto cleanup;
+        return -1;
 
     if (virNumaGetPageInfo(node, system_page_size, huge_page_sum,
                            &tmp_avail[ntmp], &tmp_free[ntmp]) < 0)
-        goto cleanup;
+        return -1;
     tmp_size[ntmp] = system_page_size;
     ntmp++;
 
@@ -852,9 +851,7 @@ virNumaGetPages(int node,
         tmp_free = NULL;
     }
     *npages = ntmp;
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
index 025eb9d91cb2bae11f6c798c755955f35aebd765..a501db6ff7644698148ef6c4dfaf6365a4ef5d4d 100644 (file)
@@ -1706,7 +1706,6 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
 {
     g_autofree char *pcidir = NULL;
     g_autoptr(DIR) dir = NULL;
-    int ret = -1;
     struct dirent *ent;
     int direrr;
 
@@ -1715,7 +1714,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
                              dev->address.function);
 
     if (virDirOpen(&dir, pcidir) < 0)
-        goto cleanup;
+        return -1;
 
     while ((direrr = virDirRead(dir, &ent, pcidir)) > 0) {
         g_autofree char *file = NULL;
@@ -1731,16 +1730,13 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
             STREQ(ent->d_name, "reset")) {
             file = g_strdup_printf("%s/%s", pcidir, ent->d_name);
             if ((actor)(dev, file, opaque) < 0)
-                goto cleanup;
+                return -1;
         }
     }
     if (direrr < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -1756,7 +1752,6 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
 {
     g_autofree char *groupPath = NULL;
     g_autoptr(DIR) groupDir = NULL;
-    int ret = -1;
     struct dirent *ent;
     int direrr;
 
@@ -1765,8 +1760,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
 
     if (virDirOpenQuiet(&groupDir, groupPath) < 0) {
         /* just process the original device, nothing more */
-        ret = (actor)(orig, opaque);
-        goto cleanup;
+        return (actor)(orig, opaque);
     }
 
     while ((direrr = virDirRead(groupDir, &ent, groupPath)) > 0) {
@@ -1776,19 +1770,16 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Found invalid device link '%s' in '%s'"),
                            ent->d_name, groupPath);
-            goto cleanup;
+            return -1;
         }
 
         if ((actor)(&newDev, opaque) < 0)
-            goto cleanup;
+            return -1;
     }
     if (direrr < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
index aa466592fcdfb616505d2523ed872fc7c481da58..d3087b98c1124b5222d1b4a4c520c842d179e839 100644 (file)
@@ -786,23 +786,18 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
 
     ret = virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info");
     if (ret <= 0)
-        goto cleanup;
+        return ret;
 
-    ret = virResctrlGetMemoryBandwidthInfo(resctrl);
-    if (ret < 0)
-        goto cleanup;
+    if ((ret = virResctrlGetMemoryBandwidthInfo(resctrl)) < 0)
+        return -1;
 
-    ret = virResctrlGetCacheInfo(resctrl, dirp);
-    if (ret < 0)
-        goto cleanup;
+    if ((ret = virResctrlGetCacheInfo(resctrl, dirp)) < 0)
+        return -1;
 
-    ret = virResctrlGetMonitorInfo(resctrl);
-    if (ret < 0)
-        goto cleanup;
+    if ((ret = virResctrlGetMonitorInfo(resctrl)) < 0)
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
index 256acc37fafd68c857c14e48f27110bfab8c7b40..22d46793681dd07e31689305681a918ee530ef1a 100644 (file)
@@ -109,7 +109,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
     g_autoptr(DIR) dir = NULL;
     struct dirent *entry;
     g_autofree char *path = NULL;
-    char *sg = NULL;
     unsigned int adapter_id;
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
 
@@ -120,16 +119,13 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
                            bus, target, unit);
 
     if (virDirOpen(&dir, path) < 0)
-        goto cleanup;
+        return NULL;
 
-    while (virDirRead(dir, &entry, path) > 0) {
-        /* Assume a single directory entry */
-        sg = g_strdup(entry->d_name);
-        break;
-    }
+    /* Assume a single directory entry */
+    if (virDirRead(dir, &entry, path) > 0)
+        return  g_strdup(entry->d_name);
 
- cleanup:
-    return sg;
+    return NULL;
 }
 
 /* Returns device name (e.g. "sdc") on success, or NULL
@@ -145,7 +141,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
     g_autoptr(DIR) dir = NULL;
     struct dirent *entry;
     g_autofree char *path = NULL;
-    char *name = NULL;
     unsigned int adapter_id;
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
 
@@ -156,15 +151,12 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
                            target, unit);
 
     if (virDirOpen(&dir, path) < 0)
-        goto cleanup;
+        return NULL;
 
-    while (virDirRead(dir, &entry, path) > 0) {
-        name = g_strdup(entry->d_name);
-        break;
-    }
+    if (virDirRead(dir, &entry, path) > 0)
+        return g_strdup(entry->d_name);
 
- cleanup:
-    return name;
+    return NULL;
 }
 
 virSCSIDevicePtr
index 41e92023fc7a4502e0c9d3b619c5e5a61cb8db17..a0cd0f1bcd0083f393e3bb85efe8f3d24d11762a 100644 (file)
@@ -1623,22 +1623,18 @@ virHostHasIOMMU(void)
 {
     g_autoptr(DIR) iommuDir = NULL;
     struct dirent *iommuGroup = NULL;
-    bool ret = false;
     int direrr;
 
     if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
-        goto cleanup;
+        return false;
 
     while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0)
         break;
 
     if (direrr < 0 || !iommuGroup)
-        goto cleanup;
-
-    ret = true;
+        return false;
 
- cleanup:
-    return ret;
+    return true;
 }
 
 
@@ -1656,7 +1652,6 @@ virHostHasIOMMU(void)
 char *
 virHostGetDRMRenderNode(void)
 {
-    char *ret = NULL;
     g_autoptr(DIR) driDir = NULL;
     const char *driPath = "/dev/dri";
     struct dirent *ent = NULL;
@@ -1674,19 +1669,16 @@ virHostGetDRMRenderNode(void)
     }
 
     if (dirErr < 0)
-        goto cleanup;
+        return NULL;
 
     /* even if /dev/dri exists, there might be no renderDX nodes available */
     if (!have_rendernode) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("No DRM render nodes available"));
-        goto cleanup;
+        return NULL;
     }
 
-    ret = g_strdup_printf("%s/%s", driPath, ent->d_name);
-
- cleanup:
-    return ret;
+    return g_strdup_printf("%s/%s", driPath, ent->d_name);
 }
 
 
index 471d94d3dd0363ef183d12c0122df36d9849ddb3..a4e88024d1cbe159d6e43f74ff10168d7e306581 100644 (file)
@@ -365,7 +365,6 @@ virVHBAGetHostByWWN(const char *sysfs_prefix,
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
     struct dirent *entry = NULL;
     g_autoptr(DIR) dir = NULL;
-    char *ret = NULL;
 
     if (virDirOpen(&dir, prefix) < 0)
         return NULL;
@@ -375,24 +374,22 @@ virVHBAGetHostByWWN(const char *sysfs_prefix,
 
         if ((rc = vhbaReadCompareWWN(prefix, entry->d_name,
                                      "node_name", wwnn)) < 0)
-            goto cleanup;
+            return NULL;
 
         if (rc == 0)
             continue;
 
         if ((rc = vhbaReadCompareWWN(prefix, entry->d_name,
                                      "port_name", wwpn)) < 0)
-            goto cleanup;
+            return NULL;
 
         if (rc == 0)
             continue;
 
-        ret = g_strdup(entry->d_name);
-        break;
+        return g_strdup(entry->d_name);
     }
 
- cleanup:
-    return ret;
+    return NULL;
 }
 
 /* virVHBAGetHostByFabricWWN:
index 5ae1d64337a96d805e0653b7e130f0027db0098b..c6848c12a2af4ed5b7e97a2c0e2250946cc7bd60 100644 (file)
@@ -516,12 +516,11 @@ testQemuGetLatestCapsForArch(const char *arch,
     unsigned long maxver = 0;
     unsigned long ver;
     g_autofree char *maxname = NULL;
-    char *ret = NULL;
 
     fullsuffix = g_strdup_printf("%s.%s", arch, suffix);
 
     if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0)
-        goto cleanup;
+        return NULL;
 
     while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
         g_autofree char *tmp = NULL;
@@ -547,18 +546,15 @@ testQemuGetLatestCapsForArch(const char *arch,
     }
 
     if (rc < 0)
-        goto cleanup;
+        return NULL;
 
     if (!maxname) {
         VIR_TEST_VERBOSE("failed to find capabilities for '%s' in '%s'",
                          arch, TEST_QEMU_CAPS_PATH);
-        goto cleanup;
+        return NULL;
     }
 
-    ret = g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
-
- cleanup:
-    return ret;
+    return g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
 }
 
 
@@ -607,7 +603,6 @@ testQemuCapsIterate(const char *suffix,
     struct dirent *ent;
     g_autoptr(DIR) dir = NULL;
     int rc;
-    int ret = -1;
     bool fail = false;
 
     if (!callback)
@@ -616,11 +611,11 @@ testQemuCapsIterate(const char *suffix,
     /* Validate suffix */
     if (!STRPREFIX(suffix, ".")) {
         VIR_TEST_VERBOSE("malformed suffix '%s'", suffix);
-        goto cleanup;
+        return -1;
     }
 
     if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0)
-        goto cleanup;
+        return -1;
 
     while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
         g_autofree char *tmp = g_strdup(ent->d_name);
@@ -634,13 +629,13 @@ testQemuCapsIterate(const char *suffix,
         /* Strip the leading prefix */
         if (!(version = STRSKIP(tmp, "caps_"))) {
             VIR_TEST_VERBOSE("malformed file name '%s'", ent->d_name);
-            goto cleanup;
+            return -1;
         }
 
         /* Find the last dot */
         if (!(archName = strrchr(tmp, '.'))) {
             VIR_TEST_VERBOSE("malformed file name '%s'", ent->d_name);
-            goto cleanup;
+            return -1;
         }
 
         /* The version number and the architecture name are separated by
@@ -661,12 +656,9 @@ testQemuCapsIterate(const char *suffix,
     }
 
     if (rc < 0 || fail)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }