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 <mporter@linaro.org> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
Родитель
42d4a22d6b
Коммит
ff6e0b9c2f
|
@ -579,13 +579,12 @@ out:
|
||||||
static int gb_gpio_request(struct gpio_chip *chip, unsigned offset)
|
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);
|
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
||||||
u8 which;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
printk("passed check\n");
|
||||||
ret = gb_gpio_activate_operation(gb_gpio_controller, which);
|
ret = gb_gpio_activate_operation(gb_gpio_controller, (u8)offset);
|
||||||
if (ret)
|
if (ret)
|
||||||
; /* return ret; */
|
; /* return ret; */
|
||||||
return 0;
|
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)
|
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);
|
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
||||||
u8 which;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio) {
|
if (offset < 0 || offset >= chip->ngpio) {
|
||||||
pr_err("bad offset %u supplied (must be %u..%u)\n",
|
pr_err("bad offset %u supplied (must be 0..%u)\n",
|
||||||
offset, chip->base, chip->base + chip->ngpio - 1);
|
offset, chip->ngpio - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
which = (u8)(offset - chip->base);
|
ret = gb_gpio_deactivate_operation(gb_gpio_controller, (u8)offset);
|
||||||
ret = gb_gpio_deactivate_operation(gb_gpio_controller, which);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
; /* return ret; */
|
; /* return ret; */
|
||||||
}
|
}
|
||||||
|
@ -614,9 +611,9 @@ static int gb_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
|
||||||
u8 which;
|
u8 which;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
which = (u8)offset;
|
||||||
ret = gb_gpio_get_direction_operation(gb_gpio_controller, which);
|
ret = gb_gpio_get_direction_operation(gb_gpio_controller, which);
|
||||||
if (ret)
|
if (ret)
|
||||||
; /* return 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)
|
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);
|
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
||||||
u8 which;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
ret = gb_gpio_direction_in_operation(gb_gpio_controller, (u8)offset);
|
||||||
ret = gb_gpio_direction_in_operation(gb_gpio_controller, which);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
; /* return ret; */
|
; /* return ret; */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -642,13 +637,11 @@ static int gb_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
|
||||||
int value)
|
int value)
|
||||||
{
|
{
|
||||||
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
||||||
u8 which;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
ret = gb_gpio_direction_out_operation(gb_gpio_controller, (u8)offset, !!value);
|
||||||
ret = gb_gpio_direction_out_operation(gb_gpio_controller, which, !!value);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
; /* return ret; */
|
; /* return ret; */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -660,9 +653,9 @@ static int gb_gpio_get(struct gpio_chip *chip, unsigned offset)
|
||||||
u8 which;
|
u8 which;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
which = (u8)offset;
|
||||||
ret = gb_gpio_get_value_operation(gb_gpio_controller, which);
|
ret = gb_gpio_get_value_operation(gb_gpio_controller, which);
|
||||||
if (ret)
|
if (ret)
|
||||||
return 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)
|
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);
|
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
||||||
u8 which;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio) {
|
if (offset < 0 || offset >= chip->ngpio) {
|
||||||
pr_err("bad offset %u supplied (must be %u..%u)\n",
|
pr_err("bad offset %u supplied (must be 0..%u)\n",
|
||||||
offset, chip->base, chip->base + chip->ngpio - 1);
|
offset, chip->ngpio - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
which = (u8)(offset - chip->base);
|
ret = gb_gpio_set_value_operation(gb_gpio_controller, (u8)offset, !!value);
|
||||||
ret = gb_gpio_set_value_operation(gb_gpio_controller, which, !!value);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
; /* return 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);
|
struct gb_gpio_controller *gb_gpio_controller = gpio_chip_to_gb_gpio_controller(chip);
|
||||||
u16 usec;
|
u16 usec;
|
||||||
u8 which;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
|
||||||
if (debounce > (unsigned int)U16_MAX)
|
if (debounce > (unsigned int)U16_MAX)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
usec = (u8)debounce;
|
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)
|
if (ret)
|
||||||
; /* return 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)
|
static int gb_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
|
||||||
{
|
{
|
||||||
u8 which;
|
if (offset < 0 || offset >= chip->ngpio)
|
||||||
|
|
||||||
if (offset < chip->base || offset >= chip->base + chip->ngpio)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
which = (u8)(offset - chip->base);
|
|
||||||
|
|
||||||
return 0; /* XXX */
|
return 0; /* XXX */
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче