[PATCH] power: fix pstate number parsing
Markus Theil
markus.theil at tu-ilmenau.de
Wed Oct 12 13:33:42 CEST 2022
From: Markus Theil <markus.theil at secunet.com>
When converting atoi to strtol in a revision
of introducing sysfs support for turbo percentage,
a necessary check against '\n' returned by sysfs
was not introduced.
Fixes: de254dac608e ("power: read P-state turbo percentage from sysfs")
Signed-off-by: Markus Theil <markus.theil at secunet.com>
---
lib/power/power_pstate_cpufreq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index 49ddb2eefd..7e660618db 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -2,6 +2,7 @@
* Copyright(c) 2018 Intel Corporation
*/
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -96,7 +97,7 @@ power_read_turbo_pct(uint64_t *outVal)
errno = 0;
*outVal = (uint64_t) strtol(val, &endptr, 10);
- if (*endptr != 0 || errno != 0) {
+ if (errno != 0 || (*endptr != 0 && *endptr != '\n')) {
RTE_LOG(ERR, POWER, "Error converting str to digits, read from %s: %s\n",
POWER_SYSFILE_TURBO_PCT, strerror(errno));
ret = -1;
--
2.38.0
More information about the dev
mailing list