From: Mikael Pettersson <mikpe@it.uu.se>
To: Ben Dooks <ben-linux@fluff.org>
Cc: linux-kernel@vger.kernel.org, david-b@pacbell.net
Subject: Re: GPIO: Add generic gpio_to_irq call.
Date: Thu, 24 Jul 2008 14:17:00 +0200 [thread overview]
Message-ID: <18568.29372.218800.510498@harpo.it.uu.se> (raw)
In-Reply-To: <20080724114627.574586848@fluff.org.uk>
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;
> +}
next prev parent reply other threads:[~2008-07-24 12:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-24 11:46 Ben Dooks
2008-07-24 11:51 ` Ben Dooks
2008-07-24 12:17 ` Mikael Pettersson [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-09-14 20:57 Ben Dooks
2008-07-17 23:52 Ben Dooks
2008-07-17 23:50 Ben Dooks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18568.29372.218800.510498@harpo.it.uu.se \
--to=mikpe@it.uu.se \
--cc=ben-linux@fluff.org \
--cc=david-b@pacbell.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®