mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laxman Dewangan <ldewangan@nvidia.com>
To: <linus.walleij@linaro.org>, <gnurou@gmail.com>
Cc: <linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Laxman Dewangan" <ldewangan@nvidia.com>
Subject: [PATCH] gpio: core: Do not call get_direction in atomic context for sleeping gpio
Date: Tue, 24 May 2016 18:48:22 +0530	[thread overview]
Message-ID: <1464095903-29145-1-git-send-email-ldewangan@nvidia.com> (raw)

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 <ldewangan@nvidia.com>

---
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);
-- 
2.1.4

             reply	other threads:[~2016-05-24 13:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24 13:18 Laxman Dewangan [this message]
2016-05-30 15:15 ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464095903-29145-1-git-send-email-ldewangan@nvidia.com \
    --to=ldewangan@nvidia.com \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®