bcddb9
From 054fbe2bdd426eb9f3346513ac7d39f0b843a04e Mon Sep 17 00:00:00 2001
bcddb9
Message-Id: <054fbe2bdd426eb9f3346513ac7d39f0b843a04e@dist-git>
bcddb9
From: Jiri Denemark <jdenemar@redhat.com>
bcddb9
Date: Wed, 20 Mar 2019 14:55:20 +0100
bcddb9
Subject: [PATCH] cpu_x86: Separate signature parsing from x86ModelParse
bcddb9
MIME-Version: 1.0
bcddb9
Content-Type: text/plain; charset=UTF-8
bcddb9
Content-Transfer-Encoding: 8bit
bcddb9
bcddb9
The code is separated into a new x86ModelParseSignature function.
bcddb9
bcddb9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
bcddb9
Reviewed-by: Ján Tomko <jtomko@redhat.com>
bcddb9
(cherry picked from commit fe78d2fda9f2dd67eb9daa98e48fbffa468d271e)
bcddb9
bcddb9
https://bugzilla.redhat.com/show_bug.cgi?id=1558558
bcddb9
https://bugzilla.redhat.com/show_bug.cgi?id=1687515
bcddb9
bcddb9
Conflicts:
bcddb9
	src/cpu/cpu_x86.c
bcddb9
            - other patches separating parts of x86ModelParse into
bcddb9
              smaller functions were not backported due to conflicts
bcddb9
              with older refactoring which is missing in RHEL-7
bcddb9
            - commit 118fcdd480ad38a3e8477f466f6a876dce7e9fa6 changing
bcddb9
              goto labels from "cleanup" to "error" was not backported
bcddb9
              because the goto statement is removed in this patch anyway
bcddb9
bcddb9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
bcddb9
Reviewed-by: Ján Tomko <jtomko@redhat.com>
bcddb9
---
bcddb9
 src/cpu/cpu_x86.c | 58 ++++++++++++++++++++++++++++-------------------
bcddb9
 1 file changed, 35 insertions(+), 23 deletions(-)
bcddb9
bcddb9
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
bcddb9
index 809da94117..668e8aa3f0 100644
bcddb9
--- a/src/cpu/cpu_x86.c
bcddb9
+++ b/src/cpu/cpu_x86.c
bcddb9
@@ -1184,6 +1184,39 @@ x86ModelCompare(virCPUx86ModelPtr model1,
bcddb9
 }
bcddb9
 
bcddb9
 
bcddb9
+static int
bcddb9
+x86ModelParseSignature(virCPUx86ModelPtr model,
bcddb9
+                       xmlXPathContextPtr ctxt)
bcddb9
+{
bcddb9
+
bcddb9
+    if (virXPathBoolean("boolean(./signature)", ctxt)) {
bcddb9
+        unsigned int sigFamily = 0;
bcddb9
+        unsigned int sigModel = 0;
bcddb9
+        int rc;
bcddb9
+
bcddb9
+        rc = virXPathUInt("string(./signature/@family)", ctxt, &sigFamily);
bcddb9
+        if (rc < 0 || sigFamily == 0) {
bcddb9
+            virReportError(VIR_ERR_INTERNAL_ERROR,
bcddb9
+                           _("Invalid CPU signature family in model %s"),
bcddb9
+                           model->name);
bcddb9
+            return -1;
bcddb9
+        }
bcddb9
+
bcddb9
+        rc = virXPathUInt("string(./signature/@model)", ctxt, &sigModel);
bcddb9
+        if (rc < 0 || sigModel == 0) {
bcddb9
+            virReportError(VIR_ERR_INTERNAL_ERROR,
bcddb9
+                           _("Invalid CPU signature model in model %s"),
bcddb9
+                           model->name);
bcddb9
+            return -1;
bcddb9
+        }
bcddb9
+
bcddb9
+        model->signature = x86MakeSignature(sigFamily, sigModel, 0);
bcddb9
+    }
bcddb9
+
bcddb9
+    return 0;
bcddb9
+}
bcddb9
+
bcddb9
+
bcddb9
 static virCPUx86ModelPtr
bcddb9
 x86ModelParse(xmlXPathContextPtr ctxt,
bcddb9
               virCPUx86MapPtr map)
bcddb9
@@ -1232,29 +1265,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
bcddb9
             goto error;
bcddb9
     }
bcddb9
 
bcddb9
-    if (virXPathBoolean("boolean(./signature)", ctxt)) {
bcddb9
-        unsigned int sigFamily = 0;
bcddb9
-        unsigned int sigModel = 0;
bcddb9
-        int rc;
bcddb9
-
bcddb9
-        rc = virXPathUInt("string(./signature/@family)", ctxt, &sigFamily);
bcddb9
-        if (rc < 0 || sigFamily == 0) {
bcddb9
-            virReportError(VIR_ERR_INTERNAL_ERROR,
bcddb9
-                           _("Invalid CPU signature family in model %s"),
bcddb9
-                           model->name);
bcddb9
-            goto cleanup;
bcddb9
-        }
bcddb9
-
bcddb9
-        rc = virXPathUInt("string(./signature/@model)", ctxt, &sigModel);
bcddb9
-        if (rc < 0 || sigModel == 0) {
bcddb9
-            virReportError(VIR_ERR_INTERNAL_ERROR,
bcddb9
-                           _("Invalid CPU signature model in model %s"),
bcddb9
-                           model->name);
bcddb9
-            goto cleanup;
bcddb9
-        }
bcddb9
-
bcddb9
-        model->signature = x86MakeSignature(sigFamily, sigModel, 0);
bcddb9
-    }
bcddb9
+    if (x86ModelParseSignature(model, ctxt) < 0)
bcddb9
+        goto error;
bcddb9
 
bcddb9
     if (virXPathBoolean("boolean(./vendor)", ctxt)) {
bcddb9
         vendor = virXPathString("string(./vendor/@name)", ctxt);
bcddb9
-- 
bcddb9
2.21.0
bcddb9