Re: [libvirt PATCH 22/39] cpu_x86: Use g_auto* in virCPUx86Baseline

2020-04-07 Thread Ján Tomko

On a Friday in 2020, Jiri Denemark wrote:

Signed-off-by: Jiri Denemark 
---
src/cpu/cpu_x86.c | 46 +-
1 file changed, 17 insertions(+), 29 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


[libvirt PATCH 22/39] cpu_x86: Use g_auto* in virCPUx86Baseline

2020-03-27 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/cpu/cpu_x86.c | 46 +-
 1 file changed, 17 insertions(+), 29 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 7bd19a1676..ccbae3dabd 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2701,21 +2701,20 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
   bool migratable)
 {
 virCPUx86MapPtr map = NULL;
-virCPUx86ModelPtr base_model = NULL;
-virCPUDefPtr cpu = NULL;
+g_autoptr(virCPUx86Model) base_model = NULL;
+g_autoptr(virCPUDef) cpu = NULL;
 size_t i;
 virCPUx86VendorPtr vendor = NULL;
-virCPUx86ModelPtr model = NULL;
 bool outputVendor = true;
 const char *modelName;
 bool matchingNames = true;
-virCPUDataPtr featData = NULL;
+g_autoptr(virCPUData) featData = NULL;
 
 if (!(map = virCPUx86GetMap()))
-goto error;
+return NULL;
 
 if (!(base_model = x86ModelFromCPU(cpus[0], map, -1)))
-goto error;
+return NULL;
 
 cpu = virCPUDefNew();
 
@@ -2727,11 +2726,12 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
 } else if (!(vendor = x86VendorFind(map, cpus[0]->vendor))) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("Unknown CPU vendor %s"), cpus[0]->vendor);
-goto error;
+return NULL;
 }
 
 modelName = cpus[0]->model;
 for (i = 1; i < ncpus; i++) {
+g_autoptr(virCPUx86Model) model = NULL;
 const char *vn = NULL;
 
 if (matchingNames && cpus[i]->model) {
@@ -2744,14 +2744,14 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
 }
 
 if (!(model = x86ModelFromCPU(cpus[i], map, -1)))
-goto error;
+return NULL;
 
 if (cpus[i]->vendor && model->vendor &&
 STRNEQ(cpus[i]->vendor, model->vendor->name)) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("CPU vendor %s of model %s differs from vendor 
%s"),
model->vendor->name, model->name, cpus[i]->vendor);
-goto error;
+return NULL;
 }
 
 if (cpus[i]->vendor) {
@@ -2767,30 +2767,28 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
 if (!(vendor = x86VendorFind(map, vn))) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("Unknown CPU vendor %s"), vn);
-goto error;
+return NULL;
 }
 } else if (STRNEQ(vendor->name, vn)) {
 virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("CPU vendors do not match"));
-goto error;
+return NULL;
 }
 }
 
 x86DataIntersect(_model->data, >data);
-x86ModelFree(model);
-model = NULL;
 }
 
 if (features) {
 virCPUx86FeaturePtr feat;
 
 if (!(featData = virCPUDataNew(archs[0])))
-goto cleanup;
+return NULL;
 
 for (i = 0; features[i]; i++) {
 if ((feat = x86FeatureFind(map, features[i])) &&
 x86DataAdd(>data.x86, >data) < 0)
-goto cleanup;
+return NULL;
 }
 
 x86DataIntersect(_model->data, >data.x86);
@@ -2799,15 +2797,15 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
 if (x86DataIsEmpty(_model->data)) {
 virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("CPUs are incompatible"));
-goto error;
+return NULL;
 }
 
 if (vendor &&
 virCPUx86DataAddItem(_model->data, >data) < 0)
-goto error;
+return NULL;
 
 if (x86Decode(cpu, _model->data, models, modelName, migratable) < 0)
-goto error;
+return NULL;
 
 if (STREQ_NULLABLE(cpu->model, modelName))
 cpu->fallback = VIR_CPU_FALLBACK_FORBID;
@@ -2815,17 +2813,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
 if (!outputVendor)
 VIR_FREE(cpu->vendor);
 
- cleanup:
-x86ModelFree(base_model);
-virCPUx86DataFree(featData);
-
-return cpu;
-
- error:
-x86ModelFree(model);
-virCPUDefFree(cpu);
-cpu = NULL;
-goto cleanup;
+return g_steal_pointer();
 }
 
 
-- 
2.26.0