render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From e1b42297bc41c8f356693f2756e806a8c7275f4f Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <e1b42297bc41c8f356693f2756e806a8c7275f4f@dist-git>
c480ed
From: Jiri Denemark <jdenemar@redhat.com>
c480ed
Date: Fri, 21 Jun 2019 09:24:56 +0200
c480ed
Subject: [PATCH] cpu_x86: Separate vendor parsing from x86ModelParse
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
The code is separated into a new x86ModelParseVendor function.
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
(cherry picked from commit 232266839c994dcf2958f1efdfe74cfb7973a749)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1686895
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Message-Id: <aaa0e5fac04ccd7b267e6912ceb3308249d9217e.1561068591.git.jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/cpu/cpu_x86.c | 50 ++++++++++++++++++++++++++++++-----------------
c480ed
 1 file changed, 32 insertions(+), 18 deletions(-)
c480ed
c480ed
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
c480ed
index 119ece4758..62894cae9b 100644
c480ed
--- a/src/cpu/cpu_x86.c
c480ed
+++ b/src/cpu/cpu_x86.c
c480ed
@@ -1217,6 +1217,36 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+x86ModelParseVendor(virCPUx86ModelPtr model,
c480ed
+                    xmlXPathContextPtr ctxt,
c480ed
+                    virCPUx86MapPtr map)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) vendor = NULL;
c480ed
+    int rc;
c480ed
+
c480ed
+    if ((rc = virXPathBoolean("boolean(./vendor)", ctxt)) <= 0)
c480ed
+        return rc;
c480ed
+
c480ed
+    vendor = virXPathString("string(./vendor/@name)", ctxt);
c480ed
+    if (!vendor) {
c480ed
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                       _("Invalid vendor element in CPU model %s"),
c480ed
+                       model->name);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (!(model->vendor = x86VendorFind(map, vendor))) {
c480ed
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                       _("Unknown vendor %s referenced by CPU model %s"),
c480ed
+                       vendor, model->name);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 static int
c480ed
 x86ModelParse(xmlXPathContextPtr ctxt,
c480ed
               const char *name,
c480ed
@@ -1225,7 +1255,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
c480ed
     virCPUx86MapPtr map = data;
c480ed
     xmlNodePtr *nodes = NULL;
c480ed
     virCPUx86ModelPtr model;
c480ed
-    char *vendor = NULL;
c480ed
     size_t i;
c480ed
     int n;
c480ed
     int ret = -1;
c480ed
@@ -1242,22 +1271,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
c480ed
     if (x86ModelParseSignature(model, ctxt) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
-    if (virXPathBoolean("boolean(./vendor)", ctxt)) {
c480ed
-        vendor = virXPathString("string(./vendor/@name)", ctxt);
c480ed
-        if (!vendor) {
c480ed
-            virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
-                           _("Invalid vendor element in CPU model %s"),
c480ed
-                           model->name);
c480ed
-            goto cleanup;
c480ed
-        }
c480ed
-
c480ed
-        if (!(model->vendor = x86VendorFind(map, vendor))) {
c480ed
-            virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
-                           _("Unknown vendor %s referenced by CPU model %s"),
c480ed
-                           vendor, model->name);
c480ed
-            goto cleanup;
c480ed
-        }
c480ed
-    }
c480ed
+    if (x86ModelParseVendor(model, ctxt, map) < 0)
c480ed
+        goto cleanup;
c480ed
 
c480ed
     n = virXPathNodeSet("./feature", ctxt, &nodes);
c480ed
     if (n < 0)
c480ed
@@ -1293,7 +1308,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
c480ed
 
c480ed
  cleanup:
c480ed
     x86ModelFree(model);
c480ed
-    VIR_FREE(vendor);
c480ed
     VIR_FREE(nodes);
c480ed
     return ret;
c480ed
 }
c480ed
-- 
c480ed
2.22.0
c480ed