Skip to contentSkip to conversation

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

PATCH In review Laxman Dewangan 2 participants 2 messages May 24, 2016 – May 30, 2016 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: core: Do not call get_direction in atomic context for sleeping gpio

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.

---
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(-)
drivers/gpio/gpiolib.c +9 -1
index d407f904..4d04171 100644
@@ -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);
Signature · 1 line
2.1.4
#1 lore raw
Quoted 5 lines · Laxman Dewangan

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.

Quoted 8 lines

Call get_direction() in non-atomic context from gpiochip_add() if GPIO HW driver is having sleepable callback i.e. chip->can_sleep = 1.

---
This is found when implementing the get_direction() of max77620 on 20160520 linux-next.

I chose to send a new patch just moving the lock release before the direction check. I just sent it with you as Reported-by.

Yours,
Linus Walleij