b971b8
From e9b93240af4c391414b301c7a4a20837bc09b109 Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <e9b93240af4c391414b301c7a4a20837bc09b109@dist-git>
b971b8
From: Jiri Denemark <jdenemar@redhat.com>
b971b8
Date: Tue, 26 May 2020 10:59:15 +0200
b971b8
Subject: [PATCH] cpu_x86: Use g_auto* in x86Decode
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 9bb9cbf6761ecf985fe9cf8a18030a8aff9b448b)
b971b8
b971b8
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
b971b8
b971b8
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
b971b8
Message-Id: <1414d86a79eb63d5600cf494455411814cbf10f7.1590483392.git.jdenemar@redhat.com>
b971b8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
b971b8
---
b971b8
 src/cpu/cpu_x86.c | 24 +++++++-----------------
b971b8
 1 file changed, 7 insertions(+), 17 deletions(-)
b971b8
b971b8
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
b971b8
index c111ff45d4..dba4165527 100644
b971b8
--- a/src/cpu/cpu_x86.c
b971b8
+++ b/src/cpu/cpu_x86.c
b971b8
@@ -2032,15 +2032,12 @@ x86Decode(virCPUDefPtr cpu,
b971b8
           const char *preferred,
b971b8
           bool migratable)
b971b8
 {
b971b8
-    int ret = -1;
b971b8
     virCPUx86MapPtr map;
b971b8
     virCPUx86ModelPtr candidate;
b971b8
     virCPUDefPtr cpuCandidate;
b971b8
     virCPUx86ModelPtr model = NULL;
b971b8
-    virCPUDefPtr cpuModel = NULL;
b971b8
-    virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
b971b8
-    virCPUx86Data copy = VIR_CPU_X86_DATA_INIT;
b971b8
-    virCPUx86Data features = VIR_CPU_X86_DATA_INIT;
b971b8
+    g_autoptr(virCPUDef) cpuModel = NULL;
b971b8
+    g_auto(virCPUx86Data) data = VIR_CPU_X86_DATA_INIT;
b971b8
     virCPUx86VendorPtr vendor;
b971b8
     virDomainCapsCPUModelPtr hvModel = NULL;
b971b8
     g_autofree char *sigs = NULL;
b971b8
@@ -2054,7 +2051,7 @@ x86Decode(virCPUDefPtr cpu,
b971b8
     x86DataCopy(&data, cpuData);
b971b8
 
b971b8
     if (!(map = virCPUx86GetMap()))
b971b8
-        goto cleanup;
b971b8
+        return -1;
b971b8
 
b971b8
     vendor = x86DataToVendor(&data, map);
b971b8
     signature = x86DataToSignature(&data);
b971b8
@@ -2073,7 +2070,7 @@ x86Decode(virCPUDefPtr cpu,
b971b8
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
b971b8
                                    _("CPU model %s is not supported by hypervisor"),
b971b8
                                    preferred);
b971b8
-                    goto cleanup;
b971b8
+                    return -1;
b971b8
                 } else {
b971b8
                     VIR_WARN("Preferred CPU model %s not allowed by"
b971b8
                              " hypervisor; closest supported model will be"
b971b8
@@ -2096,7 +2093,7 @@ x86Decode(virCPUDefPtr cpu,
b971b8
         }
b971b8
 
b971b8
         if (!(cpuCandidate = x86DataToCPU(&data, candidate, map, hvModel)))
b971b8
-            goto cleanup;
b971b8
+            return -1;
b971b8
         cpuCandidate->type = cpu->type;
b971b8
 
b971b8
         if ((rc = x86DecodeUseCandidate(model, cpuModel,
b971b8
@@ -2115,7 +2112,7 @@ x86Decode(virCPUDefPtr cpu,
b971b8
     if (!cpuModel) {
b971b8
         virReportError(VIR_ERR_INTERNAL_ERROR,
b971b8
                        "%s", _("Cannot find suitable CPU model for given data"));
b971b8
-        goto cleanup;
b971b8
+        return -1;
b971b8
     }
b971b8
 
b971b8
     /* Remove non-migratable features if requested
b971b8
@@ -2149,14 +2146,7 @@ x86Decode(virCPUDefPtr cpu,
b971b8
     cpu->nfeatures_max = cpuModel->nfeatures_max;
b971b8
     cpuModel->nfeatures_max = 0;
b971b8
 
b971b8
-    ret = 0;
b971b8
-
b971b8
- cleanup:
b971b8
-    virCPUDefFree(cpuModel);
b971b8
-    virCPUx86DataClear(&data);
b971b8
-    virCPUx86DataClear(©);
b971b8
-    virCPUx86DataClear(&features);
b971b8
-    return ret;
b971b8
+    return 0;
b971b8
 }
b971b8
 
b971b8
 static int
b971b8
-- 
b971b8
2.26.2
b971b8