diff options
Diffstat (limited to 'tools/testing/selftests/bpf/bpf_util.h')
| -rw-r--r-- | tools/testing/selftests/bpf/bpf_util.h | 18 | 
1 files changed, 10 insertions, 8 deletions
| diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h index 20ecbaa0d85d..d0811b3d6a6f 100644 --- a/tools/testing/selftests/bpf/bpf_util.h +++ b/tools/testing/selftests/bpf/bpf_util.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */  #ifndef __BPF_UTIL__  #define __BPF_UTIL__ @@ -12,6 +13,7 @@ static inline unsigned int bpf_num_possible_cpus(void)  	unsigned int start, end, possible_cpus = 0;  	char buff[128];  	FILE *fp; +	int n;  	fp = fopen(fcpu, "r");  	if (!fp) { @@ -20,17 +22,17 @@ static inline unsigned int bpf_num_possible_cpus(void)  	}  	while (fgets(buff, sizeof(buff), fp)) { -		if (sscanf(buff, "%u-%u", &start, &end) == 2) { -			possible_cpus = start == 0 ? end + 1 : 0; -			break; +		n = sscanf(buff, "%u-%u", &start, &end); +		if (n == 0) { +			printf("Failed to retrieve # possible CPUs!\n"); +			exit(1); +		} else if (n == 1) { +			end = start;  		} +		possible_cpus = start == 0 ? end + 1 : 0; +		break;  	} -  	fclose(fp); -	if (!possible_cpus) { -		printf("Failed to retrieve # possible CPUs!\n"); -		exit(1); -	}  	return possible_cpus;  } |