Skip to content

Commit 56a268c

Browse files
thomasmeyShuah Khan
authored andcommitted
selftests/bpf: Make bpf_util work on uniprocessor systems
The current implementation fails to work on uniprocessor systems. Fix the parser to also handle the uniprocessor case. Signed-off-by: Thomas Meyer <thomas@m3y3r.de> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
1 parent 6f00033 commit 56a268c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

tools/testing/selftests/bpf/bpf_util.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
1212
unsigned int start, end, possible_cpus = 0;
1313
char buff[128];
1414
FILE *fp;
15+
int n;
1516

1617
fp = fopen(fcpu, "r");
1718
if (!fp) {
@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
2021
}
2122

2223
while (fgets(buff, sizeof(buff), fp)) {
23-
if (sscanf(buff, "%u-%u", &start, &end) == 2) {
24-
possible_cpus = start == 0 ? end + 1 : 0;
25-
break;
24+
n = sscanf(buff, "%u-%u", &start, &end);
25+
if (n == 0) {
26+
printf("Failed to retrieve # possible CPUs!\n");
27+
exit(1);
28+
} else if (n == 1) {
29+
end = start;
2630
}
31+
possible_cpus = start == 0 ? end + 1 : 0;
32+
break;
2733
}
28-
2934
fclose(fp);
30-
if (!possible_cpus) {
31-
printf("Failed to retrieve # possible CPUs!\n");
32-
exit(1);
33-
}
3435

3536
return possible_cpus;
3637
}

0 commit comments

Comments
 (0)