Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bff5fda9 authored by Trent Piepho's avatar Trent Piepho Committed by Linus Torvalds
Browse files

gpiolib: fix off by one errors



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: default avatarTrent Piepho <xyzzy@speakeasy.org>
Acked-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1d1c1d9b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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 @@ 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;
}