Skip to contentSkip to conversation

spi: meson-spifc: use devm_pm_runtime_set_active_enabled

PATCH Superseded Felix Gu 3 participants 3 messages Jul 22 – Jul 30

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 spi: meson-spifc: use devm_pm_runtime_set_active_enabled

Use devm_pm_runtime_set_active_enabled to replace pm_runtime_set_active() + pm_runtime_enable() and drop the out_pm error label and now-unnecessary remove function.

---
 drivers/spi/spi-meson-spifc.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
drivers/spi/spi-meson-spifc.c +5 -18
index e36aa94bbdae..f67a0d10b602 100644
@@ -325,27 +325,15 @@ static int meson_spifc_probe(struct platform_device *pdev)
 
 	meson_spifc_hw_init(spifc);
 
-	pm_runtime_set_active(spifc->dev);
-	pm_runtime_enable(spifc->dev);
+	ret =  devm_pm_runtime_set_active_enabled(spifc->dev);
+	if (ret)
+		return dev_err_probe(spifc->dev, ret, "failed to set runtime PM\n");
 
 	ret = devm_spi_register_controller(spifc->dev, host);
-	if (ret) {
-		dev_err(spifc->dev, "failed to register spi host\n");
-		goto out_pm;
-	}
+	if (ret)
+		return dev_err_probe(spifc->dev, ret, "failed to register spi host\n");
 
 	return 0;
-out_pm:
-	pm_runtime_disable(spifc->dev);
-
-	return ret;
-}
-
-static void meson_spifc_remove(struct platform_device *pdev)
-{
-	pm_runtime_get_sync(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
-	pm_runtime_put_noidle(&pdev->dev);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -423,7 +411,6 @@ MODULE_DEVICE_TABLE(of, meson_spifc_dt_match);
 
 static struct platform_driver meson_spifc_driver = {
 	.probe	= meson_spifc_probe,
-	.remove = meson_spifc_remove,
 	.driver	= {
 		.name		= "meson-spifc",
 		.of_match_table	= of_match_ptr(meson_spifc_dt_match),

---
base-commit: 3fe08b9796f36ef437ab9328e7dd1e5ff2d66603
change-id: 20260722-spifc-336fbde9511b

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Removing `meson_spifc_remove()` introduces a clock enable count underflow (double-disable) when…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removing meson_spifc_remove() introduces a clock enable count underflow (double-disable) when the device is unbound. --

--- Patch [1]: [PATCH] spi: meson-spifc: use devm_pm_runtime_set_active_enabled --- commit 8bdf0818e31891c7533aa22fdb8392acb6154567
Author: Felix Gu <[email protected]>

spi: meson-spifc: use devm_pm_runtime_set_active_enabled

This commit replaces pm_runtime_set_active() and pm_runtime_enable() with devm_pm_runtime_set_active_enabled(). It also drops the out_pm error path and entirely removes the meson_spifc_remove() function.

Quoted 3 lines
drivers/spi/spi-meson-spifc.c +0 -0

[ ... ]

drivers/spi/spi-meson-spifc.c static int meson_spifc_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/spi/spi-meson-spifc.c +0 -6
-static void meson_spifc_remove(struct platform_device *pdev)
-{
-	pm_runtime_get_sync(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
-	pm_runtime_put_noidle(&pdev->dev);
-}

[Severity: Medium]
Does removing this function introduce a clock enable count underflow during driver unbind?

When the driver is unbound, the driver core calls pm_runtime_put_sync() in __device_release_driver(). Since the driver does not use autosuspend, this synchronously suspends the device by invoking meson_spifc_runtime_suspend(), which disables the clock.

Subsequently, the devres cleanup for devm_clk_get_enabled() executes and calls clk_disable_unprepare() a second time on the already disabled clock.

The removed meson_spifc_remove() function prevented this by calling pm_runtime_get_sync() to wake the device and keep the clock active until the devres teardown runs.

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
maintainer
#2 lore raw
In reply to Felix Gu

drivers/spi/spi-meson-spifc.c static int meson_spifc_probe(struct platform_device *pdev) · line 337

Quoted 10 lines · Felix Gu

Use devm_pm_runtime_set_active_enabled to replace pm_runtime_set_active() + pm_runtime_enable() and drop the out_pm error label and now-unnecessary remove function.

drivers/spi/spi-meson-spifc.c +0 -5
-static void meson_spifc_remove(struct platform_device *pdev)
-{
-	pm_runtime_get_sync(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
-	pm_runtime_put_noidle(&pdev->dev);
 }

We still need the pm_runtime_get_sync() here since the driver uses devm_get_clk_enabled() - we need to exit remove() with the clock enabled. The other changes look OK.