[v2] power: fix pstate number parsing

Message ID 20221012123637.51640-1-markus.theil@tu-ilmenau.de (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] power: fix pstate number parsing |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed

Commit Message

Markus Theil Oct. 12, 2022, 12:36 p.m. UTC
From: Markus Theil <markus.theil@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")
Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>
Acked-by: Reshma Pattan <reshma.pattan@intel.com>
Signed-off-by: Markus Theil <markus.theil@secunet.com>
---
 lib/power/power_pstate_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.38.0
  

Comments

Thomas Monjalon Oct. 26, 2022, 9:35 p.m. UTC | #1
12/10/2022 14:36, Markus Theil:
> From: Markus Theil <markus.theil@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")
> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>
> Acked-by: Reshma Pattan <reshma.pattan@intel.com>
> Signed-off-by: Markus Theil <markus.theil@secunet.com>

Applied, thanks.
  

Patch

diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index 49ddb2eefd..52aa64510e 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -96,7 +96,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;