Skip to content

Commit 78e5a33

Browse files
committed
cpumask: fix checking valid cpu range
The range of valid CPUs is [0, nr_cpu_ids). Some cpumask functions are passed with a shifted CPU index, and for them, the valid range is [-1, nr_cpu_ids-1). Currently for those functions, we check the index against [-1, nr_cpu_ids), which is wrong. Signed-off-by: Yury Norov <[email protected]>
1 parent 8173aa2 commit 78e5a33

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

include/linux/cpumask.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ static inline unsigned int cpumask_last(const struct cpumask *srcp)
174174
static inline
175175
unsigned int cpumask_next(int n, const struct cpumask *srcp)
176176
{
177-
/* -1 is a legal arg here. */
178-
if (n != -1)
179-
cpumask_check(n);
177+
/* n is a prior cpu */
178+
cpumask_check(n + 1);
180179
return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
181180
}
182181

@@ -189,9 +188,8 @@ unsigned int cpumask_next(int n, const struct cpumask *srcp)
189188
*/
190189
static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
191190
{
192-
/* -1 is a legal arg here. */
193-
if (n != -1)
194-
cpumask_check(n);
191+
/* n is a prior cpu */
192+
cpumask_check(n + 1);
195193
return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
196194
}
197195

@@ -231,9 +229,8 @@ static inline
231229
unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
232230
const struct cpumask *src2p)
233231
{
234-
/* -1 is a legal arg here. */
235-
if (n != -1)
236-
cpumask_check(n);
232+
/* n is a prior cpu */
233+
cpumask_check(n + 1);
237234
return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p),
238235
nr_cpumask_bits, n + 1);
239236
}
@@ -263,8 +260,8 @@ static inline
263260
unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
264261
{
265262
cpumask_check(start);
266-
if (n != -1)
267-
cpumask_check(n);
263+
/* n is a prior cpu */
264+
cpumask_check(n + 1);
268265

269266
/*
270267
* Return the first available CPU when wrapping, or when starting before cpu0,

0 commit comments

Comments
 (0)