[libvirt] [PATCH 4/6] util: Tweak virHostCPUGetInfoParseCPUFrequency()

Andrea Bolognani abologna at redhat.com
Mon Dec 11 16:40:34 UTC 2017


Just a couple of small cosmetic improvements, performed separately
from the pure code motion which created the function.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/util/virhostcpu.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 85803d527..e74125147 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -524,16 +524,19 @@ virHostCPUGetInfoParseCPUFrequency(const char *buf,
         while (*buf && c_isspace(*buf))
             buf++;
 
-        if (*buf != ':' || !buf[1]) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("parsing cpu MHz from cpuinfo"));
+        if (buf[0] != ':' || !buf[1]) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Missing or invalid CPU frequency in %s"),
+                           CPUINFO_PATH);
             goto cleanup;
         }
 
-        if (virStrToLong_ui(buf+1, &p, 10, &ui) == 0 &&
-            /* Accept trailing fractional part.  */
-            (*p == '\0' || *p == '.' || c_isspace(*p)))
+        /* Accept an unsigned value, optionally followed by
+         * a fractional part (which gets discarded) */
+        if (virStrToLong_ui(buf + 1, &p, 10, &ui) == 0 &&
+            (*p == '\0' || *p == '.' || c_isspace(*p))) {
             *mhz = ui;
+        }
     }
 
     ret = 0;
-- 
2.14.3




More information about the libvir-list mailing list