From 8d2f5155be8834db501930716e2cd2e1be14785c Mon Sep 17 00:00:00 2001 Message-Id: <8d2f5155be8834db501930716e2cd2e1be14785c@dist-git> From: Jiri Denemark Date: Fri, 21 Jun 2019 09:24:57 +0200 Subject: [PATCH] cpu_x86: Separate feature list parsing from x86ModelParse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code is separated into a new x86ModelParseFeatures function. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko (cherry picked from commit 8d249df9c917040d180202343e5cf7f70c3e4fe1) https://bugzilla.redhat.com/show_bug.cgi?id=1686895 Signed-off-by: Jiri Denemark Message-Id: <5a741350b39394a93aee99a3b98142548936bc2d.1561068591.git.jdenemar@redhat.com> Reviewed-by: Ján Tomko --- src/cpu/cpu_x86.c | 68 +++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 62894cae9b..91362198ab 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1247,16 +1247,51 @@ x86ModelParseVendor(virCPUx86ModelPtr model, } +static int +x86ModelParseFeatures(virCPUx86ModelPtr model, + xmlXPathContextPtr ctxt, + virCPUx86MapPtr map) +{ + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; + size_t i; + int n; + + if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) <= 0) + return n; + + for (i = 0; i < n; i++) { + VIR_AUTOFREE(char *) ftname = NULL; + virCPUx86FeaturePtr feature; + + if (!(ftname = virXMLPropString(nodes[i], "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing feature name for CPU model %s"), + model->name); + return -1; + } + + if (!(feature = x86FeatureFind(map, ftname))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Feature %s required by CPU model %s not found"), + ftname, model->name); + return -1; + } + + if (x86DataAdd(&model->data, &feature->data)) + return -1; + } + + return 0; +} + + static int x86ModelParse(xmlXPathContextPtr ctxt, const char *name, void *data) { virCPUx86MapPtr map = data; - xmlNodePtr *nodes = NULL; virCPUx86ModelPtr model; - size_t i; - int n; int ret = -1; if (!(model = x86ModelNew())) @@ -1274,33 +1309,9 @@ x86ModelParse(xmlXPathContextPtr ctxt, if (x86ModelParseVendor(model, ctxt, map) < 0) goto cleanup; - n = virXPathNodeSet("./feature", ctxt, &nodes); - if (n < 0) + if (x86ModelParseFeatures(model, ctxt, map) < 0) goto cleanup; - for (i = 0; i < n; i++) { - virCPUx86FeaturePtr feature; - char *ftname; - - if (!(ftname = virXMLPropString(nodes[i], "name"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing feature name for CPU model %s"), model->name); - goto cleanup; - } - - if (!(feature = x86FeatureFind(map, ftname))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Feature %s required by CPU model %s not found"), - ftname, model->name); - VIR_FREE(ftname); - goto cleanup; - } - VIR_FREE(ftname); - - if (x86DataAdd(&model->data, &feature->data)) - goto cleanup; - } - if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0) goto cleanup; @@ -1308,7 +1319,6 @@ x86ModelParse(xmlXPathContextPtr ctxt, cleanup: x86ModelFree(model); - VIR_FREE(nodes); return ret; } -- 2.22.0