sparc/irq: Remove on-stack cpumask var
authorDawei Li <dawei.li@shingroup.cn>
Wed, 24 Apr 2024 02:55:45 +0000 (10:55 +0800)
committerAndreas Larsson <andreas@gaisler.com>
Wed, 8 May 2024 17:42:15 +0000 (19:42 +0200)
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.

- Both 2 arguments of cpumask_equal() is constant and free of change, no
  need to allocate extra cpumask variables.

- Merge cpumask_and(), cpumask_first() and cpumask_empty() into
  cpumask_first_and().

Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Dawei Li <dawei.li@shingroup.cn>
Reviewed-by: Andreas Larsson <andreas@gaisler.com>
Link: https://lore.kernel.org/r/20240424025548.3765250-3-dawei.li@shingroup.cn
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
arch/sparc/kernel/irq_64.c

index 5280e325d4d6f1081dc6f5f7748fcaeaf71cb11c..01ee800efde3e91e149af9d2a76f7a4854b52ef7 100644 (file)
@@ -349,17 +349,13 @@ static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
 #ifdef CONFIG_SMP
 static int irq_choose_cpu(unsigned int irq, const struct cpumask *affinity)
 {
-       cpumask_t mask;
        int cpuid;
 
-       cpumask_copy(&mask, affinity);
-       if (cpumask_equal(&mask, cpu_online_mask)) {
+       if (cpumask_equal(affinity, cpu_online_mask)) {
                cpuid = map_to_cpu(irq);
        } else {
-               cpumask_t tmp;
-
-               cpumask_and(&tmp, cpu_online_mask, &mask);
-               cpuid = cpumask_empty(&tmp) ? map_to_cpu(irq) : cpumask_first(&tmp);
+               cpuid = cpumask_first_and(affinity, cpu_online_mask);
+               cpuid = cpuid < nr_cpu_ids ? cpuid : map_to_cpu(irq);
        }
 
        return cpuid;