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