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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux