]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
gpiolib: fix off by one errors
authorTrent Piepho <xyzzy@speakeasy.org>
Fri, 23 May 2008 20:04:44 +0000 (13:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 24 May 2008 16:56:11 +0000 (09:56 -0700)
The last gpio belonging to a chip is chip->base + chip->ngpios - 1.  Some
places in the code, but not all, forgot the critical minus one.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Acked-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>
drivers/gpio/gpiolib.c

index 7f138c6195ff38ceba44bf14dea45a83705c47d4..beaf6b3a37dcefb0b2c1d8c8f79b7db2713dba45 100644 (file)
@@ -127,7 +127,7 @@ int __init gpiochip_reserve(int start, int ngpio)
        unsigned long flags;
        int i;
 
-       if (!gpio_is_valid(start) || !gpio_is_valid(start + ngpio))
+       if (!gpio_is_valid(start) || !gpio_is_valid(start + ngpio - 1))
                return -EINVAL;
 
        spin_lock_irqsave(&gpio_lock, flags);
@@ -170,7 +170,7 @@ int gpiochip_add(struct gpio_chip *chip)
        unsigned        id;
        int             base = chip->base;
 
-       if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio))
+       if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1))
                        && base >= 0) {
                status = -EINVAL;
                goto fail;
@@ -207,7 +207,7 @@ fail:
        /* failures here can mean systems won't boot... */
        if (status)
                pr_err("gpiochip_add: gpios %d..%d (%s) not registered\n",
-                       chip->base, chip->base + chip->ngpio,
+                       chip->base, chip->base + chip->ngpio - 1,
                        chip->label ? : "generic");
        return status;
 }