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: 9214327 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 49C816048B for ; Tue, 5 Jul 2016 14:15:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 386131FFCA for ; Tue, 5 Jul 2016 14:15:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A8A61FFD7; Tue, 5 Jul 2016 14:15:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A56E61FFCA for ; Tue, 5 Jul 2016 14:15:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754637AbcGEOPd (ORCPT ); Tue, 5 Jul 2016 10:15:33 -0400 Received: from mail-lf0-f49.google.com ([209.85.215.49]:34253 "EHLO mail-lf0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751762AbcGEOPd (ORCPT ); Tue, 5 Jul 2016 10:15:33 -0400 Received: by mail-lf0-f49.google.com with SMTP id h129so135796219lfh.1 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=B9pKI/XxTa/MQaUtPm7U6h81mEPFQBmOkQGIfBV0aZNuy1f4aau0E+QJJP9LE4CvOZ xGB/d3XvW2sI9TwJIaBqlltKzHFiW5izRB5S4WIZe+GegkGc/LB+uYfAxYF+85x8Tt3H SRCljBRvaLuIeyq1x8OYYTZLBKxK3FwtdMJqpgYAvUVwPmFJpiZw22W0iSoXWuuYeGnz Ng45vVCN7CPKXj/dLxb0+jLyd+TmVwK+9IC09WN2jPRWfiI6P4z+lF8X/WEI2F8jLqmR lnDBgoJZ3P0e9ftCE5lUW+DleUWA/aE/v3l0oGxaLV+ouB5MSsh8fmScx9yH+NGlMKJI d12w== X-Gm-Message-State: ALyK8tJu94D3GHixa5t90Jww3gY5IrAeidh9o87Npaun1KSnehjVSdlpoCOvBM9j3cVzKp6J 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-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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); }