From patchwork Tue Jul 5 14:15:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 71392 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp334734qgy; Tue, 5 Jul 2016 07:15:34 -0700 (PDT) X-Received: by 10.66.138.43 with SMTP id qn11mr32357735pab.1.1467728134850; Tue, 05 Jul 2016 07:15:34 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 198si4314874pfx.22.2016.07.05.07.15.34; Tue, 05 Jul 2016 07:15:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751762AbcGEOPd (ORCPT + 4 others); Tue, 5 Jul 2016 10:15:33 -0400 Received: from mail-lf0-f51.google.com ([209.85.215.51]:36615 "EHLO mail-lf0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754596AbcGEOPd (ORCPT ); Tue, 5 Jul 2016 10:15:33 -0400 Received: by mail-lf0-f51.google.com with SMTP id q132so135663558lfe.3 for ; Tue, 05 Jul 2016 07:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=q7bcBrif7GORPeDqMSPp4GzZfocd5beW2R0ZLM1Xh8w=; b=dKenODYXCK9/6oPOvGK3b6FTUH4iamNThQWmwgRSAtc3PkxMqWc+d+sCGvtVrmwMOV IPqyBXsVtFV4GkkskPzVMN8fEyh7RxckHWp6DcICBBRo69/gp33c+dp0XnCDUsj5XGbp ToPmhZJ17RHn2NT9Bdq8B4QOYajfOl9HdKTXY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=q7bcBrif7GORPeDqMSPp4GzZfocd5beW2R0ZLM1Xh8w=; b=mFwKqGlSrbgre9yeiaa2qSUrCQ2GTrRwmdP6uDDeG5GQEN/ShC3rCx8wIuNfxPfy2p NkvBbi1zi4pP4/isqqSjiDUYA7qy36q9AXJPQREPO6xT6uOEJMRSxCdBK/Y6mRVa1MIR U8cqZIPbyB4AI/1IOwOLIE/b7z2G4JYSBt+WdKMLes5665t/mvKzWEKgElZHDr49dRGH /HZAtGdbhxa198QS0t8HwI/ZpdRFg0xSco7O64cTdCo5qNudjZNN0fnI/VZv/xfOH1AX CdiZMk+SzzlofbolbGa4p8KS4LJae0BYQ5U0ripd/TH1QzrZe90eidPmLS0m4lJ7QuW2 6zxg== X-Gm-Message-State: ALyK8tKMCPQ0f5lqlzMOs6NeuRrdQqrsyxg1pZo9gZwD9ZQhNqdW4eAL4MhvIKI+qxt/ZuU+ X-Received: by 10.25.160.135 with SMTP id j129mr3581266lfe.231.1467728131288; Tue, 05 Jul 2016 07:15:31 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u21sm299134lja.16.2016.07.05.07.15.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jul 2016 07:15:29 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij , Linux-Renesas Subject: [PATCH] gpio: be more careful when forcing IRQ line to input Date: Tue, 5 Jul 2016 16:15:26 +0200 Message-Id: <1467728126-26131-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 Cc: Linux-Renesas Signed-off-by: Linus Walleij --- 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 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); }