render / rpms / libvirt

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