fbe740
From b8162d4174443babbd260b36ea4645469eca7d67 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <b8162d4174443babbd260b36ea4645469eca7d67@dist-git>
fbe740
From: Jiri Denemark <jdenemar@redhat.com>
fbe740
Date: Tue, 26 May 2020 10:59:13 +0200
fbe740
Subject: [PATCH] cpu_x86: Use g_auto* in x86Compute
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit edf3c9045f1742d6c132066e4ba2da25c9ad7b26)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
fbe740
fbe740
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
fbe740
Message-Id: <6022f3717ce7ab0df25d31f2aaa08cac1c5f82de.1590483392.git.jdenemar@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/cpu/cpu_x86.c | 65 +++++++++++++++++------------------------------
fbe740
 1 file changed, 24 insertions(+), 41 deletions(-)
fbe740
fbe740
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
fbe740
index 107fd9227d..1a1c846383 100644
fbe740
--- a/src/cpu/cpu_x86.c
fbe740
+++ b/src/cpu/cpu_x86.c
fbe740
@@ -1680,7 +1680,6 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
fbe740
  * redundant code:
fbe740
  * MSG: error message
fbe740
  * CPU_DEF: a virCPUx86Data pointer with flags that are conflicting
fbe740
- * RET: return code to set
fbe740
  *
fbe740
  * This macro generates the error string outputs it into logs.
fbe740
  */
fbe740
@@ -1689,13 +1688,12 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
fbe740
             char *flagsStr = NULL; \
fbe740
             if (!(flagsStr = x86FeatureNames(map, ", ", (CPU_DEF)))) { \
fbe740
                 virReportOOMError(); \
fbe740
-                goto error; \
fbe740
+                return VIR_CPU_COMPARE_ERROR; \
fbe740
             } \
fbe740
             if (message) \
fbe740
                 *message = g_strdup_printf("%s: %s", _(MSG), flagsStr); \
fbe740
             VIR_DEBUG("%s: %s", MSG, flagsStr); \
fbe740
             VIR_FREE(flagsStr); \
fbe740
-            ret = VIR_CPU_COMPARE_INCOMPATIBLE; \
fbe740
         } while (0)
fbe740
 
fbe740
 
fbe740
@@ -1706,15 +1704,15 @@ x86Compute(virCPUDefPtr host,
fbe740
            char **message)
fbe740
 {
fbe740
     virCPUx86MapPtr map = NULL;
fbe740
-    virCPUx86ModelPtr host_model = NULL;
fbe740
-    virCPUx86ModelPtr cpu_force = NULL;
fbe740
-    virCPUx86ModelPtr cpu_require = NULL;
fbe740
-    virCPUx86ModelPtr cpu_optional = NULL;
fbe740
-    virCPUx86ModelPtr cpu_disable = NULL;
fbe740
-    virCPUx86ModelPtr cpu_forbid = NULL;
fbe740
-    virCPUx86ModelPtr diff = NULL;
fbe740
-    virCPUx86ModelPtr guest_model = NULL;
fbe740
-    virCPUDataPtr guestData = NULL;
fbe740
+    g_autoptr(virCPUx86Model) host_model = NULL;
fbe740
+    g_autoptr(virCPUx86Model) cpu_force = NULL;
fbe740
+    g_autoptr(virCPUx86Model) cpu_require = NULL;
fbe740
+    g_autoptr(virCPUx86Model) cpu_optional = NULL;
fbe740
+    g_autoptr(virCPUx86Model) cpu_disable = NULL;
fbe740
+    g_autoptr(virCPUx86Model) cpu_forbid = NULL;
fbe740
+    g_autoptr(virCPUx86Model) diff = NULL;
fbe740
+    g_autoptr(virCPUx86Model) guest_model = NULL;
fbe740
+    g_autoptr(virCPUData) guestData = NULL;
fbe740
     virCPUCompareResult ret;
fbe740
     virCPUx86CompareResult result;
fbe740
     virArch arch;
fbe740
@@ -1764,13 +1762,13 @@ x86Compute(virCPUDefPtr host,
fbe740
         !(cpu_optional = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_OPTIONAL)) ||
fbe740
         !(cpu_disable = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_DISABLE)) ||
fbe740
         !(cpu_forbid = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_FORBID)))
fbe740
-        goto error;
fbe740
+        return VIR_CPU_COMPARE_ERROR;
fbe740
 
fbe740
     x86DataIntersect(&cpu_forbid->data, &host_model->data);
fbe740
     if (!x86DataIsEmpty(&cpu_forbid->data)) {
fbe740
         virX86CpuIncompatible(N_("Host CPU provides forbidden features"),
fbe740
                               &cpu_forbid->data);
fbe740
-        goto cleanup;
fbe740
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
fbe740
     }
fbe740
 
fbe740
     /* first remove features that were inherited from the CPU model and were
fbe740
@@ -1785,20 +1783,20 @@ x86Compute(virCPUDefPtr host,
fbe740
         virX86CpuIncompatible(N_("Host CPU does not provide required "
fbe740
                                  "features"),
fbe740
                               &cpu_require->data);
fbe740
-        goto cleanup;
fbe740
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
fbe740
     }
fbe740
 
fbe740
-    ret = VIR_CPU_COMPARE_IDENTICAL;
fbe740
-
fbe740
     if (!(diff = x86ModelCopy(host_model)))
fbe740
-        goto error;
fbe740
+        return VIR_CPU_COMPARE_ERROR;
fbe740
 
fbe740
     x86DataSubtract(&diff->data, &cpu_optional->data);
fbe740
     x86DataSubtract(&diff->data, &cpu_require->data);
fbe740
     x86DataSubtract(&diff->data, &cpu_disable->data);
fbe740
     x86DataSubtract(&diff->data, &cpu_force->data);
fbe740
 
fbe740
-    if (!x86DataIsEmpty(&diff->data))
fbe740
+    if (x86DataIsEmpty(&diff->data))
fbe740
+        ret = VIR_CPU_COMPARE_IDENTICAL;
fbe740
+    else
fbe740
         ret = VIR_CPU_COMPARE_SUPERSET;
fbe740
 
fbe740
     if (ret == VIR_CPU_COMPARE_SUPERSET
fbe740
@@ -1807,54 +1805,39 @@ x86Compute(virCPUDefPtr host,
fbe740
         virX86CpuIncompatible(N_("Host CPU does not strictly match guest CPU: "
fbe740
                                  "Extra features"),
fbe740
                               &diff->data);
fbe740
-        goto cleanup;
fbe740
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
fbe740
     }
fbe740
 
fbe740
     if (guest) {
fbe740
         if (!(guest_model = x86ModelCopy(host_model)))
fbe740
-            goto error;
fbe740
+            return VIR_CPU_COMPARE_ERROR;
fbe740
 
fbe740
         if (cpu->vendor && host_model->vendor &&
fbe740
             virCPUx86DataAddItem(&guest_model->data,
fbe740
                                  &host_model->vendor->data) < 0)
fbe740
-            goto error;
fbe740
+            return VIR_CPU_COMPARE_ERROR;
fbe740
 
fbe740
         if (host_model->signatures &&
fbe740
             x86DataAddSignature(&guest_model->data, *host_model->signatures) < 0)
fbe740
-            goto error;
fbe740
+            return VIR_CPU_COMPARE_ERROR;
fbe740
 
fbe740
         if (cpu->type == VIR_CPU_TYPE_GUEST
fbe740
             && cpu->match == VIR_CPU_MATCH_EXACT)
fbe740
             x86DataSubtract(&guest_model->data, &diff->data);
fbe740
 
fbe740
         if (x86DataAdd(&guest_model->data, &cpu_force->data))
fbe740
-            goto error;
fbe740
+            return VIR_CPU_COMPARE_ERROR;
fbe740
 
fbe740
         x86DataSubtract(&guest_model->data, &cpu_disable->data);
fbe740
 
fbe740
         if (!(guestData = virCPUDataNew(arch)))
fbe740
-            goto error;
fbe740
+            return VIR_CPU_COMPARE_ERROR;
fbe740
         x86DataCopy(&guestData->data.x86, &guest_model->data);
fbe740
 
fbe740
-        *guest = guestData;
fbe740
+        *guest = g_steal_pointer(&guestData);
fbe740
     }
fbe740
 
fbe740
- cleanup:
fbe740
-    x86ModelFree(host_model);
fbe740
-    x86ModelFree(diff);
fbe740
-    x86ModelFree(cpu_force);
fbe740
-    x86ModelFree(cpu_require);
fbe740
-    x86ModelFree(cpu_optional);
fbe740
-    x86ModelFree(cpu_disable);
fbe740
-    x86ModelFree(cpu_forbid);
fbe740
-    x86ModelFree(guest_model);
fbe740
-
fbe740
     return ret;
fbe740
-
fbe740
- error:
fbe740
-    virCPUx86DataFree(guestData);
fbe740
-    ret = VIR_CPU_COMPARE_ERROR;
fbe740
-    goto cleanup;
fbe740
 }
fbe740
 #undef virX86CpuIncompatible
fbe740
 
fbe740
-- 
fbe740
2.26.2
fbe740