]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu_ppc64.c: use g_autofree() whenever possible
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Wed, 2 Sep 2020 20:25:45 +0000 (17:25 -0300)
committerJán Tomko <jtomko@redhat.com>
Tue, 8 Sep 2020 16:13:15 +0000 (18:13 +0200)
This allows for a label removal in ppc64ModelParse().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/cpu/cpu_ppc64.c

index bc9d3999398d2322009b732fbf0061eeb393a18b..0c140b33e410acb58310995f479202da84007b90 100644 (file)
@@ -308,22 +308,21 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
 {
     virCPUppc64MapPtr map = data;
     g_autoptr(virCPUppc64Model) model = NULL;
-    xmlNodePtr *nodes = NULL;
-    char *vendor = NULL;
+    g_autofree xmlNodePtr *nodes = NULL;
+    g_autofree char *vendor = NULL;
     unsigned long pvr;
     size_t i;
     int n;
-    int ret = -1;
 
     if (VIR_ALLOC(model) < 0)
-        goto cleanup;
+        return -1;
 
     model->name = g_strdup(name);
 
     if (ppc64ModelFind(map, model->name)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("CPU model %s already defined"), model->name);
-        goto cleanup;
+        return -1;
     }
 
     if (virXPathBoolean("boolean(./vendor)", ctxt)) {
@@ -332,14 +331,14 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid vendor element in CPU model %s"),
                            model->name);
-            goto cleanup;
+            return -1;
         }
 
         if (!(model->vendor = ppc64VendorFind(map, vendor))) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unknown vendor %s referenced by CPU model %s"),
                            vendor, model->name);
-            goto cleanup;
+            return -1;
         }
     }
 
@@ -347,11 +346,11 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Missing PVR information for CPU model %s"),
                        model->name);
-        goto cleanup;
+        return -1;
     }
 
     if (VIR_ALLOC_N(model->data.pvr, n) < 0)
-        goto cleanup;
+        return -1;
 
     model->data.len = n;
 
@@ -362,7 +361,7 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Missing or invalid PVR value in CPU model %s"),
                            model->name);
-            goto cleanup;
+            return -1;
         }
         model->data.pvr[i].value = pvr;
 
@@ -370,20 +369,15 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Missing or invalid PVR mask in CPU model %s"),
                            model->name);
-            goto cleanup;
+            return -1;
         }
         model->data.pvr[i].mask = pvr;
     }
 
     if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    VIR_FREE(vendor);
-    VIR_FREE(nodes);
-    return ret;
+    return 0;
 }
 
 
@@ -547,7 +541,7 @@ virCPUppc64Compare(virCPUDefPtr host,
                    bool failIncompatible)
 {
     virCPUCompareResult ret;
-    char *message = NULL;
+    g_autofree char *message = NULL;
 
     if (!host || !host->model) {
         if (failIncompatible) {
@@ -570,7 +564,6 @@ virCPUppc64Compare(virCPUDefPtr host,
             virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);
         }
     }
-    VIR_FREE(message);
 
     return ret;
 }