Skip to content

Commit a109b53

Browse files
zhang-ruigregkh
authored andcommitted
tools/power turbostat: Fix trailing '\n' parsing
[ Upstream commit fed8511 ] 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: 8c3dd2c ("tools/power/turbostat: Abstrct function for parsing cpu string") Signed-off-by: Zhang Rui <[email protected]> Signed-off-by: Len Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 588bdec commit a109b53

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5385,6 +5385,9 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size)
53855385
if (*next == '-') /* no negative cpu numbers */
53865386
return 1;
53875387

5388+
if (*next == '\0' || *next == '\n')
5389+
break;
5390+
53885391
start = strtoul(next, &next, 10);
53895392

53905393
if (start >= CPU_SUBSET_MAXCPUS)

0 commit comments

Comments
 (0)