a41c76
From 7a293db132130fdda7b550d701fdb426de5257e3 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <7a293db132130fdda7b550d701fdb426de5257e3@dist-git>
a41c76
From: Jiri Denemark <jdenemar@redhat.com>
a41c76
Date: Tue, 26 May 2020 10:59:23 +0200
a41c76
Subject: [PATCH] cpu_x86: Use g_auto* in virCPUx86UpdateLive
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 2748e91c548cbc48a5ea499e06e62de528c10d20)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Message-Id: <5c29b10ead2332033087fc6ed487c9ca53b7e3a4.1590483392.git.jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/cpu/cpu_x86.c | 42 +++++++++++++++---------------------------
a41c76
 1 file changed, 15 insertions(+), 27 deletions(-)
a41c76
a41c76
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
a41c76
index 1f7a8802f6..e3a83061d0 100644
a41c76
--- a/src/cpu/cpu_x86.c
a41c76
+++ b/src/cpu/cpu_x86.c
a41c76
@@ -2897,26 +2897,25 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
a41c76
 {
a41c76
     bool hostPassthrough = cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH;
a41c76
     virCPUx86MapPtr map;
a41c76
-    virCPUx86ModelPtr model = NULL;
a41c76
-    virCPUx86ModelPtr modelDisabled = NULL;
a41c76
-    virCPUx86Data enabled = VIR_CPU_X86_DATA_INIT;
a41c76
-    virCPUx86Data disabled = VIR_CPU_X86_DATA_INIT;
a41c76
-    virBuffer bufAdded = VIR_BUFFER_INITIALIZER;
a41c76
-    virBuffer bufRemoved = VIR_BUFFER_INITIALIZER;
a41c76
-    char *added = NULL;
a41c76
-    char *removed = NULL;
a41c76
+    g_autoptr(virCPUx86Model) model = NULL;
a41c76
+    g_autoptr(virCPUx86Model) modelDisabled = NULL;
a41c76
+    g_auto(virCPUx86Data) enabled = VIR_CPU_X86_DATA_INIT;
a41c76
+    g_auto(virCPUx86Data) disabled = VIR_CPU_X86_DATA_INIT;
a41c76
+    g_auto(virBuffer) bufAdded = VIR_BUFFER_INITIALIZER;
a41c76
+    g_auto(virBuffer) bufRemoved = VIR_BUFFER_INITIALIZER;
a41c76
+    g_autofree char *added = NULL;
a41c76
+    g_autofree char *removed = NULL;
a41c76
     size_t i;
a41c76
-    int ret = -1;
a41c76
 
a41c76
     if (!(map = virCPUx86GetMap()))
a41c76
         return -1;
a41c76
 
a41c76
     if (!(model = x86ModelFromCPU(cpu, map, -1)))
a41c76
-        goto cleanup;
a41c76
+        return -1;
a41c76
 
a41c76
     if (hostPassthrough &&
a41c76
         !(modelDisabled = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_DISABLE)))
a41c76
-        goto cleanup;
a41c76
+        return -1;
a41c76
 
a41c76
     if (dataEnabled)
a41c76
         x86DataCopy(&enabled, &dataEnabled->data.x86);
a41c76
@@ -2941,7 +2940,7 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
a41c76
                 virBufferAsprintf(&bufAdded, "%s,", feature->name);
a41c76
             else if (virCPUDefUpdateFeature(cpu, feature->name,
a41c76
                                             VIR_CPU_FEATURE_REQUIRE) < 0)
a41c76
-                goto cleanup;
a41c76
+                return -1;
a41c76
         }
a41c76
 
a41c76
         if (x86DataIsSubset(&disabled, &feature->data) ||
a41c76
@@ -2952,7 +2951,7 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
a41c76
                 virBufferAsprintf(&bufRemoved, "%s,", feature->name);
a41c76
             else if (virCPUDefUpdateFeature(cpu, feature->name,
a41c76
                                             VIR_CPU_FEATURE_DISABLE) < 0)
a41c76
-                goto cleanup;
a41c76
+                return -1;
a41c76
         }
a41c76
     }
a41c76
 
a41c76
@@ -2978,28 +2977,17 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
a41c76
                            _("guest CPU doesn't match specification: "
a41c76
                              "missing features: %s"),
a41c76
                            removed);
a41c76
-        goto cleanup;
a41c76
+        return -1;
a41c76
     }
a41c76
 
a41c76
     if (cpu->check == VIR_CPU_CHECK_FULL &&
a41c76
         !x86DataIsEmpty(&disabled)) {
a41c76
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
a41c76
                        _("guest CPU doesn't match specification"));
a41c76
-        goto cleanup;
a41c76
+        return -1;
a41c76
     }
a41c76
 
a41c76
-    ret = 0;
a41c76
-
a41c76
- cleanup:
a41c76
-    x86ModelFree(model);
a41c76
-    x86ModelFree(modelDisabled);
a41c76
-    virCPUx86DataClear(&enabled);
a41c76
-    virCPUx86DataClear(&disabled);
a41c76
-    VIR_FREE(added);
a41c76
-    VIR_FREE(removed);
a41c76
-    virBufferFreeAndReset(&bufAdded);
a41c76
-    virBufferFreeAndReset(&bufRemoved);
a41c76
-    return ret;
a41c76
+    return 0;
a41c76
 }
a41c76
 
a41c76
 
a41c76
-- 
a41c76
2.26.2
a41c76