cpu_x86: Use g_auto* in x86Decode

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2020-03-25 10:29:54 +01:00
parent bc62d7a491
commit 9bb9cbf676

View File

@ -2032,15 +2032,12 @@ x86Decode(virCPUDefPtr cpu,
const char *preferred, const char *preferred,
bool migratable) bool migratable)
{ {
int ret = -1;
virCPUx86MapPtr map; virCPUx86MapPtr map;
virCPUx86ModelPtr candidate; virCPUx86ModelPtr candidate;
virCPUDefPtr cpuCandidate; virCPUDefPtr cpuCandidate;
virCPUx86ModelPtr model = NULL; virCPUx86ModelPtr model = NULL;
virCPUDefPtr cpuModel = NULL; g_autoptr(virCPUDef) cpuModel = NULL;
virCPUx86Data data = VIR_CPU_X86_DATA_INIT; g_auto(virCPUx86Data) data = VIR_CPU_X86_DATA_INIT;
virCPUx86Data copy = VIR_CPU_X86_DATA_INIT;
virCPUx86Data features = VIR_CPU_X86_DATA_INIT;
virCPUx86VendorPtr vendor; virCPUx86VendorPtr vendor;
virDomainCapsCPUModelPtr hvModel = NULL; virDomainCapsCPUModelPtr hvModel = NULL;
g_autofree char *sigs = NULL; g_autofree char *sigs = NULL;
@ -2054,7 +2051,7 @@ x86Decode(virCPUDefPtr cpu,
x86DataCopy(&data, cpuData); x86DataCopy(&data, cpuData);
if (!(map = virCPUx86GetMap())) if (!(map = virCPUx86GetMap()))
goto cleanup; return -1;
vendor = x86DataToVendor(&data, map); vendor = x86DataToVendor(&data, map);
signature = x86DataToSignature(&data); signature = x86DataToSignature(&data);
@ -2073,7 +2070,7 @@ x86Decode(virCPUDefPtr cpu,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("CPU model %s is not supported by hypervisor"), _("CPU model %s is not supported by hypervisor"),
preferred); preferred);
goto cleanup; return -1;
} else { } else {
VIR_WARN("Preferred CPU model %s not allowed by" VIR_WARN("Preferred CPU model %s not allowed by"
" hypervisor; closest supported model will be" " hypervisor; closest supported model will be"
@ -2096,7 +2093,7 @@ x86Decode(virCPUDefPtr cpu,
} }
if (!(cpuCandidate = x86DataToCPU(&data, candidate, map, hvModel))) if (!(cpuCandidate = x86DataToCPU(&data, candidate, map, hvModel)))
goto cleanup; return -1;
cpuCandidate->type = cpu->type; cpuCandidate->type = cpu->type;
if ((rc = x86DecodeUseCandidate(model, cpuModel, if ((rc = x86DecodeUseCandidate(model, cpuModel,
@ -2115,7 +2112,7 @@ x86Decode(virCPUDefPtr cpu,
if (!cpuModel) { if (!cpuModel) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Cannot find suitable CPU model for given data")); "%s", _("Cannot find suitable CPU model for given data"));
goto cleanup; return -1;
} }
/* Remove non-migratable features if requested /* Remove non-migratable features if requested
@ -2149,14 +2146,7 @@ x86Decode(virCPUDefPtr cpu,
cpu->nfeatures_max = cpuModel->nfeatures_max; cpu->nfeatures_max = cpuModel->nfeatures_max;
cpuModel->nfeatures_max = 0; cpuModel->nfeatures_max = 0;
ret = 0; return 0;
cleanup:
virCPUDefFree(cpuModel);
virCPUx86DataClear(&data);
virCPUx86DataClear(&copy);
virCPUx86DataClear(&features);
return ret;
} }
static int static int