diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 0a9a6da21e74..db21f68aaef0 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -83,7 +83,13 @@ extern const struct cpumask *const cpu_active_mask; #if NR_CPUS > 1 #define num_online_cpus() cpumask_weight(cpu_online_mask) -#define num_possible_cpus() cpumask_weight(cpu_possible_mask) +/* + * For platforms with discontig CPU numbering, the weight of the possible + * bitmask may be less than the highest numbered CPU. Return the max of + * the two, to prevent accidentical bugs. + */ +#define num_possible_cpus() \ + max_t(unsigned int, cpumask_weight(cpu_possible_mask), nr_cpu_ids) #define num_present_cpus() cpumask_weight(cpu_present_mask) #define num_active_cpus() cpumask_weight(cpu_active_mask) #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)