libvirt/SOURCES/libvirt-cpu_x86-Use-g_auto-in-virCPUx86UpdateLive.patch
2021-10-08 13:11:20 +00:00

117 lines
3.9 KiB
Diff

From 7a293db132130fdda7b550d701fdb426de5257e3 Mon Sep 17 00:00:00 2001
Message-Id: <7a293db132130fdda7b550d701fdb426de5257e3@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Tue, 26 May 2020 10:59:23 +0200
Subject: [PATCH] cpu_x86: Use g_auto* in virCPUx86UpdateLive
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 2748e91c548cbc48a5ea499e06e62de528c10d20)
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <5c29b10ead2332033087fc6ed487c9ca53b7e3a4.1590483392.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/cpu/cpu_x86.c | 42 +++++++++++++++---------------------------
1 file changed, 15 insertions(+), 27 deletions(-)
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 1f7a8802f6..e3a83061d0 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2897,26 +2897,25 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
{
bool hostPassthrough = cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH;
virCPUx86MapPtr map;
- virCPUx86ModelPtr model = NULL;
- virCPUx86ModelPtr modelDisabled = NULL;
- virCPUx86Data enabled = VIR_CPU_X86_DATA_INIT;
- virCPUx86Data disabled = VIR_CPU_X86_DATA_INIT;
- virBuffer bufAdded = VIR_BUFFER_INITIALIZER;
- virBuffer bufRemoved = VIR_BUFFER_INITIALIZER;
- char *added = NULL;
- char *removed = NULL;
+ g_autoptr(virCPUx86Model) model = NULL;
+ g_autoptr(virCPUx86Model) modelDisabled = NULL;
+ g_auto(virCPUx86Data) enabled = VIR_CPU_X86_DATA_INIT;
+ g_auto(virCPUx86Data) disabled = VIR_CPU_X86_DATA_INIT;
+ g_auto(virBuffer) bufAdded = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) bufRemoved = VIR_BUFFER_INITIALIZER;
+ g_autofree char *added = NULL;
+ g_autofree char *removed = NULL;
size_t i;
- int ret = -1;
if (!(map = virCPUx86GetMap()))
return -1;
if (!(model = x86ModelFromCPU(cpu, map, -1)))
- goto cleanup;
+ return -1;
if (hostPassthrough &&
!(modelDisabled = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_DISABLE)))
- goto cleanup;
+ return -1;
if (dataEnabled)
x86DataCopy(&enabled, &dataEnabled->data.x86);
@@ -2941,7 +2940,7 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
virBufferAsprintf(&bufAdded, "%s,", feature->name);
else if (virCPUDefUpdateFeature(cpu, feature->name,
VIR_CPU_FEATURE_REQUIRE) < 0)
- goto cleanup;
+ return -1;
}
if (x86DataIsSubset(&disabled, &feature->data) ||
@@ -2952,7 +2951,7 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
virBufferAsprintf(&bufRemoved, "%s,", feature->name);
else if (virCPUDefUpdateFeature(cpu, feature->name,
VIR_CPU_FEATURE_DISABLE) < 0)
- goto cleanup;
+ return -1;
}
}
@@ -2978,28 +2977,17 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
_("guest CPU doesn't match specification: "
"missing features: %s"),
removed);
- goto cleanup;
+ return -1;
}
if (cpu->check == VIR_CPU_CHECK_FULL &&
!x86DataIsEmpty(&disabled)) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("guest CPU doesn't match specification"));
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- x86ModelFree(model);
- x86ModelFree(modelDisabled);
- virCPUx86DataClear(&enabled);
- virCPUx86DataClear(&disabled);
- VIR_FREE(added);
- VIR_FREE(removed);
- virBufferFreeAndReset(&bufAdded);
- virBufferFreeAndReset(&bufRemoved);
- return ret;
+ return 0;
}
--
2.26.2