Re: GPIO: Add generic gpio_to_irq call.
From: Mikael Pettersson
Date: Thu Jul 24 2008 - 08:17:22 EST
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@xxxxxxxxx>
>
> 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;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/