Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

irqchip/riscv-aplic-direct: Avoid explicit cpumask allocation on stack

In general it's preferable to avoid placing cpumasks on the stack, as
for large values of NR_CPUS these can consume significant amounts of
stack space and make stack overflows more likely.

Use cpumask_first_and_and() to avoid the need for a temporary cpumask on
the stack.

Signed-off-by: Dawei Li <dawei.li@shingroup.cn>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20240416085454.3547175-6-dawei.li@shingroup.cn

authored by

Dawei Li and committed by
Thomas Gleixner
5d650d1e 2bc32db5

+2 -5
+2 -5
drivers/irqchip/irq-riscv-aplic-direct.c
··· 54 54 struct aplic_direct *direct = container_of(priv, struct aplic_direct, priv); 55 55 struct aplic_idc *idc; 56 56 unsigned int cpu, val; 57 - struct cpumask amask; 58 57 void __iomem *target; 59 58 60 - cpumask_and(&amask, &direct->lmask, mask_val); 61 - 62 59 if (force) 63 - cpu = cpumask_first(&amask); 60 + cpu = cpumask_first_and(&direct->lmask, mask_val); 64 61 else 65 - cpu = cpumask_any_and(&amask, cpu_online_mask); 62 + cpu = cpumask_first_and_and(&direct->lmask, mask_val, cpu_online_mask); 66 63 67 64 if (cpu >= nr_cpu_ids) 68 65 return -EINVAL;