]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpio: tegra: do not call pinctrl for GPIO direction
authorRunyu Xiao <runyu.xiao@seu.edu.cn>
Fri, 19 Jun 2026 15:24:39 +0000 (23:24 +0800)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Tue, 23 Jun 2026 08:44:12 +0000 (10:44 +0200)
tegra_gpio_direction_input() and tegra_gpio_direction_output() already
program the GPIO controller direction registers directly. The additional
pinctrl_gpio_direction_input/output() calls do not add a Tegra pinctrl
operation, because the Tegra pinmux ops provide GPIO request/free
handling but no gpio_set_direction hook.

The extra call still enters the pinctrl core and takes pctldev->mutex.
Shared GPIO users can call the direction path while holding their
per-line spinlock, so this otherwise redundant pinctrl direction call can
sleep in an atomic context.

This was found by our static analysis tool and then confirmed by manual
review of tegra_gpio_probe(), the Tegra GPIO direction callbacks and the
Tegra pinctrl ops. The reviewed path has a default non-sleeping
struct gpio_chip while the direction callback still enters the pinctrl
mutex path.

A directed runtime validation kept the same non-sleeping chip registration
and drove:

  gpio_shared_proxy_direction_output()
  gpiod_direction_output_raw_commit()
  tegra_gpio_direction_output()
  pinctrl_gpio_direction_output()

Lockdep reported a sleep-in-atomic warning with the shared GPIO spinlock
held and pinctrl_get_device_gpio_range() plus tegra_gpio_direction_output()
on the stack.

Do not mark the whole chip as can_sleep to paper over this: can_sleep
describes whether get()/set() may sleep, and Tegra value access is MMIO.
Remove the redundant pinctrl direction calls and keep pinctrl involvement
in the existing request/free path.

Fixes: 11da90541283 ("gpio: tegra: Fix offset of pinctrl calls")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
Link: https://patch.msgid.link/20260619152439.1239561-1-runyu.xiao@seu.edu.cn
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpio-tegra.c

index df06b56a2ade8543f4285665be66187259b3f88a..fa6c8ee92093ceb2d81863a6013ada07517b661a 100644 (file)
@@ -172,18 +172,11 @@ static int tegra_gpio_direction_input(struct gpio_chip *chip,
                                      unsigned int offset)
 {
        struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
-       int ret;
 
        tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, offset), offset, 0);
        tegra_gpio_enable(tgi, offset);
 
-       ret = pinctrl_gpio_direction_input(chip, offset);
-       if (ret < 0)
-               dev_err(tgi->dev,
-                       "Failed to set pinctrl input direction of GPIO %d: %d",
-                        chip->base + offset, ret);
-
-       return ret;
+       return 0;
 }
 
 static int tegra_gpio_direction_output(struct gpio_chip *chip,
@@ -191,19 +184,12 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip,
                                       int value)
 {
        struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
-       int ret;
 
        tegra_gpio_set(chip, offset, value);
        tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, offset), offset, 1);
        tegra_gpio_enable(tgi, offset);
 
-       ret = pinctrl_gpio_direction_output(chip, offset);
-       if (ret < 0)
-               dev_err(tgi->dev,
-                       "Failed to set pinctrl output direction of GPIO %d: %d",
-                        chip->base + offset, ret);
-
-       return ret;
+       return 0;
 }
 
 static int tegra_gpio_get_direction(struct gpio_chip *chip,