[libvirt PATCH v2 02/20] cpu_x86: Simplify x86ParseMSR

Tim Wiederhake twiederh at redhat.com
Thu Nov 4 16:27:02 UTC 2021


... by using virXMLProp*() helpers. These only require a xmlNodePtr and
do not need a xmlXPathContextPtr. Reflect that in the function signature.

Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/cpu/cpu_x86.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index b0f6fa8f34..006221215a 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1048,26 +1048,22 @@ x86ParseCPUID(xmlNodePtr node,
 
 
 static int
-x86ParseMSR(xmlXPathContextPtr ctxt,
+x86ParseMSR(xmlNodePtr node,
             virCPUx86DataItem *item)
 {
-    virCPUx86MSR *msr;
-    unsigned long index;
-    unsigned long eax;
-    unsigned long edx;
+    virCPUx86MSR msr;
 
-    memset(item, 0, sizeof(*item));
+    memset(&msr, 0, sizeof(msr));
 
-    if (virXPathULongHex("string(@index)", ctxt, &index) < 0 ||
-        virXPathULongHex("string(@eax)", ctxt, &eax) < 0 ||
-        virXPathULongHex("string(@edx)", ctxt, &edx) < 0)
+    if (virXMLPropUInt(node, "index", 0, VIR_XML_PROP_REQUIRED, &msr.index) < 0)
+        return -1;
+    if (virXMLPropUInt(node, "eax", 0, VIR_XML_PROP_REQUIRED, &msr.eax) < 0)
+        return -1;
+    if (virXMLPropUInt(node, "edx", 0, VIR_XML_PROP_REQUIRED, &msr.edx) < 0)
         return -1;
 
     item->type = VIR_CPU_X86_DATA_MSR;
-    msr = &item->data.msr;
-    msr->index = index;
-    msr->eax = eax;
-    msr->edx = edx;
+    item->data.msr = msr;
     return 0;
 }
 
@@ -1120,7 +1116,7 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
                 return -1;
             }
         } else {
-            if (x86ParseMSR(ctxt, &item) < 0) {
+            if (x86ParseMSR(ctxt->node, &item) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Invalid msr[%zu] in %s feature"),
                                i, feature->name);
@@ -1809,7 +1805,7 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
                 return NULL;
             }
         } else {
-            if (x86ParseMSR(ctxt, &item) < 0) {
+            if (x86ParseMSR(ctxt->node, &item) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("failed to parse msr[%zu]"), i);
                 return NULL;
-- 
2.31.1




More information about the libvir-list mailing list