From patchwork Tue May 24 13:18:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laxman Dewangan X-Patchwork-Id: 625635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rDbrZ189dz9t7s for ; Tue, 24 May 2016 23:30:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754036AbcEXNag (ORCPT ); Tue, 24 May 2016 09:30:36 -0400 Received: from nat-hk.nvidia.com ([203.18.50.4]:29982 "EHLO hkmmgate102.nvidia.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753075AbcEXNag (ORCPT ); Tue, 24 May 2016 09:30:36 -0400 Received: from hkpgpgate101.nvidia.com (Not Verified[10.18.92.9]) by hkmmgate102.nvidia.com id ; Tue, 24 May 2016 21:31:18 +0800 Received: from HKMAIL104.nvidia.com ([10.18.67.137]) by hkpgpgate101.nvidia.com (PGP Universal service); Tue, 24 May 2016 06:30:33 -0700 X-PGP-Universal: processed; by hkpgpgate101.nvidia.com on Tue, 24 May 2016 06:30:33 -0700 Received: from DRBGMAIL101.nvidia.com (10.18.16.20) by HKMAIL104.nvidia.com (10.18.16.13) with Microsoft SMTP Server (TLS) id 15.0.1130.7; Tue, 24 May 2016 13:30:31 +0000 Received: from HQMAIL103.nvidia.com (172.20.187.11) by DRBGMAIL101.nvidia.com (10.18.16.20) with Microsoft SMTP Server (TLS) id 15.0.1130.7; Tue, 24 May 2016 13:30:29 +0000 Received: from ldewanganubuntu-System-Product-Name.nvidia.com (172.20.13.39) by HQMAIL103.nvidia.com (172.20.187.11) with Microsoft SMTP Server id 15.0.1130.7 via Frontend Transport; Tue, 24 May 2016 13:30:26 +0000 From: Laxman Dewangan To: , CC: , , "Laxman Dewangan" Subject: [PATCH] gpio: core: Do not call get_direction in atomic context for sleeping gpio Date: Tue, 24 May 2016 18:48:22 +0530 Message-ID: <1464095903-29145-1-git-send-email-ldewangan@nvidia.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org When adding the gpiochip, the GPIO HW drivers' callback get_direction() get called in atomic context. Some of the GPIO HW drivers can sleep when accessing the register and hence it can create the sleeping call in atomic context. Call get_direction() in non-atomic context from gpiochip_add() if GPIO HW driver is having sleepable callback i.e. chip->can_sleep = 1. Signed-off-by: Laxman Dewangan --- This is found when implementing the get_direction() of max77620 on 20160520 linux-next. drivers/gpio/gpiolib.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d407f904..4d04171 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -636,7 +636,15 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) * If we have .get_direction, set up the initial * direction flag from the hardware. */ - int dir = chip->get_direction(chip, i); + int dir; + + if (chip->can_sleep) + spin_unlock_irqrestore(&gpio_lock, flags); + + dir = chip->get_direction(chip, i); + + if (chip->can_sleep) + spin_lock_irqsave(&gpio_lock, flags); if (!dir) set_bit(FLAG_IS_OUT, &desc->flags);