render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
b971b8
From 39dea7f80de53e9f7fb8f298d1f9f7f32f20fc29 Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <39dea7f80de53e9f7fb8f298d1f9f7f32f20fc29@dist-git>
b971b8
From: Jiri Denemark <jdenemar@redhat.com>
b971b8
Date: Tue, 26 May 2020 10:59:08 +0200
b971b8
Subject: [PATCH] cpu_x86: Use g_auto* in x86FeatureParse
b971b8
MIME-Version: 1.0
b971b8
Content-Type: text/plain; charset=UTF-8
b971b8
Content-Transfer-Encoding: 8bit
b971b8
b971b8
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
b971b8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
b971b8
(cherry picked from commit 3125688f78f6289e51bfdaa196addb230b0de4e1)
b971b8
b971b8
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
b971b8
b971b8
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
b971b8
Message-Id: <14cf6ca6816ee8bda3e195aa5218162b280715b5.1590483392.git.jdenemar@redhat.com>
b971b8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
b971b8
---
b971b8
 src/cpu/cpu_x86.c | 31 ++++++++++++-------------------
b971b8
 1 file changed, 12 insertions(+), 19 deletions(-)
b971b8
b971b8
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
b971b8
index 3ffddf0342..10c5fbacf7 100644
b971b8
--- a/src/cpu/cpu_x86.c
b971b8
+++ b/src/cpu/cpu_x86.c
b971b8
@@ -1023,13 +1023,12 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
b971b8
                 void *data)
b971b8
 {
b971b8
     virCPUx86MapPtr map = data;
b971b8
-    xmlNodePtr *nodes = NULL;
b971b8
-    virCPUx86FeaturePtr feature;
b971b8
+    g_autofree xmlNodePtr *nodes = NULL;
b971b8
+    g_autoptr(virCPUx86Feature) feature = NULL;
b971b8
     virCPUx86DataItem item;
b971b8
     size_t i;
b971b8
     int n;
b971b8
-    char *str = NULL;
b971b8
-    int ret = -1;
b971b8
+    g_autofree char *str = NULL;
b971b8
 
b971b8
     feature = g_new0(virCPUx86Feature, 1);
b971b8
     feature->migratable = true;
b971b8
@@ -1038,7 +1037,7 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
b971b8
     if (x86FeatureFind(map, feature->name)) {
b971b8
         virReportError(VIR_ERR_INTERNAL_ERROR,
b971b8
                        _("CPU feature %s already defined"), feature->name);
b971b8
-        goto cleanup;
b971b8
+        return -1;
b971b8
     }
b971b8
 
b971b8
     str = virXPathString("string(@migratable)", ctxt);
b971b8
@@ -1047,13 +1046,13 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
b971b8
 
b971b8
     n = virXPathNodeSet("./cpuid|./msr", ctxt, &nodes);
b971b8
     if (n < 0)
b971b8
-        goto cleanup;
b971b8
+        return -1;
b971b8
 
b971b8
     if (n == 0) {
b971b8
         virReportError(VIR_ERR_INTERNAL_ERROR,
b971b8
                        _("Missing cpuid or msr element in feature %s"),
b971b8
                        feature->name);
b971b8
-        goto cleanup;
b971b8
+        return -1;
b971b8
     }
b971b8
 
b971b8
     for (i = 0; i < n; i++) {
b971b8
@@ -1063,37 +1062,31 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
b971b8
                 virReportError(VIR_ERR_INTERNAL_ERROR,
b971b8
                                _("Invalid cpuid[%zu] in %s feature"),
b971b8
                                i, feature->name);
b971b8
-                goto cleanup;
b971b8
+                return -1;
b971b8
             }
b971b8
         } else {
b971b8
             if (x86ParseMSR(ctxt, &item) < 0) {
b971b8
                 virReportError(VIR_ERR_INTERNAL_ERROR,
b971b8
                                _("Invalid msr[%zu] in %s feature"),
b971b8
                                i, feature->name);
b971b8
-                goto cleanup;
b971b8
+                return -1;
b971b8
             }
b971b8
         }
b971b8
 
b971b8
         if (virCPUx86DataAddItem(&feature->data, &item))
b971b8
-            goto cleanup;
b971b8
+            return -1;
b971b8
     }
b971b8
 
b971b8
     if (!feature->migratable &&
b971b8
         VIR_APPEND_ELEMENT_COPY(map->migrate_blockers,
b971b8
                                 map->nblockers,
b971b8
                                 feature) < 0)
b971b8
-        goto cleanup;
b971b8
+        return -1;
b971b8
 
b971b8
     if (VIR_APPEND_ELEMENT(map->features, map->nfeatures, feature) < 0)
b971b8
-        goto cleanup;
b971b8
-
b971b8
-    ret = 0;
b971b8
+        return -1;
b971b8
 
b971b8
- cleanup:
b971b8
-    x86FeatureFree(feature);
b971b8
-    VIR_FREE(nodes);
b971b8
-    VIR_FREE(str);
b971b8
-    return ret;
b971b8
+    return 0;
b971b8
 }
b971b8
 
b971b8
 
b971b8
-- 
b971b8
2.26.2
b971b8