]> git.hungrycats.org Git - linux/commit
tools/power turbostat: Fix trailing '\n' parsing
authorZhang Rui <rui.zhang@intel.com>
Tue, 27 Aug 2024 05:07:51 +0000 (13:07 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:54:33 +0000 (13:54 +0100)
commit2409cf42bce57992adc1791ccecf45fc812d465e
tree6cec30e22388474f1e7c5da0f855ec0edce43b30
parent6ba6e19912570b2ad68298be0be1dc779014a303
tools/power turbostat: Fix trailing '\n' parsing

[ Upstream commit fed8511cc8996989178823052dc0200643e1389a ]

parse_cpu_string() parses the string input either from command line or
from /sys/fs/cgroup/cpuset.cpus.effective to get a list of CPUs that
turbostat can run with.

The cpu string returned by /sys/fs/cgroup/cpuset.cpus.effective contains
a trailing '\n', but strtoul() fails to treat this as an error.

That says, for the code below
val = ("\n", NULL, 10);
val returns 0, and errno is also not set.

As a result, CPU0 is erroneously considered as allowed CPU and this
causes failures when turbostat tries to run on CPU0.

 get_counters: Could not migrate to CPU 0
 ...
 turbostat: re-initialized with num_cpus 8, allowed_cpus 5
 get_counters: Could not migrate to CPU 0

Add a check to return immediately if '\n' or '\0' is detected.

Fixes: 8c3dd2c9e542 ("tools/power/turbostat: Abstrct function for parsing cpu string")
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/power/x86/turbostat/turbostat.c