[PATCH v1 14/21] util: remove unneeded cleanup labels

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

 



Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/util/vircgroupv1.c     | 18 ++++---------
 src/util/vircommand.c      | 11 +++-----
 src/util/virdbus.c         | 30 +++++++--------------
 src/util/virfile.c         | 19 +++++--------
 src/util/virhash.c         |  6 ++---
 src/util/virhostcpu.c      | 20 ++++++--------
 src/util/virhostdev.c      |  7 ++---
 src/util/virhostmem.c      | 55 +++++++++++++-------------------------
 src/util/virjson.c         | 30 +++++++++------------
 src/util/virmacmap.c       | 10 +++----
 src/util/virnetdevbridge.c | 21 +++++----------
 src/util/virnuma.c         | 27 +++++++------------
 src/util/virpci.c          |  7 ++---
 src/util/virprocess.c      | 19 +++++--------
 src/util/virresctrl.c      |  7 ++---
 src/util/virstoragefile.c  | 46 +++++++++++--------------------
 src/util/virutil.c         | 19 ++++++-------
 17 files changed, 117 insertions(+), 235 deletions(-)

diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 0820c5d638..d70e910b4c 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -708,7 +708,6 @@ virCgroupV1AddTask(virCgroupPtr group,
                    pid_t pid,
                    unsigned int flags)
 {
-    int ret = -1;
     size_t i;
 
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
@@ -724,12 +723,10 @@ virCgroupV1AddTask(virCgroupPtr group,
             continue;
 
         if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
-            goto cleanup;
+            return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -1845,18 +1842,13 @@ static int
 virCgroupV1AllowAllDevices(virCgroupPtr group,
                            int perms)
 {
-    int ret = -1;
-
     if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0)
-        goto cleanup;
+        return -1;
 
     if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 223a2a824e..240a670ea1 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -405,8 +405,6 @@ virCommandHandshakeChild(virCommandPtr cmd)
 static int
 virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
 {
-    int ret = -1;
-
     if (cmd->uid != (uid_t)-1 || cmd->gid != (gid_t)-1 ||
         cmd->capabilities || (cmd->flags & VIR_EXEC_CLEAR_CAPS)) {
         VIR_DEBUG("Setting child uid:gid to %d:%d with caps %llx",
@@ -414,7 +412,7 @@ virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
         if (virSetUIDGIDWithCaps(cmd->uid, cmd->gid, groups, ngroups,
                                  cmd->capabilities,
                                  !!(cmd->flags & VIR_EXEC_CLEAR_CAPS)) < 0)
-            goto cleanup;
+            return -1;
     }
 
     if (cmd->pwd) {
@@ -422,13 +420,10 @@ virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
         if (chdir(cmd->pwd) < 0) {
             virReportSystemError(errno,
                                  _("Unable to change to %s"), cmd->pwd);
-            goto cleanup;
+            return -1;
         }
     }
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 # ifdef __linux__
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index 89c9cb3e24..e44d2bc6a1 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -1194,7 +1194,6 @@ int virDBusMessageDecodeArgs(DBusMessage* msg,
                              va_list args)
 {
     DBusMessageIter iter;
-    int ret = -1;
 
     if (!dbus_message_iter_init(msg, &iter)) {
         if (*types != '\0') {
@@ -1202,15 +1201,12 @@ int virDBusMessageDecodeArgs(DBusMessage* msg,
                            _("No args present for signature %s"),
                            types);
         } else {
-            ret = 0;
+            return 0;
         }
-        goto cleanup;
+        return -1;
     }
 
-    ret = virDBusMessageIterDecode(&iter, types, args);
-
- cleanup:
-    return ret;
+    return virDBusMessageIterDecode(&iter, types, args);
 }
 
 
@@ -1399,25 +1395,21 @@ int virDBusCreateMethodV(DBusMessage **call,
                          const char *types,
                          va_list args)
 {
-    int ret = -1;
-
     if (!(*call = dbus_message_new_method_call(destination,
                                                path,
                                                iface,
                                                member))) {
         virReportOOMError();
-        goto cleanup;
+        return -1;
     }
 
     if (virDBusMessageEncodeArgs(*call, types, args) < 0) {
         virDBusMessageUnref(*call);
         *call = NULL;
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -1471,22 +1463,18 @@ int virDBusCreateReplyV(DBusMessage **reply,
                         const char *types,
                         va_list args)
 {
-    int ret = -1;
-
     if (!(*reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN))) {
         virReportOOMError();
-        goto cleanup;
+        return -1;
     }
 
     if (virDBusMessageEncodeArgs(*reply, types, args) < 0) {
         virDBusMessageUnref(*reply);
         *reply = NULL;
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virfile.c b/src/util/virfile.c
index c4d544be73..10526dc644 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3610,27 +3610,25 @@ int
 virFileGetHugepageSize(const char *path,
                        unsigned long long *size)
 {
-    int ret = -1;
     struct statfs fs;
 
     if (statfs(path, &fs) < 0) {
         virReportSystemError(errno,
                              _("cannot determine filesystem for '%s'"),
                              path);
-        goto cleanup;
+        return -1;
     }
 
     if (fs.f_type != HUGETLBFS_MAGIC) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("not a hugetlbfs mount: '%s'"),
                        path);
-        goto cleanup;
+        return -1;
     }
 
     *size = fs.f_bsize / 1024; /* we are storing size in KiB */
-    ret = 0;
- cleanup:
-    return ret;
+
+    return 0;
 }
 
 # define PROC_MEMINFO "/proc/meminfo"
@@ -3802,12 +3800,11 @@ virFileSetupDev(const char *path,
 {
     const unsigned long mount_flags = MS_NOSUID;
     const char *mount_fs = "tmpfs";
-    int ret = -1;
 
     if (virFileMakePath(path) < 0) {
         virReportSystemError(errno,
                              _("Failed to make path %s"), path);
-        goto cleanup;
+        return -1;
     }
 
     VIR_DEBUG("Mount devfs on %s type=tmpfs flags=0x%lx, opts=%s",
@@ -3816,12 +3813,10 @@ virFileSetupDev(const char *path,
         virReportSystemError(errno,
                              _("Failed to mount devfs on %s type %s (%s)"),
                              path, mount_fs, mount_options);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virhash.c b/src/util/virhash.c
index 05a3b803f2..1df7f6efca 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -646,15 +646,13 @@ virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
             ret = iter(entry->payload, entry->name, data);
 
             if (ret < 0)
-                goto cleanup;
+                return ret;
 
             entry = next;
         }
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index d544d36c61..5a7b61e0d7 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -776,7 +776,6 @@ virHostCPUGetStatsLinux(FILE *procstat,
                         virNodeCPUStatsPtr params,
                         int *nparams)
 {
-    int ret = -1;
     char line[1024];
     unsigned long long usr, ni, sys, idle, iowait;
     unsigned long long irq, softirq, steal, guest, guest_nice;
@@ -785,15 +784,14 @@ virHostCPUGetStatsLinux(FILE *procstat,
     if ((*nparams) == 0) {
         /* Current number of cpu stats supported by linux */
         *nparams = LINUX_NB_CPU_STATS;
-        ret = 0;
-        goto cleanup;
+        return 0;
     }
 
     if ((*nparams) != LINUX_NB_CPU_STATS) {
         virReportInvalidArg(*nparams,
                             _("nparams in %s must be equal to %d"),
                             __FUNCTION__, LINUX_NB_CPU_STATS);
-        goto cleanup;
+        return -1;
     }
 
     if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) {
@@ -816,22 +814,21 @@ virHostCPUGetStatsLinux(FILE *procstat,
 
             if (virHostCPUStatsAssign(&params[0], VIR_NODE_CPU_STATS_KERNEL,
                                       (sys + irq + softirq) * TICK_TO_NSEC) < 0)
-                goto cleanup;
+                return -1;
 
             if (virHostCPUStatsAssign(&params[1], VIR_NODE_CPU_STATS_USER,
                                       (usr + ni) * TICK_TO_NSEC) < 0)
-                goto cleanup;
+                return -1;
 
             if (virHostCPUStatsAssign(&params[2], VIR_NODE_CPU_STATS_IDLE,
                                       idle * TICK_TO_NSEC) < 0)
-                goto cleanup;
+                return -1;
 
             if (virHostCPUStatsAssign(&params[3], VIR_NODE_CPU_STATS_IOWAIT,
                                       iowait * TICK_TO_NSEC) < 0)
-                goto cleanup;
+                return -1;
 
-            ret = 0;
-            goto cleanup;
+            return 0;
         }
     }
 
@@ -839,8 +836,7 @@ virHostCPUGetStatsLinux(FILE *procstat,
                         _("Invalid cpuNum in %s"),
                         __FUNCTION__);
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 010eb551a9..c35b6ff3b6 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -80,7 +80,6 @@ struct virHostdevIsPCINodeDeviceUsedData {
 static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *opaque)
 {
     virPCIDevicePtr actual;
-    int ret = -1;
     struct virHostdevIsPCINodeDeviceUsedData *helperData = opaque;
 
     actual = virPCIDeviceListFindByIDs(helperData->mgr->activePCIHostdevs,
@@ -106,12 +105,10 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
             virReportError(VIR_ERR_OPERATION_INVALID,
                            _("PCI device %s is in use"),
                            virPCIDeviceGetName(actual));
-        goto cleanup;
+        return -1;
     }
  iommu_owner:
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int virHostdevManagerOnceInit(void)
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index c1dfc1225c..0918ede7c2 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -142,7 +142,6 @@ virHostMemGetStatsLinux(FILE *meminfo,
                         virNodeMemoryStatsPtr params,
                         int *nparams)
 {
-    int ret = -1;
     size_t i = 0, j = 0, k = 0;
     int found = 0;
     int nr_param;
@@ -169,15 +168,14 @@ virHostMemGetStatsLinux(FILE *meminfo,
     if ((*nparams) == 0) {
         /* Current number of memory stats supported by linux */
         *nparams = nr_param;
-        ret = 0;
-        goto cleanup;
+        return 0;
     }
 
     if ((*nparams) != nr_param) {
         virReportInvalidArg(nparams,
                             _("nparams in %s must be %d"),
                             __FUNCTION__, nr_param);
-        goto cleanup;
+        return -1;
     }
 
     while (fgets(line, sizeof(line), meminfo) != NULL) {
@@ -200,7 +198,7 @@ virHostMemGetStatsLinux(FILE *meminfo,
                 if (p == NULL) {
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    "%s", _("no prefix found"));
-                    goto cleanup;
+                    return -1;
                 }
                 p++;
             }
@@ -219,7 +217,7 @@ virHostMemGetStatsLinux(FILE *meminfo,
                 if (virStrcpyStatic(param->field, convp->field) < 0) {
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    "%s", _("Field kernel memory too long for destination"));
-                    goto cleanup;
+                    return -1;
                 }
                 param->value = val;
                 found++;
@@ -233,13 +231,10 @@ virHostMemGetStatsLinux(FILE *meminfo,
     if (found == 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("no available memory line found"));
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 #endif
 
@@ -620,14 +615,12 @@ static int
 virHostMemGetInfoFake(unsigned long long *mem,
                       unsigned long long *freeMem)
 {
-    int ret = -1;
-
     if (mem) {
         double total = physmem_total();
         if (!total) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Cannot determine free memory"));
-            goto cleanup;
+            return -1;
         }
 
         *mem = (unsigned long long) total;
@@ -639,15 +632,13 @@ virHostMemGetInfoFake(unsigned long long *mem,
         if (!avail) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Cannot determine free memory"));
-            goto cleanup;
+            return -1;
         }
 
         *freeMem = (unsigned long long) avail;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -658,7 +649,6 @@ virHostMemGetCellsFree(unsigned long long *freeMems,
 {
     unsigned long long mem;
     int n, lastCell, numCells;
-    int ret = -1;
     int maxCell;
 
     if (!virNumaIsAvailable())
@@ -672,7 +662,7 @@ virHostMemGetCellsFree(unsigned long long *freeMems,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("start cell %d out of range (0-%d)"),
                        startCell, maxCell);
-        goto cleanup;
+        return -1;
     }
     lastCell = startCell + maxCells - 1;
     if (lastCell > maxCell)
@@ -683,10 +673,7 @@ virHostMemGetCellsFree(unsigned long long *freeMems,
 
         freeMems[numCells++] = mem;
     }
-    ret = numCells;
-
- cleanup:
-    return ret;
+    return numCells;
 }
 
 int
@@ -734,7 +721,6 @@ virHostMemGetFreePages(unsigned int npages,
                        unsigned int cellCount,
                        unsigned long long *counts)
 {
-    int ret = -1;
     int cell, lastCell;
     size_t i, ncounts = 0;
 
@@ -745,7 +731,7 @@ virHostMemGetFreePages(unsigned int npages,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("start cell %d out of range (0-%d)"),
                        startCell, lastCell);
-        goto cleanup;
+        return -1;
     }
 
     lastCell = MIN(lastCell, startCell + (int) cellCount - 1);
@@ -756,7 +742,7 @@ virHostMemGetFreePages(unsigned int npages,
             unsigned long long page_free;
 
             if (virNumaGetPageInfo(cell, page_size, 0, NULL, &page_free) < 0)
-                goto cleanup;
+                return -1;
 
             counts[ncounts++] = page_free;
         }
@@ -765,12 +751,10 @@ virHostMemGetFreePages(unsigned int npages,
     if (!ncounts) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("no suitable info found"));
-        goto cleanup;
+        return -1;
     }
 
-    ret = ncounts;
- cleanup:
-    return ret;
+    return ncounts;
 }
 
 int
@@ -781,7 +765,6 @@ virHostMemAllocPages(unsigned int npages,
                      unsigned int cellCount,
                      bool add)
 {
-    int ret = -1;
     int cell, lastCell;
     size_t i, ncounts = 0;
 
@@ -792,7 +775,7 @@ virHostMemAllocPages(unsigned int npages,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("start cell %d out of range (0-%d)"),
                        startCell, lastCell);
-        goto cleanup;
+        return -1;
     }
 
     lastCell = MIN(lastCell, startCell + (int) cellCount - 1);
@@ -803,13 +786,11 @@ virHostMemAllocPages(unsigned int npages,
             unsigned long long page_count = pageCounts[i];
 
             if (virNumaSetPagePoolSize(cell, page_size, page_count, add) < 0)
-                goto cleanup;
+                return -1;
 
             ncounts++;
         }
     }
 
-    ret = ncounts;
- cleanup:
-    return ret;
+    return ncounts;
 }
diff --git a/src/util/virjson.c b/src/util/virjson.c
index eb6207f13f..1b1be81a1a 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -160,7 +160,6 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
 {
     char type;
     char *key;
-    int ret = -1;
     int rc;
 
     while ((key = va_arg(args, char *)) != NULL) {
@@ -169,7 +168,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("argument key '%s' is too short, missing type prefix"),
                            key);
-            goto cleanup;
+            return -1;
         }
 
         type = key[0];
@@ -187,7 +186,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("argument key '%s' must not have null value"),
                                key);
-                goto cleanup;
+                return -1;
             }
             rc = virJSONValueObjectAppendString(obj, key, val);
         }   break;
@@ -202,7 +201,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("argument key '%s' must not be negative"),
                                key);
-                goto cleanup;
+                return -1;
             }
 
             if (!val && (type == 'z' || type == 'y'))
@@ -231,7 +230,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("argument key '%s' must not be negative"),
                                key);
-                goto cleanup;
+                return -1;
             }
 
             if (!val && (type == 'Z' || type == 'Y'))
@@ -296,7 +295,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("argument key '%s' must not have null value"),
                                key);
-                goto cleanup;
+                return -1;
             }
 
             if ((rc = virJSONValueObjectAppend(obj, key, *val)) == 0)
@@ -315,11 +314,11 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("argument key '%s' must not have null value"),
                                key);
-                goto cleanup;
+                return -1;
             }
 
             if (!(jsonMap = virJSONValueNewArrayFromBitmap(map)))
-                goto cleanup;
+                return -1;
 
             if ((rc = virJSONValueObjectAppend(obj, key, jsonMap)) < 0)
                 virJSONValueFree(jsonMap);
@@ -328,23 +327,18 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
         default:
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unsupported data type '%c' for arg '%s'"), type, key - 2);
-            goto cleanup;
+            return -1;
         }
 
         if (rc < 0)
-            goto cleanup;
+            return -1;
     }
 
     /* verify that we added at least one key-value pair */
-    if (virJSONValueObjectKeysNumber(obj) == 0) {
-        ret = 0;
-        goto cleanup;
-    }
-
-    ret = 1;
+    if (virJSONValueObjectKeysNumber(obj) == 0)
+        return 0;
 
- cleanup:
-    return ret;
+    return 1;
 }
 
 
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index 43cefc1e8e..ee8633281b 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -85,22 +85,18 @@ virMacMapAddLocked(virMacMapPtr mgr,
                    const char *domain,
                    const char *mac)
 {
-    int ret = -1;
     char **macsList = NULL;
 
     if ((macsList = virHashLookup(mgr->macs, domain)) &&
         virStringListHasString((const char**) macsList, mac)) {
-        ret = 0;
-        goto cleanup;
+        return 0;
     }
 
     if (virStringListAdd(&macsList, mac) < 0 ||
         virHashUpdateEntry(mgr->macs, domain, macsList) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
index edf4cc6236..5dca8fdfae 100644
--- a/src/util/virnetdevbridge.c
+++ b/src/util/virnetdevbridge.c
@@ -274,16 +274,13 @@ virNetDevBridgePortGetLearning(const char *brname,
                                const char *ifname,
                                bool *enable)
 {
-    int ret = -1;
     unsigned long value;
 
     if (virNetDevBridgePortGet(brname, ifname, "learning", &value) < 0)
-       goto cleanup;
+       return -1;
 
     *enable = !!value;
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -301,16 +298,13 @@ virNetDevBridgePortGetUnicastFlood(const char *brname,
                                    const char *ifname,
                                    bool *enable)
 {
-    int ret = -1;
     unsigned long value;
 
     if (virNetDevBridgePortGet(brname, ifname, "unicast_flood", &value) < 0)
-       goto cleanup;
+       return -1;
 
     *enable = !!value;
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -863,16 +857,13 @@ int
 virNetDevBridgeGetVlanFiltering(const char *brname,
                                 bool *enable)
 {
-    int ret = -1;
     unsigned long value;
 
     if (virNetDevBridgeGet(brname, "vlan_filtering", &value) < 0)
-        goto cleanup;
+        return -1;
 
     *enable = !!value;
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 448833d8d1..761770979b 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -93,7 +93,6 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
 {
     nodemask_t mask;
     int node = -1;
-    int ret = -1;
     int bit = 0;
     size_t i;
     int maxnode = 0;
@@ -140,7 +139,7 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("NUMA memory tuning in 'preferred' mode "
                                    "only supports single node"));
-            goto cleanup;
+            return -1;
         }
 
         numa_set_bind_policy(0);
@@ -155,10 +154,8 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
     case VIR_DOMAIN_NUMATUNE_MEM_LAST:
         break;
     }
-    ret = 0;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 bool
@@ -466,7 +463,6 @@ virNumaGetDistances(int node,
                     int **distances,
                     int *ndistances)
 {
-    int ret = -1;
     int max_node;
     size_t i;
 
@@ -478,10 +474,10 @@ virNumaGetDistances(int node,
     }
 
     if ((max_node = virNumaGetMaxNode()) < 0)
-        goto cleanup;
+        return -1;
 
     if (VIR_ALLOC_N(*distances, max_node + 1) < 0)
-        goto cleanup;
+        return -1;
 
     *ndistances = max_node + 1;
 
@@ -492,9 +488,7 @@ virNumaGetDistances(int node,
         (*distances)[i] = numa_distance(node, i);
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 #else /* !(WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET) */
@@ -689,7 +683,6 @@ virNumaGetPageInfo(int node,
                    unsigned long long *page_avail,
                    unsigned long long *page_free)
 {
-    int ret = -1;
     long system_page_size = virGetSystemPageSize();
 
     /* sysconf() returns page size in bytes,
@@ -701,10 +694,10 @@ virNumaGetPageInfo(int node,
          * account. The problem is huge pages cut off regular memory. */
         if (node == -1) {
             if (virHostMemGetInfo(&memsize, &memfree) < 0)
-                goto cleanup;
+                return -1;
         } else {
             if (virNumaGetNodeMemory(node, &memsize, &memfree) < 0)
-                goto cleanup;
+                return -1;
         }
 
         /* see description above */
@@ -717,12 +710,10 @@ virNumaGetPageInfo(int node,
             *page_free = memfree / system_page_size;
     } else {
         if (virNumaGetHugePageInfo(node, page_size, page_avail, page_free) < 0)
-            goto cleanup;
+            return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virpci.c b/src/util/virpci.c
index f9e39e79d8..a39c2be29f 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1908,18 +1908,15 @@ virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
                                           virPCIDeviceAddressPtr **iommuGroupDevices,
                                           size_t *nIommuGroupDevices)
 {
-    int ret = -1;
     virPCIDeviceAddressList addrList = { iommuGroupDevices,
                                          nIommuGroupDevices };
 
     if (virPCIDeviceAddressIOMMUGroupIterate(devAddr,
                                              virPCIGetIOMMUGroupAddressesAddOne,
                                              &addrList) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index b5fda05e0c..2073664303 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -349,7 +349,6 @@ int
 virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
 {
     size_t i;
-    int ret = -1;
     /* This is in 1/5th seconds since polling is on a 0.2s interval */
     unsigned int polldelay = (force ? 200 : 75) + (extradelay*5);
     const char *signame = "TERM";
@@ -393,10 +392,9 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
                 virReportSystemError(errno,
                                      _("Failed to terminate process %lld with SIG%s"),
                                      (long long)pid, signame);
-                goto cleanup;
+                return -1;
             }
-            ret = signum == SIGTERM ? 0 : 1;
-            goto cleanup; /* process is dead */
+            return signum == SIGTERM ? 0 : 1;
         }
 
         g_usleep(200 * 1000);
@@ -406,8 +404,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
                          _("Failed to terminate process %lld with SIG%s"),
                          (long long)pid, signame);
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -1183,23 +1180,19 @@ virProcessRunInFork(virProcessForkCallback cb,
 int
 virProcessSetupPrivateMountNS(void)
 {
-    int ret = -1;
-
     if (unshare(CLONE_NEWNS) < 0) {
         virReportSystemError(errno, "%s",
                              _("Cannot unshare mount namespace"));
-        goto cleanup;
+        return -1;
     }
 
     if (mount("", "/", "none", MS_SLAVE|MS_REC, NULL) < 0) {
         virReportSystemError(errno, "%s",
                              _("Failed to switch root mount into slave mode"));
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 #else /* !defined(HAVE_SYS_MOUNT_H) || !defined(HAVE_UNSHARE) */
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 29ea52a16f..90eee9e6b5 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -871,7 +871,6 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
     virResctrlInfoPerLevelPtr i_level = NULL;
     virResctrlInfoPerTypePtr i_type = NULL;
     size_t i = 0;
-    int ret = -1;
 
     if (virResctrlInfoIsEmpty(resctrl))
         return 0;
@@ -928,14 +927,12 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
         memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control));
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
  error:
     while (*ncontrols)
         VIR_FREE((*controls)[--*ncontrols]);
     VIR_FREE(*controls);
-    goto cleanup;
+    return -1;
 }
 
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index be2b5479bb..b640957bb3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -601,11 +601,10 @@ vmdk4GetBackingStore(char **res,
     static const char prefix[] = "parentFileNameHint=\"";
     char *start, *end;
     size_t len;
-    int ret = BACKING_STORE_ERROR;
     g_autofree char *desc = NULL;
 
     if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0)
-        goto cleanup;
+        return BACKING_STORE_ERROR;
 
     *res = NULL;
     /*
@@ -617,10 +616,9 @@ vmdk4GetBackingStore(char **res,
      */
     *format = VIR_STORAGE_FILE_AUTO;
 
-    if (buf_size <= 0x200) {
-        ret = BACKING_STORE_INVALID;
-        goto cleanup;
-    }
+    if (buf_size <= 0x200)
+        return BACKING_STORE_INVALID;
+
     len = buf_size - 0x200;
     if (len > VIR_STORAGE_MAX_HEADER)
         len = VIR_STORAGE_MAX_HEADER;
@@ -629,27 +627,21 @@ vmdk4GetBackingStore(char **res,
     start = strstr(desc, prefix);
     if (start == NULL) {
         *format = VIR_STORAGE_FILE_NONE;
-        ret = BACKING_STORE_OK;
-        goto cleanup;
+        return BACKING_STORE_OK;
     }
     start += strlen(prefix);
     end = strchr(start, '"');
-    if (end == NULL) {
-        ret = BACKING_STORE_INVALID;
-        goto cleanup;
-    }
+    if (end == NULL)
+        return BACKING_STORE_INVALID;
+
     if (end == start) {
         *format = VIR_STORAGE_FILE_NONE;
-        ret = BACKING_STORE_OK;
-        goto cleanup;
+        return BACKING_STORE_OK;
     }
     *end = '\0';
     *res = g_strdup(start);
 
-    ret = BACKING_STORE_OK;
-
- cleanup:
-    return ret;
+    return BACKING_STORE_OK;
 }
 
 static int
@@ -2391,20 +2383,15 @@ virStorageSourceInitChainElement(virStorageSourcePtr newelem,
                                  virStorageSourcePtr old,
                                  bool transferLabels)
 {
-    int ret = -1;
-
     if (transferLabels &&
         !newelem->seclabels &&
         virStorageSourceSeclabelsCopy(newelem, old) < 0)
-        goto cleanup;
+        return -1;
 
     newelem->shared = old->shared;
     newelem->readonly = old->readonly;
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -3440,7 +3427,6 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
     virJSONValuePtr servers = virJSONValueObjectGetArray(json, "server");
     size_t nservers;
     size_t i;
-    int ret = -1;
 
     src->type = VIR_STORAGE_TYPE_NETWORK;
     src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
@@ -3465,20 +3451,18 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
         nservers = virJSONValueArraySize(servers);
 
         if (VIR_ALLOC_N(src->hosts, nservers) < 0)
-            goto cleanup;
+            return -1;
 
         src->nhosts = nservers;
 
         for (i = 0; i < nservers; i++) {
             if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts + i,
                                                                   virJSONValueArrayGet(servers, i)) < 0)
-                goto cleanup;
+                return -1;
         }
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/src/util/virutil.c b/src/util/virutil.c
index f2528e257c..8862a6b800 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1331,7 +1331,7 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
                      unsigned long long capBits, bool clearExistingCaps)
 {
     size_t i;
-    int capng_ret, ret = -1;
+    int capng_ret;
     bool need_setgid = false;
     bool need_setuid = false;
     bool need_setpcap = false;
@@ -1383,7 +1383,7 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
     if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
         virReportSystemError(errno, "%s",
                              _("prctl failed to set KEEPCAPS"));
-        goto cleanup;
+        return -1;
     }
 
     /* Change to the temp capabilities */
@@ -1401,18 +1401,18 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("cannot apply process capabilities %d"), capng_ret);
-            goto cleanup;
+            return -1;
         }
     }
 
     if (virSetUIDGID(uid, gid, groups, ngroups) < 0)
-        goto cleanup;
+        return -1;
 
     /* Tell it we are done keeping capabilities */
     if (prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0)) {
         virReportSystemError(errno, "%s",
                              _("prctl failed to reset KEEPCAPS"));
-        goto cleanup;
+        return -1;
     }
 
 # ifdef PR_CAP_AMBIENT
@@ -1430,7 +1430,7 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
                                      _("prctl failed to enable '%s' in the "
                                        "AMBIENT set"),
                                      capstr);
-                goto cleanup;
+                return -1;
             }
         }
     }
@@ -1454,13 +1454,10 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
     if (((capng_ret = capng_apply(CAPNG_SELECT_CAPS)) < 0)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot apply process capabilities %d"), capng_ret);
-        ret = -1;
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 #else
-- 
2.21.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]

  Powered by Linux