irqchip: mips-gic: Use cpumask_first_and() in gic_set_affinity()
authorPaul Burton <paul.burton@imgtec.com>
Fri, 18 Aug 2017 21:04:35 +0000 (14:04 -0700)
committerRalf Baechle <ralf@linux-mips.org>
Mon, 4 Sep 2017 11:53:15 +0000 (13:53 +0200)
Currently in gic_set_affinity() we calculate a temporary cpumask holding
the intersection of the provided cpumask & the CPUs that are online,
then we call cpumask_first twice on it to find the first such CPU. Since
we don't need the temporary cpumask for anything else & we only care
about the first CPU that's both online & in the provided cpumask, we can
instead use cpumask_first_and to find that CPU & drop the temporary
mask.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/17110/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
drivers/irqchip/irq-mips-gic.c

index 183c225b84de6f343f9285dad8acb8ce3ca1b310..8f64ac824d20222f86ae6c0b3d2abbc9e47d4f8c 100644 (file)
@@ -250,23 +250,23 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
                            bool force)
 {
        unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq);
-       cpumask_t       tmp = CPU_MASK_NONE;
-       unsigned long   flags;
+       unsigned long flags;
+       unsigned int cpu;
 
-       cpumask_and(&tmp, cpumask, cpu_online_mask);
-       if (cpumask_empty(&tmp))
+       cpu = cpumask_first_and(cpumask, cpu_online_mask);
+       if (cpu >= NR_CPUS)
                return -EINVAL;
 
        /* Assumption : cpumask refers to a single CPU */
        spin_lock_irqsave(&gic_lock, flags);
 
        /* Re-route this IRQ */
-       write_gic_map_vp(irq, BIT(mips_cm_vp_id(cpumask_first(&tmp))));
+       write_gic_map_vp(irq, BIT(mips_cm_vp_id(cpu)));
 
        /* Update the pcpu_masks */
        gic_clear_pcpu_masks(irq);
        if (read_gic_mask(irq))
-               set_bit(irq, per_cpu_ptr(pcpu_masks, cpumask_first(&tmp)));
+               set_bit(irq, per_cpu_ptr(pcpu_masks, cpu));
 
        cpumask_copy(irq_data_get_affinity_mask(d), cpumask);
        spin_unlock_irqrestore(&gic_lock, flags);