Skip to content

Commit

Permalink
gpiolib: fix off by one errors
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Trent Piepho authored and Linus Torvalds committed May 24, 2008
1 parent 1d1c1d9 commit bff5fda
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -207,7 +207,7 @@ int gpiochip_add(struct gpio_chip *chip)
/* 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;
}
Expand Down

0 comments on commit bff5fda

Please sign in to comment.