Messages in this thread | | | Date | Thu, 24 Jul 2008 14:17:00 +0200 | From | Mikael Pettersson <> | Subject | Re: GPIO: Add generic gpio_to_irq call. |
| |
Ben Dooks writes: > Add gpio_to_irq() implementation allowing the > gpio_chip registration to also specify an function > to map GPIO offsets into IRQs. > > Signed-off-by: Ben Dooks <ben-linux@fluff.org> > > Index: linux-2.6.26-quilt3/drivers/gpio/gpiolib.c > =================================================================== > --- linux-2.6.26-quilt3.orig/drivers/gpio/gpiolib.c 2008-07-18 13:50:32.000000000 +0100 > +++ linux-2.6.26-quilt3/drivers/gpio/gpiolib.c 2008-07-22 15:20:26.000000000 +0100 > @@ -339,6 +339,36 @@ const char *gpiochip_is_requested(struct > } > EXPORT_SYMBOL_GPL(gpiochip_is_requested); > > +int __gpio_to_irq(unsigned gpio) > +{ > + struct gpio_chip *chip; > + struct gpio_desc *desc = &gpio_desc[gpio]; > + unsigned long flags; > + int status = -EINVAL; > + > + spin_lock_irqsave(&gpio_lock, flags); > + > + if (!gpio_is_valid(gpio)) > + goto fail;
Please move the &gpio_desc[gpio] expression after the gpio_is_valid(gpio) test. Otherwise you risk violating C's pointer rules if the gpio is invalid.
> + > + chip = desc->chip; > + if (!chip || !chip->to_irq) > + goto fail; > + > + gpio -= chip->base; > + if (gpio >= chip->ngpio) > + goto fail; > + > + status = chip->to_irq(chip, gpio); > + > + fail: > + spin_unlock_irqrestore(&gpio_lock, flags); > + if (status) > + pr_debug("%s: gpio-%d status %d\n", > + __func__, gpio, status); > + return status; > +}
| |