[PATCH v4] cpumask: Fix implicit type conversion

From: Jiasheng Jiang
Date: Thu Oct 28 2021 - 08:42:15 EST


Although the upper bounds for NR_CPUS are less than 2^13 now, maybe
in the future the NR_CPUS will increase and become bigger than
INT_MAX.
Therefore, it might be better to add the assertion in case it will
be forgotten when the futurn come true.
Anyway, patch costs much less than the loss.
Also, it might be better to fix the macro description of 'cpu' and
deal with all the existing issues.

Signed-off-by: Jiasheng Jiang <jiasheng@xxxxxxxxxxx>
---
include/linux/cpumask.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index bfc4690..c433c9b 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -183,7 +183,7 @@ static inline int cpumask_any_distribute(const struct cpumask *srcp)
for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)(start))
#define for_each_cpu_and(cpu, mask1, mask2) \
for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2)
-#else
+#elif NR_CPUS <= 2147483647
/**
* cpumask_first - get the first cpu in a cpumask
* @srcp: the cpumask pointer
@@ -232,7 +232,7 @@ int cpumask_any_distribute(const struct cpumask *srcp);

/**
* for_each_cpu - iterate over every cpu in a mask
- * @cpu: the (optionally unsigned) integer iterator
+ * @cpu: the integer iterator
* @mask: the cpumask pointer
*
* After the loop, cpu is >= nr_cpu_ids.
@@ -244,7 +244,7 @@ int cpumask_any_distribute(const struct cpumask *srcp);

/**
* for_each_cpu_not - iterate over every cpu in a complemented mask
- * @cpu: the (optionally unsigned) integer iterator
+ * @cpu: the integer iterator
* @mask: the cpumask pointer
*
* After the loop, cpu is >= nr_cpu_ids.
@@ -258,7 +258,7 @@ extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool

/**
* for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location
- * @cpu: the (optionally unsigned) integer iterator
+ * @cpu: the integer iterator
* @mask: the cpumask poiter
* @start: the start location
*
@@ -273,7 +273,7 @@ extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool

/**
* for_each_cpu_and - iterate over every cpu in both masks
- * @cpu: the (optionally unsigned) integer iterator
+ * @cpu: the integer iterator
* @mask1: the first cpumask pointer
* @mask2: the second cpumask pointer
*
--
2.7.4