Skip to contentSkip to conversation

mips: irq: Use DECLARE_BITMAP

PATCH In review Joe Perches 2 participants 3 messages May 20, 2015 – May 21, 2015 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mips: irq: Use DECLARE_BITMAP

Use the generic mechanism to declare a bitmap instead of unsigned long.

This could fix an overwrite defect of whatever follows irq_map.

Not all "#define NR_IRQS <value>" are a multiple of BITS_PER_LONG so using DECLARE_BITMAP allocates the proper number of longs required for the possible bits.

For instance:

arch/mips/include/asm/mach-ath79/irq.h:#define NR_IRQS 51
arch/mips/include/asm/mach-db1x00/irq.h:#define NR_IRQS 152 arch/mips/include/asm/mach-lantiq/falcon/irq.h:#define NR_IRQS 328

---
 arch/mips/kernel/irq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/irq.c +1 -1
index d2bfbc2..51f57d8 100644
@@ -29,7 +29,7 @@
 int kgdb_early_setup;
 #endif
 
-static unsigned long irq_map[NR_IRQS / BITS_PER_LONG];
+static DECLARE_BITMAP(irq_map, NR_IRQS);
 
 int allocate_irqno(void)
 {
#1 lore raw
Quoted 8 lines · Joe Perches

Use the generic mechanism to declare a bitmap instead of unsigned long.

This could fix an overwrite defect of whatever follows irq_map.

Not all "#define NR_IRQS <value>" are a multiple of BITS_PER_LONG so using DECLARE_BITMAP allocates the proper number of longs required for the possible bits.

Quoted 5 lines

For instance:

arch/mips/include/asm/mach-ath79/irq.h:#define NR_IRQS 51
arch/mips/include/asm/mach-db1x00/irq.h:#define NR_IRQS 152 arch/mips/include/asm/mach-lantiq/falcon/irq.h:#define NR_IRQS 328

This only matters to user of the allocate_irqno() API and there is only on such platform, the IP27 which fortunately uses a NR_IRQS value that is a multiple of 64, so no impact.

Thanks anyway!

Ralf

#2 lore raw
Quoted 16 lines · Ralf Baechle
Quoted 8 lines · Joe Perches

Use the generic mechanism to declare a bitmap instead of unsigned long.

This could fix an overwrite defect of whatever follows irq_map.

Not all "#define NR_IRQS <value>" are a multiple of BITS_PER_LONG so using DECLARE_BITMAP allocates the proper number of longs required for the possible bits.

Quoted 5 lines

For instance:

arch/mips/include/asm/mach-ath79/irq.h:#define NR_IRQS 51
arch/mips/include/asm/mach-db1x00/irq.h:#define NR_IRQS 152 arch/mips/include/asm/mach-lantiq/falcon/irq.h:#define NR_IRQS 328

Quoted 5 lines

This only matters to user of the allocate_irqno() API and there is only on such platform, the IP27 which fortunately uses a NR_IRQS value that is a multiple of 64, so no impact.

Thanks anyway!

I think you should apply it anyway as it's an error-prone style.

There are 3 mechanisms used today in the kernel to declare bitmap arrays.

DECLARE_BITMAP(array, size) unsigned long array[BITS_TO_LONGS(size)] unsigned long array[size/BITS_PER_LONG]

The first 2 are fine, the last has this defect possible whenever size % BITS_PER_LONG != 0.

The series I sent converts all the uses of the the possibly defective style.

cheers, Joe