Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1406186

[PATCH] gpio: core: Do not call get_direction in atomic context for sleeping gpio

From Laxman Dewangan <ldewangan@nvidia.com>
Newsgroups linux.kernel
Subject [PATCH] gpio: core: Do not call get_direction in atomic context for sleeping gpio
Date 2016-05-24 15:40 +0200
Message-ID <rCkIX-3Ps-79@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View 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

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] gpio: core: Do not call get_direction in atomic context for sleeping gpio Laxman Dewangan <ldewangan@nvidia.com> - 2016-05-24 15:40 +0200
  Re: [PATCH] gpio: core: Do not call get_direction in atomic context  for sleeping gpio Linus Walleij <linus.walleij@linaro.org> - 2016-05-30 17:20 +0200

csiph-web