a41c76
From 6fa7baf5345b053e8215b34f721316f6f72f1cf3 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <6fa7baf5345b053e8215b34f721316f6f72f1cf3@dist-git>
a41c76
From: Jiri Denemark <jdenemar@redhat.com>
a41c76
Date: Tue, 26 May 2020 10:59:00 +0200
a41c76
Subject: [PATCH] cpu_x86: Use glib allocation for virCPU{, x86}Data
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 800868583012e20fb60eb4be9fb1ccc018677006)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Message-Id: <dbb07df3c1ad3f47f21caa1b9555bd37db037694.1590483392.git.jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/cpu/cpu_x86.c | 45 ++++++++++++++++++++++-----------------------
a41c76
 1 file changed, 22 insertions(+), 23 deletions(-)
a41c76
a41c76
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
a41c76
index 1b388ec1b2..4d82d85746 100644
a41c76
--- a/src/cpu/cpu_x86.c
a41c76
+++ b/src/cpu/cpu_x86.c
a41c76
@@ -468,8 +468,9 @@ virCPUx86DataClear(virCPUx86Data *data)
a41c76
     if (!data)
a41c76
         return;
a41c76
 
a41c76
-    VIR_FREE(data->items);
a41c76
+    g_free(data->items);
a41c76
 }
a41c76
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virCPUx86Data, virCPUx86DataClear);
a41c76
 
a41c76
 
a41c76
 static void
a41c76
@@ -481,21 +482,19 @@ virCPUx86DataFree(virCPUDataPtr data)
a41c76
     virCPUx86DataClear(&data->data.x86);
a41c76
     VIR_FREE(data);
a41c76
 }
a41c76
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUData, virCPUx86DataFree);
a41c76
 
a41c76
 
a41c76
-static int
a41c76
+static void
a41c76
 x86DataCopy(virCPUx86Data *dst, const virCPUx86Data *src)
a41c76
 {
a41c76
     size_t i;
a41c76
 
a41c76
-    if (VIR_ALLOC_N(dst->items, src->len) < 0)
a41c76
-        return -1;
a41c76
-
a41c76
+    dst->items = g_new0(virCPUx86DataItem, src->len);
a41c76
     dst->len = src->len;
a41c76
+
a41c76
     for (i = 0; i < src->len; i++)
a41c76
         dst->items[i] = src->items[i];
a41c76
-
a41c76
-    return 0;
a41c76
 }
a41c76
 
a41c76
 
a41c76
@@ -781,9 +780,8 @@ x86DataToCPU(const virCPUx86Data *data,
a41c76
 
a41c76
     cpu->model = g_strdup(model->name);
a41c76
 
a41c76
-    if (x86DataCopy(&copy, data) < 0 ||
a41c76
-        x86DataCopy(&modelData, &model->data) < 0)
a41c76
-        goto error;
a41c76
+    x86DataCopy(&copy, data);
a41c76
+    x86DataCopy(&modelData, &model->data);
a41c76
 
a41c76
     if ((vendor = x86DataToVendor(&copy, map)))
a41c76
         cpu->vendor = g_strdup(vendor->name);
a41c76
@@ -1183,11 +1181,11 @@ x86ModelCopy(virCPUx86ModelPtr model)
a41c76
 
a41c76
     copy->name = g_strdup(model->name);
a41c76
 
a41c76
-    if (x86ModelCopySignatures(copy, model) < 0 ||
a41c76
-        x86DataCopy(&copy->data, &model->data) < 0) {
a41c76
+    if (x86ModelCopySignatures(copy, model) < 0) {
a41c76
         x86ModelFree(copy);
a41c76
         return NULL;
a41c76
     }
a41c76
+    x86DataCopy(&copy->data, &model->data);
a41c76
 
a41c76
     copy->vendor = model->vendor;
a41c76
 
a41c76
@@ -1415,10 +1413,11 @@ x86ModelParseAncestor(virCPUx86ModelPtr model,
a41c76
     }
a41c76
 
a41c76
     model->vendor = ancestor->vendor;
a41c76
-    if (x86ModelCopySignatures(model, ancestor) < 0 ||
a41c76
-        x86DataCopy(&model->data, &ancestor->data) < 0)
a41c76
+    if (x86ModelCopySignatures(model, ancestor) < 0)
a41c76
         return -1;
a41c76
 
a41c76
+    x86DataCopy(&model->data, &ancestor->data);
a41c76
+
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
@@ -1904,9 +1903,9 @@ x86Compute(virCPUDefPtr host,
a41c76
 
a41c76
         x86DataSubtract(&guest_model->data, &cpu_disable->data);
a41c76
 
a41c76
-        if (!(guestData = virCPUDataNew(arch)) ||
a41c76
-            x86DataCopy(&guestData->data.x86, &guest_model->data) < 0)
a41c76
+        if (!(guestData = virCPUDataNew(arch)))
a41c76
             goto error;
a41c76
+        x86DataCopy(&guestData->data.x86, &guest_model->data);
a41c76
 
a41c76
         *guest = guestData;
a41c76
     }
a41c76
@@ -2139,9 +2138,11 @@ x86Decode(virCPUDefPtr cpu,
a41c76
     ssize_t i;
a41c76
     int rc;
a41c76
 
a41c76
-    if (!cpuData || x86DataCopy(&data, cpuData) < 0)
a41c76
+    if (!cpuData)
a41c76
         return -1;
a41c76
 
a41c76
+    x86DataCopy(&data, cpuData);
a41c76
+
a41c76
     if (!(map = virCPUx86GetMap()))
a41c76
         goto cleanup;
a41c76
 
a41c76
@@ -3055,13 +3056,11 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
a41c76
         !(modelDisabled = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_DISABLE)))
a41c76
         goto cleanup;
a41c76
 
a41c76
-    if (dataEnabled &&
a41c76
-        x86DataCopy(&enabled, &dataEnabled->data.x86) < 0)
a41c76
-        goto cleanup;
a41c76
+    if (dataEnabled)
a41c76
+        x86DataCopy(&enabled, &dataEnabled->data.x86);
a41c76
 
a41c76
-    if (dataDisabled &&
a41c76
-        x86DataCopy(&disabled, &dataDisabled->data.x86) < 0)
a41c76
-        goto cleanup;
a41c76
+    if (dataDisabled)
a41c76
+        x86DataCopy(&disabled, &dataDisabled->data.x86);
a41c76
 
a41c76
     for (i = 0; i < map->nfeatures; i++) {
a41c76
         virCPUx86FeaturePtr feature = map->features[i];
a41c76
-- 
a41c76
2.26.2
a41c76