aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@pengutronix.de>2008-04-28 05:14:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-28 11:58:34 -0400
commite6de1808f8ebfeb7e49f3c5a30cb8f2032beb287 (patch)
tree2230ea8f384449c7785d636ab016af3b2aa20123 /drivers/gpio
parentd72cbed0c486e3db8b56380635f8e845073ce63a (diff)
gpio: define gpio_is_valid()
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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index eb75d12e83b7..623fcd9b547a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -99,7 +99,7 @@ int gpiochip_add(struct gpio_chip *chip)
99 * dynamic allocation. We don't currently support that. 99 * dynamic allocation. We don't currently support that.
100 */ 100 */
101 101
102 if (chip->base < 0 || (chip->base + chip->ngpio) >= ARCH_NR_GPIOS) { 102 if (chip->base < 0 || !gpio_is_valid(chip->base + chip->ngpio)) {
103 status = -EINVAL; 103 status = -EINVAL;
104 goto fail; 104 goto fail;
105 } 105 }
@@ -174,7 +174,7 @@ int gpio_request(unsigned gpio, const char *label)
174 174
175 spin_lock_irqsave(&gpio_lock, flags); 175 spin_lock_irqsave(&gpio_lock, flags);
176 176
177 if (gpio >= ARCH_NR_GPIOS) 177 if (!gpio_is_valid(gpio))
178 goto done; 178 goto done;
179 desc = &gpio_desc[gpio]; 179 desc = &gpio_desc[gpio];
180 if (desc->chip == NULL) 180 if (desc->chip == NULL)
@@ -209,7 +209,7 @@ void gpio_free(unsigned gpio)
209 unsigned long flags; 209 unsigned long flags;
210 struct gpio_desc *desc; 210 struct gpio_desc *desc;
211 211
212 if (gpio >= ARCH_NR_GPIOS) { 212 if (!gpio_is_valid(gpio)) {
213 WARN_ON(extra_checks); 213 WARN_ON(extra_checks);
214 return; 214 return;
215 } 215 }
@@ -245,7 +245,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset)
245{ 245{
246 unsigned gpio = chip->base + offset; 246 unsigned gpio = chip->base + offset;
247 247
248 if (gpio >= ARCH_NR_GPIOS || gpio_desc[gpio].chip != chip) 248 if (!gpio_is_valid(gpio) || gpio_desc[gpio].chip != chip)
249 return NULL; 249 return NULL;
250 if (test_bit(FLAG_REQUESTED, &gpio_desc[gpio].flags) == 0) 250 if (test_bit(FLAG_REQUESTED, &gpio_desc[gpio].flags) == 0)
251 return NULL; 251 return NULL;
@@ -276,7 +276,7 @@ int gpio_direction_input(unsigned gpio)
276 276
277 spin_lock_irqsave(&gpio_lock, flags); 277 spin_lock_irqsave(&gpio_lock, flags);
278 278
279 if (gpio >= ARCH_NR_GPIOS) 279 if (!gpio_is_valid(gpio))
280 goto fail; 280 goto fail;
281 chip = desc->chip; 281 chip = desc->chip;
282 if (!chip || !chip->get || !chip->direction_input) 282 if (!chip || !chip->get || !chip->direction_input)
@@ -314,7 +314,7 @@ int gpio_direction_output(unsigned gpio, int value)
314 314
315 spin_lock_irqsave(&gpio_lock, flags); 315 spin_lock_irqsave(&gpio_lock, flags);
316 316
317 if (gpio >= ARCH_NR_GPIOS) 317 if (!gpio_is_valid(gpio))
318 goto fail; 318 goto fail;
319 chip = desc->chip; 319 chip = desc->chip;
320 if (!chip || !chip->set || !chip->direction_output) 320 if (!chip || !chip->set || !chip->direction_output)
@@ -531,7 +531,7 @@ static int gpiolib_show(struct seq_file *s, void *unused)
531 531
532 /* REVISIT this isn't locked against gpio_chip removal ... */ 532 /* REVISIT this isn't locked against gpio_chip removal ... */
533 533
534 for (gpio = 0; gpio < ARCH_NR_GPIOS; gpio++) { 534 for (gpio = 0; gpio_is_valid(gpio); gpio++) {
535 if (chip == gpio_desc[gpio].chip) 535 if (chip == gpio_desc[gpio].chip)
536 continue; 536 continue;
537 chip = gpio_desc[gpio].chip; 537 chip = gpio_desc[gpio].chip;