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

mfd: rc5t583: Fix array subscript is above array bounds

I got below build warning while compiling this driver.
It's obviously RC5T583_MAX_INTERRUPT_MASK_REGS is 9 but irq_en_add
array only has 8 elements.

CC drivers/mfd/rc5t583-irq.o
drivers/mfd/rc5t583-irq.c: In function 'rc5t583_irq_sync_unlock':
drivers/mfd/rc5t583-irq.c:227: warning: array subscript is above array bounds
drivers/mfd/rc5t583-irq.c: In function 'rc5t583_irq_init':
drivers/mfd/rc5t583-irq.c:349: warning: array subscript is above array bounds

Since the number of interrupt enable registers is 8, this patch adds
define for RC5T583_MAX_INTERRUPT_EN_REGS to fix this bug.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Axel Lin and committed by
Samuel Ortiz
3f9be35b 302b9562

+3 -2
+1 -1
drivers/mfd/rc5t583-irq.c
··· 345 345 mutex_init(&rc5t583->irq_lock); 346 346 347 347 /* Initailize all int register to 0 */ 348 - for (i = 0; i < RC5T583_MAX_INTERRUPT_MASK_REGS; i++) { 348 + for (i = 0; i < RC5T583_MAX_INTERRUPT_EN_REGS; i++) { 349 349 ret = rc5t583_write(rc5t583->dev, irq_en_add[i], 350 350 rc5t583->irq_en_reg[i]); 351 351 if (ret < 0)
+2 -1
include/linux/mfd/rc5t583.h
··· 33 33 /* Maximum number of main interrupts */ 34 34 #define MAX_MAIN_INTERRUPT 5 35 35 #define RC5T583_MAX_GPEDGE_REG 2 36 + #define RC5T583_MAX_INTERRUPT_EN_REGS 8 36 37 #define RC5T583_MAX_INTERRUPT_MASK_REGS 9 37 38 38 39 /* Interrupt enable register */ ··· 305 304 uint8_t intc_inten_reg; 306 305 307 306 /* For group interrupt bits and address */ 308 - uint8_t irq_en_reg[RC5T583_MAX_INTERRUPT_MASK_REGS]; 307 + uint8_t irq_en_reg[RC5T583_MAX_INTERRUPT_EN_REGS]; 309 308 310 309 /* For gpio edge */ 311 310 uint8_t gpedge_reg[RC5T583_MAX_GPEDGE_REG];