aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/bpf_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/bpf/bpf_util.h')
-rw-r--r--tools/testing/selftests/bpf/bpf_util.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
index 20ecbaa0d85d..6c53a8906eff 100644
--- a/tools/testing/selftests/bpf/bpf_util.h
+++ b/tools/testing/selftests/bpf/bpf_util.h
@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
12 unsigned int start, end, possible_cpus = 0; 12 unsigned int start, end, possible_cpus = 0;
13 char buff[128]; 13 char buff[128];
14 FILE *fp; 14 FILE *fp;
15 int n;
15 16
16 fp = fopen(fcpu, "r"); 17 fp = fopen(fcpu, "r");
17 if (!fp) { 18 if (!fp) {
@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
20 } 21 }
21 22
22 while (fgets(buff, sizeof(buff), fp)) { 23 while (fgets(buff, sizeof(buff), fp)) {
23 if (sscanf(buff, "%u-%u", &start, &end) == 2) { 24 n = sscanf(buff, "%u-%u", &start, &end);
24 possible_cpus = start == 0 ? end + 1 : 0; 25 if (n == 0) {
25 break; 26 printf("Failed to retrieve # possible CPUs!\n");
27 exit(1);
28 } else if (n == 1) {
29 end = start;
26 } 30 }
31 possible_cpus = start == 0 ? end + 1 : 0;
32 break;
27 } 33 }
28
29 fclose(fp); 34 fclose(fp);
30 if (!possible_cpus) {
31 printf("Failed to retrieve # possible CPUs!\n");
32 exit(1);
33 }
34 35
35 return possible_cpus; 36 return possible_cpus;
36} 37}