All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mmc: tmio: Further fixup runtime PM management at remove
@ 2020-05-19 15:24 Ulf Hansson
  2020-05-20 11:35 ` Ulf Hansson
  2020-05-20 14:30 ` Geert Uytterhoeven
  0 siblings, 2 replies; 12+ messages in thread
From: Ulf Hansson @ 2020-05-19 15:24 UTC (permalink / raw)
  To: linux-mmc, Ulf Hansson, Masahiro Yamada, Wolfram Sang,
	Geert Uytterhoeven
  Cc: Ulrich Hecht, Simon Horman, Niklas Soderlund, Geert Uytterhoeven

Before calling tmio_mmc_host_probe(), the caller is required to enable
clocks for its device, as to make it accessible when reading/writing
registers during probe.

Therefore, the responsibility to disable these clocks, in the error path of
->probe() and during ->remove(), is better managed outside
tmio_mmc_host_remove(). As a matter of fact, callers of
tmio_mmc_host_remove() already expects this to be the behaviour.

However, there's a problem with tmio_mmc_host_remove() when the Kconfig
option, CONFIG_PM, is set. More precisely, tmio_mmc_host_remove() may then
disable the clock via runtime PM, which leads to clock enable/disable
imbalance problems, when the caller of tmio_mmc_host_remove() also tries to
disable the same clocks.

To solve the problem, let's make sure tmio_mmc_host_remove() leaves the
device with clocks enabled, but also make sure to disable the IRQs, as we
normally do at ->runtime_suspend().

Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/host/tmio_mmc_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
index f31afd1c2671..ba301fb7656b 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -1231,12 +1231,14 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
 	cancel_work_sync(&host->done);
 	cancel_delayed_work_sync(&host->delayed_reset_work);
 	tmio_mmc_release_dma(host);
+	tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL);
 
-	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	if (host->native_hotplug)
 		pm_runtime_put_noidle(&pdev->dev);
-	pm_runtime_put_sync(&pdev->dev);
+
 	pm_runtime_disable(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
 }
 EXPORT_SYMBOL_GPL(tmio_mmc_host_remove);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH 1/2] mmc: tmio: Further fixup runtime PM management at remove
@ 2020-05-15 14:04 Ulf Hansson
  2020-05-15 15:02 ` Ulf Hansson
  2020-05-19 13:56 ` Wolfram Sang
  0 siblings, 2 replies; 12+ messages in thread
From: Ulf Hansson @ 2020-05-15 14:04 UTC (permalink / raw)
  To: linux-mmc, Ulf Hansson, Masahiro Yamada, Wolfram Sang
  Cc: Ulrich Hecht, Simon Horman, Niklas Soderlund, Geert Uytterhoeven

Before calling tmio_mmc_host_probe(), the caller is required to enable
clocks for its device, as to make it accessible when reading/writing
registers during probe.

Therefore, the responsibility to disable these clocks, in the error path of
->probe() and during ->remove(), is better managed outside
tmio_mmc_host_remove(). As a matter of fact, callers of
tmio_mmc_host_remove() already expects this to be the behaviour.

However, there's a problem with tmio_mmc_host_remove() when the Kconfig
option, CONFIG_PM, is set. More precisely, tmio_mmc_host_remove() may then
disable the clock via runtime PM, which leads to clock enable/disable
imbalance problems, when the caller of tmio_mmc_host_remove() also tries to
disable the same clocks.

Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/host/tmio_mmc_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
index f31afd1c2671..ba301fb7656b 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -1231,12 +1231,14 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
 	cancel_work_sync(&host->done);
 	cancel_delayed_work_sync(&host->delayed_reset_work);
 	tmio_mmc_release_dma(host);
+	tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL);
 
-	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	if (host->native_hotplug)
 		pm_runtime_put_noidle(&pdev->dev);
-	pm_runtime_put_sync(&pdev->dev);
+
 	pm_runtime_disable(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
 }
 EXPORT_SYMBOL_GPL(tmio_mmc_host_remove);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-05-20 20:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 15:24 [PATCH 1/2] mmc: tmio: Further fixup runtime PM management at remove Ulf Hansson
2020-05-20 11:35 ` Ulf Hansson
2020-05-20 14:30 ` Geert Uytterhoeven
2020-05-20 15:18   ` Ulf Hansson
2020-05-20 15:49   ` Wolfram Sang
2020-05-20 18:19     ` Geert Uytterhoeven
2020-05-20 19:29       ` Geert Uytterhoeven
2020-05-20 20:32         ` Wolfram Sang
  -- strict thread matches above, loose matches on Subject: below --
2020-05-15 14:04 Ulf Hansson
2020-05-15 15:02 ` Ulf Hansson
2020-05-18 20:02   ` Wolfram Sang
2020-05-19 13:56 ` Wolfram Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.