linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: mfd: Simulate active high IRQs with wm831x
@ 2011-09-21  6:44 Dan Carpenter
  2011-09-21 12:23 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2011-09-21  6:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: Ian Lartey, Dimitris Papastamos, Samuel Ortiz, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mfd: Simulate active high IRQs with wm831x
  2011-09-21  6:44 mfd: Simulate active high IRQs with wm831x Dan Carpenter
@ 2011-09-21 12:23 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2011-09-21 12:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Ian Lartey, Dimitris Papastamos, Samuel Ortiz, linux-kernel

On Wed, Sep 21, 2011 at 09:44:15AM +0300, Dan Carpenter wrote:

>    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]) {
>                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> 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

> 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.

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-21 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-21  6:44 mfd: Simulate active high IRQs with wm831x Dan Carpenter
2011-09-21 12:23 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).