[hackers] [PATCH] Do not return NULL in cpu when setting valid

From: David Demelier <markand_AT_malikania.fr>
Date: Mon, 16 Apr 2018 16:20:47 +0200

On the first call to the cpu_freq|cpu_iowait user may see an initial n/a result
because NULL is returned but the value has been parsed correctly.

Example:

[CPU n/a%] [RAM 52%] [ 2018-04-16 15:55:19 ]
[CPU 16%] [RAM 52%] [ 2018-04-16 15:55:20 ]
[CPU 2%] [RAM 52%] [ 2018-04-16 15:55:21 ]
---
 components/cpu.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/components/cpu.c b/components/cpu.c
index a001d14..646cdad 100644
--- a/components/cpu.c
+++ b/components/cpu.c
_AT_@ -28,10 +28,8 @@ cpu_perc(void)
 	           &a[3], &a[4], &a[5], &a[6]) != 7) {
 		return NULL;
 	}
-	if (!valid) {
+	if (!valid)
 		valid = 1;
-		return NULL;
-	}
 
 	perc = 100 * ((b[0]+b[1]+b[2]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[5]+a[6])) /
 	       ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
_AT_@ -52,10 +50,8 @@ cpu_iowait(void)
 	           &a[3], &a[4], &a[5], &a[6]) != 7) {
 		return NULL;
 	}
-	if (!valid) {
+	if (!valid)
 		valid = 1;
-		return NULL;
-	}
 
 	perc = 100 * ((b[4]) - (a[4])) /
 	       ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
-- 
2.14.3
Received on Mon Apr 16 2018 - 16:20:47 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 16 2018 - 16:24:24 CEST