]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virHostCPUGetInfoPopulateLinux: Remove 'cleanup'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 7 Apr 2025 11:55:43 +0000 (13:55 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Apr 2025 16:03:29 +0000 (18:03 +0200)
As the cleanup section is empty; the code can now return directly on
errors.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virhostcpu.c

index d86a12a39071e2e09da3bcb74f893135ef32b6ac..5fd74a7152d72f392e7e45e87d41004c47f81bc1 100644 (file)
@@ -643,7 +643,6 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
     int nodecpus, nodecores, nodesockets, nodethreads, offline = 0;
     int threads_per_subcore = 0;
     unsigned int node;
-    int ret = -1;
     g_autofree char *sysfs_nodedir = NULL;
     g_autofree char *sysfs_cpudir_fallback = NULL;
     int direrr;
@@ -659,12 +658,11 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
 
     /* Get information about what CPUs are present in the host and what
      * CPUs are online, so that we don't have to so for each node */
-    present_cpus_map = virHostCPUGetPresentBitmap();
-    if (!present_cpus_map)
-        goto cleanup;
-    online_cpus_map = virHostCPUGetOnlineBitmap();
-    if (!online_cpus_map)
-        goto cleanup;
+    if (!(present_cpus_map = virHostCPUGetPresentBitmap()))
+        return -1;
+
+    if (!(online_cpus_map = virHostCPUGetOnlineBitmap()))
+        return -1;
 
     /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
      * core, node, socket, thread and topology information from /sys
@@ -699,7 +697,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
      * On hosts other than POWER this will be 0, in which case a simpler
      * thread-counting logic will be used  */
     if ((threads_per_subcore = virHostCPUGetThreadsPerSubcore(arch)) < 0)
-        goto cleanup;
+        return -1;
 
     /* If the subcore configuration is not valid, just pretend subcores
      * are not in use and count threads one by one */
@@ -723,7 +721,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
                                             threads_per_subcore,
                                             &nodesockets, &nodecores,
                                             &nodethreads, &offline)) < 0)
-            goto cleanup;
+            return -1;
 
         *cpus += nodecpus;
 
@@ -738,7 +736,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
     }
 
     if (direrr < 0)
-        goto cleanup;
+        return -1;
 
     if (*cpus && *nodes)
         goto done;
@@ -752,7 +750,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
                                         threads_per_subcore,
                                         &nodesockets, &nodecores,
                                         &nodethreads, &offline)) < 0)
-        goto cleanup;
+        return -1;
 
     *nodes = 1;
     *cpus = nodecpus;
@@ -764,17 +762,17 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
     /* There should always be at least one cpu, socket, node, and thread. */
     if (*cpus == 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no CPUs found"));
-        goto cleanup;
+        return -1;
     }
 
     if (*sockets == 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no sockets found"));
-        goto cleanup;
+        return -1;
     }
 
     if (*threads == 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no threads found"));
-        goto cleanup;
+        return -1;
     }
 
     /* Now check if the topology makes sense. There are machines that don't
@@ -794,10 +792,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
         *threads = 1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 # define TICK_TO_NSEC (1000ull * 1000ull * 1000ull / sysconf(_SC_CLK_TCK))