Skip to content

Commit 189572b

Browse files
YuryNorovbp3tk0v
authored andcommitted
cpumask: Relax cpumask_any_but()
Similarly to other cpumask search functions, accept -1, and consider it as 'any CPU' hint. This helps users to avoid coding special cases. Signed-off-by: Yury Norov [NVIDIA] <[email protected]> Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: James Morse <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Tested-by: James Morse <[email protected]> Tested-by: Tony Luck <[email protected]> Tested-by: Fenghua Yu <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent 82f2b0b commit 189572b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

include/linux/cpumask.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,18 @@ unsigned int cpumask_next_wrap(int n, const struct cpumask *src)
413413
* @cpu: the cpu to ignore.
414414
*
415415
* Often used to find any cpu but smp_processor_id() in a mask.
416+
* If @cpu == -1, the function is equivalent to cpumask_any().
416417
* Return: >= nr_cpu_ids if no cpus set.
417418
*/
418419
static __always_inline
419-
unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
420+
unsigned int cpumask_any_but(const struct cpumask *mask, int cpu)
420421
{
421422
unsigned int i;
422423

423-
cpumask_check(cpu);
424+
/* -1 is a legal arg here. */
425+
if (cpu != -1)
426+
cpumask_check(cpu);
427+
424428
for_each_cpu(i, mask)
425429
if (i != cpu)
426430
break;
@@ -433,16 +437,20 @@ unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
433437
* @mask2: the second input cpumask
434438
* @cpu: the cpu to ignore
435439
*
440+
* If @cpu == -1, the function is equivalent to cpumask_any_and().
436441
* Returns >= nr_cpu_ids if no cpus set.
437442
*/
438443
static __always_inline
439444
unsigned int cpumask_any_and_but(const struct cpumask *mask1,
440445
const struct cpumask *mask2,
441-
unsigned int cpu)
446+
int cpu)
442447
{
443448
unsigned int i;
444449

445-
cpumask_check(cpu);
450+
/* -1 is a legal arg here. */
451+
if (cpu != -1)
452+
cpumask_check(cpu);
453+
446454
i = cpumask_first_and(mask1, mask2);
447455
if (i != cpu)
448456
return i;

0 commit comments

Comments
 (0)