mfd: Simulate active high IRQs with wm831x
Hi Mark,
Smatch complains about d71820b8a8fbe9 "mfd: Simulate active high IRQs with wm831x"
drivers/mfd/wm831x-irq.c +522 wm831x_irq_thread(67)
error: buffer overflow 'wm831x->gpio_level' 16 <= 56
518 /* Simulate an edge triggered IRQ by polling the input
519 * status. This is sucky but improves interoperability.
520 */
521 if (primary == WM831X_GP_INT &&
522 wm831x->gpio_level[i - WM831X_IRQ_GPIO_1]) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
523 ret = wm831x_reg_read(wm831x, WM831X_GPIO_LEVEL);
524 while (ret & 1 << (i - WM831X_IRQ_GPIO_1)) {
525 handle_nested_irq(wm831x->irq_base + i);
526 ret = wm831x_reg_read(wm831x,
527 WM831X_GPIO_LEVEL);
528 }
529 }We're inside a for loop over ARRAY_SIZE(wm831x_irqs) which has 58 elements (so "i" is 0-57) and we subtract WM831X_IRQ_GPIO_1 (1) which gives us a max of 56. The ->gpio_level[] array only has 16 elements so we're reading beyond the end of the array.
In wm831x_irq_set_type() it only sets the first 11 elements of the ->gpio_level[] array. Perhaps something similar is needed here. I don't know the code well enough to say.
regards,
dan carpenter
Quoted 7 lines · Dan Carpenter
518 /* Simulate an edge triggered IRQ by polling the input
519 * status. This is sucky but improves interoperability.
520 */
521 if (primary == WM831X_GP_INT &&
522 wm831x->gpio_level[i - WM831X_IRQ_GPIO_1]) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Quoted 7 lines
We're inside a for loop over
ARRAY_SIZE(wm831x_irqs)which has 58 elements (so "i" is 0-57) and we subtractWM831X_IRQ_GPIO_1(1) which gives us a max of 56. The ->gpio_level[] array only has 16 elementsIn
wm831x_irq_set_type()it only sets the first 11 elements of the ->gpio_level[] array. Perhaps something similar is needed here. I don't know the code well enough to say.
There's no need for any additional checks, the check for the primary IRQ ensures that we know we're dealing with a GPIO IRQ.