From: Matt Porter Date: Mon, 20 Oct 2014 10:39:45 +0000 (-0400) Subject: greybus: gpio-gb: fix offset error checking and usage X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1994 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ff6e0b9c2f05e9f3a06e84af5af2fa8a2c8098f8;p=karo-tx-linux.git greybus: gpio-gb: fix offset error checking and usage Offset (or hwgpio num) is the offset within a gpiochip, not the unique gpio namespace number. Adjust the error checking and use of offset in our operation calls to fix this. Signed-off-by: Matt Porter Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/gpio-gb.c b/drivers/staging/greybus/gpio-gb.c index f3fb0b67b2d4..32bf45ff7e8b 100644 --- a/drivers/staging/greybus/gpio-gb.c +++ b/drivers/staging/greybus/gpio-gb.c @@ -579,13 +579,12 @@ out: static int gb_gpio_request(struct gpio_chip *chip, unsigned offset) { struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip); - u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); - ret = gb_gpio_activate_operation(gb_gpio_controller, which); + printk("passed check\n"); + ret = gb_gpio_activate_operation(gb_gpio_controller, (u8)offset); if (ret) ; /* return ret; */ return 0; @@ -594,16 +593,14 @@ static int gb_gpio_request(struct gpio_chip *chip, unsigned offset) static void gb_gpio_free(struct gpio_chip *chip, unsigned offset) { struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip); - u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) { - pr_err("bad offset %u supplied (must be %u..%u)\n", - offset, chip->base, chip->base + chip->ngpio - 1); + if (offset < 0 || offset >= chip->ngpio) { + pr_err("bad offset %u supplied (must be 0..%u)\n", + offset, chip->ngpio - 1); return; } - which = (u8)(offset - chip->base); - ret = gb_gpio_deactivate_operation(gb_gpio_controller, which); + ret = gb_gpio_deactivate_operation(gb_gpio_controller, (u8)offset); if (ret) ; /* return ret; */ } @@ -614,9 +611,9 @@ static int gb_gpio_get_direction(struct gpio_chip *chip, unsigned offset) u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); + which = (u8)offset; ret = gb_gpio_get_direction_operation(gb_gpio_controller, which); if (ret) ; /* return ret; */ @@ -626,13 +623,11 @@ static int gb_gpio_get_direction(struct gpio_chip *chip, unsigned offset) static int gb_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip); - u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); - ret = gb_gpio_direction_in_operation(gb_gpio_controller, which); + ret = gb_gpio_direction_in_operation(gb_gpio_controller, (u8)offset); if (ret) ; /* return ret; */ return 0; @@ -642,13 +637,11 @@ static int gb_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip); - u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); - ret = gb_gpio_direction_out_operation(gb_gpio_controller, which, !!value); + ret = gb_gpio_direction_out_operation(gb_gpio_controller, (u8)offset, !!value); if (ret) ; /* return ret; */ return 0; @@ -660,9 +653,9 @@ static int gb_gpio_get(struct gpio_chip *chip, unsigned offset) u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); + which = (u8)offset; ret = gb_gpio_get_value_operation(gb_gpio_controller, which); if (ret) return ret; @@ -672,16 +665,14 @@ static int gb_gpio_get(struct gpio_chip *chip, unsigned offset) static void gb_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip); - u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) { - pr_err("bad offset %u supplied (must be %u..%u)\n", - offset, chip->base, chip->base + chip->ngpio - 1); + if (offset < 0 || offset >= chip->ngpio) { + pr_err("bad offset %u supplied (must be 0..%u)\n", + offset, chip->ngpio - 1); return; } - which = (u8)(offset - chip->base); - ret = gb_gpio_set_value_operation(gb_gpio_controller, which, !!value); + ret = gb_gpio_set_value_operation(gb_gpio_controller, (u8)offset, !!value); if (ret) ; /* return ret; */ } @@ -691,16 +682,14 @@ static int gb_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, { struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip); u16 usec; - u8 which; int ret; - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); if (debounce > (unsigned int)U16_MAX) return -EINVAL; usec = (u8)debounce; - ret = gb_gpio_set_debounce_operation(gb_gpio_controller, which, usec); + ret = gb_gpio_set_debounce_operation(gb_gpio_controller, (u8)offset, usec); if (ret) ; /* return ret; */ @@ -709,11 +698,8 @@ static int gb_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, static int gb_gpio_to_irq(struct gpio_chip *chip, unsigned offset) { - u8 which; - - if (offset < chip->base || offset >= chip->base + chip->ngpio) + if (offset < 0 || offset >= chip->ngpio) return -EINVAL; - which = (u8)(offset - chip->base); return 0; /* XXX */ }