gpio: Fix crash in gpiod_set_debounce()
PATCH 1/2 gpio: Fix crash in gpiod_set_debounce()
Return an error if neither the ->set() nor the ->set_debounce() function is implemented by the chip. Furthermore move locking further down so the lock doesn't have to be unlocked on error. This is safe to do because at this point the lock doesn't protect anything.
---
Linus,
Feel free to squash this into the commit that introduced these:
fc9bbfb: gpio: improve error path in gpiolib
Thierry
drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +3 -2
@@ -1777,14 +1777,15 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)return -EINVAL ; } -spin_lock_irqsave (&gpio_lock, flags); - chip = desc->chip;if (!chip->set || !chip->set_debounce) {pr_warn ("%s: missing set() or set_debounce() operations\n" , __func__); +return -EIO ; } +spin_lock_irqsave (&gpio_lock, flags); + status =gpio_ensure_requested (desc);if (status <0 ) goto fail;
Signature · 1 line
1.8.4
PATCH 2/2 gpio: Use proper indentation
Indentation should be done using tabs, not a combination of tabs and spaces.
---
Linus,
Feel free to squash this into the commit that introduced these:
fc9bbfb: gpio: improve error path in gpiolib
Thierry
drivers/gpio/gpiolib.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +6 -6
@@ -1636,8 +1636,8 @@ static int gpiod_direction_input(struct gpio_desc *desc) chip = desc->chip;if (!chip->get || !chip->direction_input) { -pr_warn ("%s: missing get() or direction_input() operations\n" , - __func__); +pr_warn ("%s: missing get() or direction_input() operations\n" , + __func__);return -EIO ; }
@@ -1709,8 +1709,8 @@ static int gpiod_direction_output(struct gpio_desc *desc, int value) chip = desc->chip;if (!chip->set || !chip->direction_output) { -pr_warn ("%s: missing set() or direction_output() operations\n" , - __func__); +pr_warn ("%s: missing set() or direction_output() operations\n" , + __func__);return -EIO ; }
@@ -1779,8 +1779,8 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) chip = desc->chip;if (!chip->set || !chip->set_debounce) { -pr_warn ("%s: missing set() or set_debounce() operations\n" , - __func__); +pr_warn ("%s: missing set() or set_debounce() operations\n" , + __func__);return -EIO ; }
Signature · 1 line
1.8.4
Re: [PATCH 2/2] gpio: Use proper indentation
Quoted 10 lines · Thierry Reding
Indentation should be done using tabs, not a combination of tabs and spaces.
Signed-off-by Thierry Reding <[email protected]>---
Linus,Feel free to squash this into the commit that introduced these:
fc9bbfb: gpio: improve error path in gpiolib
This part I actually fixed up properly yesterday, but thanks anyway.
Thanks,
Linus Walleij
Re: [PATCH 2/2] gpio: Use proper indentation
Quoted 10 lines · Linus Walleij
Quoted 7 lines · Thierry Reding
Indentation should be done using tabs, not a combination of tabs and spaces.
Signed-off-by Thierry Reding <[email protected]>---
Linus,
Quoted 5 lines
Quoted 3 lines
Feel free to squash this into the commit that introduced these:
fc9bbfb: gpio: improve error path in gpiolib
This part I actually fixed up properly yesterday, but thanks anyway.
Yes you did. I was impatient and couldn't wait for today's linux-next to show up. Sorry for the noise.
Thierry
Quoted 5 lines · Thierry Reding
Return an error if neither the ->set() nor the ->set_debounce() function is implemented by the chip. Furthermore move locking further down so the lock doesn't have to be unlocked on error. This is safe to do because at this point the lock doesn't protect anything.
Quoted 7 lines
Signed-off-by Thierry Reding <[email protected]>---
Linus,Feel free to squash this into the commit that introduced these:
fc9bbfb: gpio: improve error path in gpiolib
Hm I fixed part of this bug yesterday, but screwed up and left the dangling spinlock in there, what is wrong with me :-(
Anyway, fixed it _finally_ now, thanks to you.
Yours,
Linus Walleij
[+Olof who had mentioned lock recursion BUG in -next]
Quoted 12 lines · Linus Walleij
Quoted 9 lines · Thierry Reding
Return an error if neither the ->set() nor the ->set_debounce() function is implemented by the chip. Furthermore move locking further down so the lock doesn't have to be unlocked on error. This is safe to do because at this point the lock doesn't protect anything.
Signed-off-by Thierry Reding <[email protected]>---
Linus,
Quoted 8 lines
Quoted 3 lines
Feel free to squash this into the commit that introduced these:
fc9bbfb: gpio: improve error path in gpiolib
Hm I fixed part of this bug yesterday, but screwed up and left the dangling spinlock in there, what is wrong with me :-(
Anyway, fixed it _finally_ now, thanks to you.
Exiting without unlocking was causing a lock recurision lockup in next-20130903 on exynos5/arndale. I just verified that moving the spinlock down as propsed here fixes the problem in -next.
Thanks,
Kevin
drivers/gpio/gpiolib.c static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) · line 1785
Quoted 13 lines · Thierry Reding
Return an error if neither the ->set() nor the ->set_debounce() function is implemented by the chip. Furthermore move locking further down so the lock doesn't have to be unlocked on error. This is safe to do because at this point the lock doesn't protect anything.
drivers/gpio/gpiolib.c +1
-0chip = desc->chip;if (!chip->set || !chip->set_debounce) {pr_warn ("%s: missing set() or set_debounce() operations\n" , __func__); +return -EIO ; }
BTW, I'm not sure that error-path should pr_warn(). For example, if this error-patch is taken due to a call from gpio_keys.c:gpio_keys_setup_key(), then a timer will be used for debounce instead, which is all perfectly valid, and probably not something that should be spewed to the kernel log.
Quoted 7 lines · Stephen Warren
Quoted 6 lines
chip = desc->chip; if (!chip->set || !chip->set_debounce) { pr_warn("%s: missing set() or set_debounce() operations\n", __func__); + return -EIO; }
Quoted 5 lines
BTW, I'm not sure that error-path should
pr_warn(). For example, if this error-patch is taken due to a call from gpio_keys.c:gpio_keys_setup_key(), then a timer will be used for debounce instead, which is all perfectly valid, and probably not something that should be spewed to the kernel log.
You're right, I wasn't aware of the fallback use-case, so I've proposed a separate patch fixing this.
Yours,
Linus Walleij