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

irqchip/sifive-plic: 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-7-dawei.li@shingroup.cn

authored by

Dawei Li and committed by
Thomas Gleixner
a7fb69ff 5d650d1e

+2 -5
+2 -5
drivers/irqchip/irq-sifive-plic.c
··· 164 164 const struct cpumask *mask_val, bool force) 165 165 { 166 166 unsigned int cpu; 167 - struct cpumask amask; 168 167 struct plic_priv *priv = irq_data_get_irq_chip_data(d); 169 168 170 - cpumask_and(&amask, &priv->lmask, mask_val); 171 - 172 169 if (force) 173 - cpu = cpumask_first(&amask); 170 + cpu = cpumask_first_and(&priv->lmask, mask_val); 174 171 else 175 - cpu = cpumask_any_and(&amask, cpu_online_mask); 172 + cpu = cpumask_first_and_and(&priv->lmask, mask_val, cpu_online_mask); 176 173 177 174 if (cpu >= nr_cpu_ids) 178 175 return -EINVAL;