gpio: be more careful when forcing IRQ line to input

Message ID 1467728126-26131-1-git-send-email-linus.walleij@linaro.org
State New
Headers show

Commit Message

Linus Walleij July 5, 2016, 2:15 p.m.
We need to convince the IRQ line to become input unless there
is a reason for. Also fixes up reference counting on the
errorpath.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linux-Renesas <linux-renesas-soc@vger.kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
Geert: does this solve the problem you saw in the RCAR
in "gpio: convince line to become input in irq helper"?
---
 drivers/gpio/gpiolib.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

-- 
2.4.11

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Linus Walleij July 6, 2016, 8:34 a.m. | #1
On Tue, Jul 5, 2016 at 7:36 PM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> Hello.

>

> On 07/05/2016 05:15 PM, Linus Walleij wrote:

>

>> We need to convince the IRQ line to become input unless there

>> is a reason for. Also fixes up reference counting on the

>

>

>    For what?


Module refcount in its kobject. I'll update the commitlog.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch hide | download patch | download mbox

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 69efe278f74d..e3e3cc19b8b0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1505,25 +1505,32 @@  static const struct irq_domain_ops gpiochip_domain_ops = {
 static int gpiochip_irq_reqres(struct irq_data *d)
 {
 	struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
+	struct gpio_desc *desc;
 
 	if (!try_module_get(chip->gpiodev->owner))
 		return -ENODEV;
 
+	/* Look up the corresponding descriptor */
+	desc = gpiochip_get_desc(chip, d->hwirq);
+	if (IS_ERR(desc)) {
+		module_put(chip->gpiodev->owner);
+		return PTR_ERR(desc);
+	}
+
 	/*
-	 * If it is possible to switch this GPIO to an input
-	 * this is a good time to do it.
+	 * If the pin is flagged as output and it is possible to
+	 * switch this GPIO to an input this is a good time to
+	 * do it.
 	 */
-	if (chip->direction_input) {
-		struct gpio_desc *desc;
+	if (test_bit(FLAG_IS_OUT, &desc->flags) &&
+	    chip->direction_input) {
 		int ret;
 
-		desc = gpiochip_get_desc(chip, d->hwirq);
-		if (IS_ERR(desc))
-			return PTR_ERR(desc);
-
 	        ret = chip->direction_input(chip, d->hwirq);
-		if (ret)
+		if (ret) {
+			module_put(chip->gpiodev->owner);
 			return ret;
+		}
 
 		clear_bit(FLAG_IS_OUT, &desc->flags);
 	}