From: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Introduce a gpio_is_valid() predicate; use it in gpiolib.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
[ use inline function; follow the gpio_* naming convention;
work without gpiolib; all programming interfaces need docs ]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
Documentation/gpio.txt | 10 ++++++++++
drivers/gpio/gpiolib.c | 14 +++++++-------
include/asm-generic/gpio.h | 12 ++++++++++++
3 files changed, 29 insertions(+), 7 deletions(-)
--- g26.orig/Documentation/gpio.txt 2008-02-10 16:06:30.000000000 -0800
+++ g26/Documentation/gpio.txt 2008-02-10 16:09:54.000000000 -0800
@@ -102,6 +102,16 @@ type of GPIO controller, and on one part
The numbers need not be contiguous; either of those platforms could also
use numbers 2000-2063 to identify GPIOs in a bank of I2C GPIO expanders.
+If you want to initialize a structure with an invalid GPIO number, use
+some negative number (perhaps "-EINVAL"); that will never be valid. To
+test if a number could reference a GPIO, you may use this predicate:
+
+ int gpio_is_valid(int number);
+
+A number that's not valid will be rejected by calls which may request
+or free GPIOs (see below). Other numbers may also be rejected; for
+example, a number might be valid but unused on a given board.
+
Whether a platform supports multiple GPIO controllers is currently a
platform-specific implementation issue.
--- g26.orig/drivers/gpio/gpiolib.c 2008-02-10 16:09:51.000000000 -0800
+++ g26/drivers/gpio/gpiolib.c 2008-02-10 16:09:54.000000000 -0800
@@ -96,7 +96,7 @@ int gpiochip_add(struct gpio_chip *chip)
* dynamic allocation. We don't currently support that.
*/
- if (chip->base < 0 || (chip->base + chip->ngpio) >= ARCH_NR_GPIOS) {
+ if (chip->base < 0 || !gpio_is_valid(chip->base + chip->ngpio)) {
status = -EINVAL;
goto fail;
}
@@ -171,7...