Blob Blame History Raw
From e1b42297bc41c8f356693f2756e806a8c7275f4f Mon Sep 17 00:00:00 2001
Message-Id: <e1b42297bc41c8f356693f2756e806a8c7275f4f@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 21 Jun 2019 09:24:56 +0200
Subject: [PATCH] cpu_x86: Separate vendor 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 x86ModelParseVendor function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 232266839c994dcf2958f1efdfe74cfb7973a749)

https://bugzilla.redhat.com/show_bug.cgi?id=1686895

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <aaa0e5fac04ccd7b267e6912ceb3308249d9217e.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/cpu/cpu_x86.c | 50 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 119ece4758..62894cae9b 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1217,6 +1217,36 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
 }
 
 
+static int
+x86ModelParseVendor(virCPUx86ModelPtr model,
+                    xmlXPathContextPtr ctxt,
+                    virCPUx86MapPtr map)
+{
+    VIR_AUTOFREE(char *) vendor = NULL;
+    int rc;
+
+    if ((rc = virXPathBoolean("boolean(./vendor)", ctxt)) <= 0)
+        return rc;
+
+    vendor = virXPathString("string(./vendor/@name)", ctxt);
+    if (!vendor) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Invalid vendor element in CPU model %s"),
+                       model->name);
+        return -1;
+    }
+
+    if (!(model->vendor = x86VendorFind(map, vendor))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unknown vendor %s referenced by CPU model %s"),
+                       vendor, model->name);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 x86ModelParse(xmlXPathContextPtr ctxt,
               const char *name,
@@ -1225,7 +1255,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
     virCPUx86MapPtr map = data;
     xmlNodePtr *nodes = NULL;
     virCPUx86ModelPtr model;
-    char *vendor = NULL;
     size_t i;
     int n;
     int ret = -1;
@@ -1242,22 +1271,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
     if (x86ModelParseSignature(model, ctxt) < 0)
         goto cleanup;
 
-    if (virXPathBoolean("boolean(./vendor)", ctxt)) {
-        vendor = virXPathString("string(./vendor/@name)", ctxt);
-        if (!vendor) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Invalid vendor element in CPU model %s"),
-                           model->name);
-            goto cleanup;
-        }
-
-        if (!(model->vendor = x86VendorFind(map, vendor))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Unknown vendor %s referenced by CPU model %s"),
-                           vendor, model->name);
-            goto cleanup;
-        }
-    }
+    if (x86ModelParseVendor(model, ctxt, map) < 0)
+        goto cleanup;
 
     n = virXPathNodeSet("./feature", ctxt, &nodes);
     if (n < 0)
@@ -1293,7 +1308,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
 
  cleanup:
     x86ModelFree(model);
-    VIR_FREE(vendor);
     VIR_FREE(nodes);
     return ret;
 }
-- 
2.22.0