[PATCH 1/5] virCPUDefParseXML: Parse uint using virXPathUInt()

Michal Privoznik posted 5 patches 4 years, 4 months ago
[PATCH 1/5] virCPUDefParseXML: Parse uint using virXPathUInt()
Posted by Michal Privoznik 4 years, 4 months ago
There is no need to use virXPathULong() and a temporary UL
variable if we can use virXPathUInt() directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/cpu_conf.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 1674cd6957..d31f28dfe7 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -526,39 +526,33 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
     }
 
     if (virXPathNode("./topology[1]", ctxt)) {
-        unsigned long ul;
-
-        if (virXPathULong("string(./topology[1]/@sockets)", ctxt, &ul) < 0) {
+        if (virXPathUInt("string(./topology[1]/@sockets)", ctxt, &def->sockets) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Missing 'sockets' attribute in CPU topology"));
             return -1;
         }
-        def->sockets = (unsigned int) ul;
 
         if (virXPathNode("./topology[1]/@dies", ctxt)) {
-            if (virXPathULong("string(./topology[1]/@dies)", ctxt, &ul) < 0) {
+            if (virXPathUInt("string(./topology[1]/@dies)", ctxt, &def->dies) < 0) {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
                                _("Malformed 'dies' attribute in CPU topology"));
                 return -1;
             }
-            def->dies = (unsigned int) ul;
         } else {
             def->dies = 1;
         }
 
-        if (virXPathULong("string(./topology[1]/@cores)", ctxt, &ul) < 0) {
+        if (virXPathUInt("string(./topology[1]/@cores)", ctxt, &def->cores) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Missing 'cores' attribute in CPU topology"));
             return -1;
         }
-        def->cores = (unsigned int) ul;
 
-        if (virXPathULong("string(./topology[1]/@threads)", ctxt, &ul) < 0) {
+        if (virXPathUInt("string(./topology[1]/@threads)", ctxt, &def->threads) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Missing 'threads' attribute in CPU topology"));
             return -1;
         }
-        def->threads = (unsigned int) ul;
 
         if (!def->sockets || !def->cores || !def->threads || !def->dies) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
-- 
2.32.0

Re: [PATCH 1/5] virCPUDefParseXML: Parse uint using virXPathUInt()
Posted by Peter Krempa 4 years, 4 months ago
On Tue, Sep 21, 2021 at 16:50:27 +0200, Michal Privoznik wrote:
> There is no need to use virXPathULong() and a temporary UL
> variable if we can use virXPathUInt() directly.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/conf/cpu_conf.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>