diff mbox series

[1/1] mmc: slot-gpio: Allow non-sleeping GPIO ro

Message ID 20240206083912.2543142-1-alexander.stein@ew.tq-group.com
State New
Headers show
Series [1/1] mmc: slot-gpio: Allow non-sleeping GPIO ro | expand

Commit Message

Alexander Stein Feb. 6, 2024, 8:39 a.m. UTC
This change uses the appropriate _cansleep or non-sleeping API for
reading GPIO read-only state. This allows users with GPIOs that
never sleepbeing called in atomic context.

Implement the same mechanism as in commit 52af318c93e97 ("mmc: Allow
non-sleeping GPIO cd").

Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
With commit 5d5dfc50e5689 ("gpiolib: remove extra_checks") thw following error
is showing on my imx8qxp-tqma8xqp-mba8xx.dts platform:
> BUG: sleeping function called from invalid context at drivers/gpio/gpiolib.c:3740

The reason is that mmc_gpio_get_ro() is called from within atomic context from
sdhci_check_ro(), which uses spin_lock_irqsave().

The problem was always there, so I assume I didn't actually deadlock cause
nobody was using SD card with a sleepable read-only GPIO.

 drivers/mmc/core/slot-gpio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Ulf Hansson Feb. 6, 2024, 11:41 a.m. UTC | #1
On Tue, 6 Feb 2024 at 09:39, Alexander Stein
<alexander.stein@ew.tq-group.com> wrote:
>
> This change uses the appropriate _cansleep or non-sleeping API for
> reading GPIO read-only state. This allows users with GPIOs that
> never sleepbeing called in atomic context.
>
> Implement the same mechanism as in commit 52af318c93e97 ("mmc: Allow
> non-sleeping GPIO cd").
>
> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>

Applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe


> ---
> With commit 5d5dfc50e5689 ("gpiolib: remove extra_checks") thw following error
> is showing on my imx8qxp-tqma8xqp-mba8xx.dts platform:
> > BUG: sleeping function called from invalid context at drivers/gpio/gpiolib.c:3740
>
> The reason is that mmc_gpio_get_ro() is called from within atomic context from
> sdhci_check_ro(), which uses spin_lock_irqsave().
>
> The problem was always there, so I assume I didn't actually deadlock cause
> nobody was using SD card with a sleepable read-only GPIO.
>
>  drivers/mmc/core/slot-gpio.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
> index 2a2d949a9344e..39f45c2b6de8a 100644
> --- a/drivers/mmc/core/slot-gpio.c
> +++ b/drivers/mmc/core/slot-gpio.c
> @@ -75,11 +75,15 @@ EXPORT_SYMBOL(mmc_gpio_set_cd_irq);
>  int mmc_gpio_get_ro(struct mmc_host *host)
>  {
>         struct mmc_gpio *ctx = host->slot.handler_priv;
> +       int cansleep;
>
>         if (!ctx || !ctx->ro_gpio)
>                 return -ENOSYS;
>
> -       return gpiod_get_value_cansleep(ctx->ro_gpio);
> +       cansleep = gpiod_cansleep(ctx->ro_gpio);
> +       return cansleep ?
> +               gpiod_get_value_cansleep(ctx->ro_gpio) :
> +               gpiod_get_value(ctx->ro_gpio);
>  }
>  EXPORT_SYMBOL(mmc_gpio_get_ro);
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 2a2d949a9344e..39f45c2b6de8a 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -75,11 +75,15 @@  EXPORT_SYMBOL(mmc_gpio_set_cd_irq);
 int mmc_gpio_get_ro(struct mmc_host *host)
 {
 	struct mmc_gpio *ctx = host->slot.handler_priv;
+	int cansleep;
 
 	if (!ctx || !ctx->ro_gpio)
 		return -ENOSYS;
 
-	return gpiod_get_value_cansleep(ctx->ro_gpio);
+	cansleep = gpiod_cansleep(ctx->ro_gpio);
+	return cansleep ?
+		gpiod_get_value_cansleep(ctx->ro_gpio) :
+		gpiod_get_value(ctx->ro_gpio);
 }
 EXPORT_SYMBOL(mmc_gpio_get_ro);