[libvirt PATCH 17/39] cpu_x86: Use g_auto* in x86Decode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/cpu/cpu_x86.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index e4e21fbed4..26d872622e 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2034,15 +2034,14 @@ 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;
+    g_auto(virCPUx86Data) copy = VIR_CPU_X86_DATA_INIT;
+    g_auto(virCPUx86Data) features = VIR_CPU_X86_DATA_INIT;
     virCPUx86VendorPtr vendor;
     virDomainCapsCPUModelPtr hvModel = NULL;
     g_autofree char *sigs = NULL;
@@ -2056,7 +2055,7 @@ x86Decode(virCPUDefPtr cpu,
     x86DataCopy(&data, cpuData);
 
     if (!(map = virCPUx86GetMap()))
-        goto cleanup;
+        return -1;
 
     vendor = x86DataToVendor(&data, map);
     signature = x86DataToSignature(&data);
@@ -2075,7 +2074,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"
@@ -2098,7 +2097,7 @@ x86Decode(virCPUDefPtr cpu,
         }
 
         if (!(cpuCandidate = x86DataToCPU(&data, candidate, map, hvModel)))
-            goto cleanup;
+            return -1;
         cpuCandidate->type = cpu->type;
 
         if ((rc = x86DecodeUseCandidate(model, cpuModel,
@@ -2117,7 +2116,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
@@ -2151,14 +2150,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.0





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux