Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH] gpiolib: Fix off by one errors

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


xyzzy at speakeasy

May 20, 2008, 10:58 AM

Post #1 of 2 (236 views)
Permalink
[PATCH] 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: Trent Piepho <xyzzy [at] speakeasy>
---
drivers/gpio/gpiolib.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 7f138c6..beaf6b3 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
}
--
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


david-b at pacbell

May 20, 2008, 11:23 AM

Post #2 of 2 (225 views)
Permalink
Re: [PATCH] gpiolib: Fix off by one errors [In reply to]

On Tuesday 20 May 2008, Trent Piepho wrote:
> 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 [at] speakeasy>

Acked-by: David Brownell <dbrownell [at] users>

... should make it into 2.6.26-final, but this is evidently
not critical at this point or we'd have had complaints already!


> ---
> drivers/gpio/gpiolib.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 7f138c6..beaf6b3 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -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;
> }
> --
> 1.5.4.1
>


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.