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

[PATCH 11/12] cpu_ppc64.c: use g_autofree() whenever possible



This allows for a label removal in ppc64ModelParse().

Signed-off-by: Daniel Henrique Barboza <danielhb413 gmail com>
---
 src/cpu/cpu_ppc64.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index bc9d399939..0c140b33e4 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -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;
 }
-- 
2.26.2


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