render / rpms / libvirt

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