From patchwork Sat Nov 12 14:01:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 81921 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp250192qge; Sat, 12 Nov 2016 06:01:18 -0800 (PST) X-Received: by 10.36.127.10 with SMTP id r10mr1395785itc.14.1478959278384; Sat, 12 Nov 2016 06:01:18 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yz10si12793534pab.158.2016.11.12.06.01.18; Sat, 12 Nov 2016 06:01:18 -0800 (PST) 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 S965865AbcKLOBR (ORCPT + 4 others); Sat, 12 Nov 2016 09:01:17 -0500 Received: from mail-lf0-f54.google.com ([209.85.215.54]:36379 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965294AbcKLOBQ (ORCPT ); Sat, 12 Nov 2016 09:01:16 -0500 Received: by mail-lf0-f54.google.com with SMTP id t196so30466302lff.3 for ; Sat, 12 Nov 2016 06:01:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=9+fRljLplcIj3UEEPM3KQJ5JYlsuPkNjRjbZoSawuL8=; b=cTbeKYF0jJmM8K/mreayohpf1OcUxV7LWKT2jWcZ1gFvgMN+917pxrSlZFEraEWVfx OyuxR886mD6UVR8stut2zx8796iE56nHiF5vKCPNoJmFj9viGqN7G/1NuwDA0HsK9sTy CVaekOToz3sO/ouNrkzvg9r3nt/P60ftzN374= 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=9+fRljLplcIj3UEEPM3KQJ5JYlsuPkNjRjbZoSawuL8=; b=fL6Najrsf9ubsaFWGHlFGQ8Bakp1GtRIilBkxHQh1L9KQGMjQkYS+bnmXV803j3oHq NThZUJ2zbWgnKNC8701nhnb/fxjBVrJi7sebmw1ct+Q+AatBCzUs5fU6Qj6uopefQbSj 04/Nb/ESx7oPLMLTZDdDbfNYlLsU8IHugbC52YdBP2vNbx6u4Hh3Vv7uA9kO4morgvZD Fvr18etLU4YWdf9XT40gBqlt0MIDj4RP4WBzqggoBUllF35y8fuqkoNar+iBnnygbKQE kxMUKowj6EvzJ7cNpfoCLxfRetoZWc2tzzNfKDbTnzmPKpQ7xt+k/lFP6bDgBHCVsDSN S+4Q== X-Gm-Message-State: ABUngvdR1TfXl4M/+RCv+cYuowZnEDzu4rt/cwFeIOykxLEu0BqZA4+n8vwTlM9K3M42r8YE X-Received: by 10.25.150.210 with SMTP id y201mr4415979lfd.58.1478959274107; Sat, 12 Nov 2016 06:01:14 -0800 (PST) Received: from fecusa.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id 65sm3261647ljb.23.2016.11.12.06.01.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Nov 2016 06:01:13 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij , stable@vger.kernel.org, Patrice Chotard Subject: [PATCH] gpio: do not double-check direction on sleeping chips Date: Sat, 12 Nov 2016 15:01:09 +0100 Message-Id: <1478959269-18531-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org When locking a GPIO line as IRQ, we go to lengths to double-check that the line is really set as input before marking it as used for IRQ. This is not good on GPIO chips that can sleep, because this function is called in IRQ-safe context. Just skip this if it can't be checked quickly. Currently this happens on sleeping expanders such as STMPE or TC3589x: BUG: scheduling while atomic: swapper/1/0x00000002 Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 4.9.0-rc1+ #38 Hardware name: Nomadik STn8815 [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (__schedule_bug+0x54/0x80) [] (__schedule_bug) from [] (__schedule+0x3a0/0x460) [] (__schedule) from [] (schedule+0x54/0xb8) (...) This patch fixes that problem and relies on the direction read from the chip when it was added. Cc: stable@vger.kernel.org Fixes: 9c10280d85c1 ("gpio: flush direction status in gpiochip_lock_as_irq()") Cc: Patrice Chotard Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.7.4 -- 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 f0fc3a0d37c8..4575c2c5f293 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2664,8 +2664,11 @@ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) if (IS_ERR(desc)) return PTR_ERR(desc); - /* Flush direction if something changed behind our back */ - if (chip->get_direction) { + /* + * If it's fast: flush the direction setting if something changed + * behind our back + */ + if (!chip->can_sleep && chip->get_direction) { int dir = chip->get_direction(chip, offset); if (dir)