Blob Blame History Raw
From e9b93240af4c391414b301c7a4a20837bc09b109 Mon Sep 17 00:00:00 2001
Message-Id: <e9b93240af4c391414b301c7a4a20837bc09b109@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Tue, 26 May 2020 10:59:15 +0200
Subject: [PATCH] cpu_x86: Use g_auto* in x86Decode
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 9bb9cbf6761ecf985fe9cf8a18030a8aff9b448b)

https://bugzilla.redhat.com/show_bug.cgi?id=1840010

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <1414d86a79eb63d5600cf494455411814cbf10f7.1590483392.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/cpu/cpu_x86.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index c111ff45d4..dba4165527 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2032,15 +2032,12 @@ x86Decode(virCPUDefPtr cpu,
           const char *preferred,
           bool migratable)
 {
-    int ret = -1;
     virCPUx86MapPtr map;
     virCPUx86ModelPtr candidate;
     virCPUDefPtr cpuCandidate;
     virCPUx86ModelPtr model = NULL;
-    virCPUDefPtr cpuModel = NULL;
-    virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
-    virCPUx86Data copy = VIR_CPU_X86_DATA_INIT;
-    virCPUx86Data features = VIR_CPU_X86_DATA_INIT;
+    g_autoptr(virCPUDef) cpuModel = NULL;
+    g_auto(virCPUx86Data) data = VIR_CPU_X86_DATA_INIT;
     virCPUx86VendorPtr vendor;
     virDomainCapsCPUModelPtr hvModel = NULL;
     g_autofree char *sigs = NULL;
@@ -2054,7 +2051,7 @@ x86Decode(virCPUDefPtr cpu,
     x86DataCopy(&data, cpuData);
 
     if (!(map = virCPUx86GetMap()))
-        goto cleanup;
+        return -1;
 
     vendor = x86DataToVendor(&data, map);
     signature = x86DataToSignature(&data);
@@ -2073,7 +2070,7 @@ x86Decode(virCPUDefPtr cpu,
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                    _("CPU model %s is not supported by hypervisor"),
                                    preferred);
-                    goto cleanup;
+                    return -1;
                 } else {
                     VIR_WARN("Preferred CPU model %s not allowed by"
                              " hypervisor; closest supported model will be"
@@ -2096,7 +2093,7 @@ x86Decode(virCPUDefPtr cpu,
         }
 
         if (!(cpuCandidate = x86DataToCPU(&data, candidate, map, hvModel)))
-            goto cleanup;
+            return -1;
         cpuCandidate->type = cpu->type;
 
         if ((rc = x86DecodeUseCandidate(model, cpuModel,
@@ -2115,7 +2112,7 @@ x86Decode(virCPUDefPtr cpu,
     if (!cpuModel) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("Cannot find suitable CPU model for given data"));
-        goto cleanup;
+        return -1;
     }
 
     /* Remove non-migratable features if requested
@@ -2149,14 +2146,7 @@ x86Decode(virCPUDefPtr cpu,
     cpu->nfeatures_max = cpuModel->nfeatures_max;
     cpuModel->nfeatures_max = 0;
 
-    ret = 0;
-
- cleanup:
-    virCPUDefFree(cpuModel);
-    virCPUx86DataClear(&data);
-    virCPUx86DataClear(&copy);
-    virCPUx86DataClear(&features);
-    return ret;
+    return 0;
 }
 
 static int
-- 
2.26.2