[PATCH] ASoC: rockchip: rockchip_sai: Fix hclk and runtime PM handling in probe
Arina Kharlamova via B4 Relay
devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Mon Nov 30 14:56:00 PST 2026
From: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
Probe powers the device up by calling rockchip_sai_runtime_resume()
directly, but runtime PM is not told about it and the status stays
suspended. The pm_runtime_put() at the end of probe then does nothing,
so the mclk and hclk enables taken by that call are never dropped: both
clocks stay on while the device is idle, and mclk stays on after unbind.
hclk is also got with devm_clk_get_enabled(), although probe drops its
own enable with clk_disable_unprepare() once the device is registered,
so devres disables it a second time at unbind. With CONFIG_PM the two
bugs cancel out for hclk; without it hclk is disabled once too often.
Get hclk with devm_clk_get() and enable it by hand, as before the
conversion, and disable it on the probe error paths. Resume the device
first, mark it active and only then enable runtime PM. Use
pm_runtime_put_sync() on the error path, so the device is suspended
before devres disables runtime PM.
The two fixes go together: either one alone leaves hclk unbalanced.
Fixes: cc78d1eaabad ("ASoC: rockchip: add Serial Audio Interface (SAI) driver")
Fixes: 03b778d19948 ("ASOC: rockchip: Use helper function devm_clk_get_enabled()")
Signed-off-by: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
---
Two fixes for the clock handling in rockchip_sai_probe().
1. hclk is got with devm_clk_get_enabled(), but probe also drops the
enable by hand once the device is registered, so devres disables the
clock a second time at unbind. Get it with devm_clk_get() and enable
it by hand, as before the conversion.
2. Probe powers the device up by calling the runtime resume callback
directly without marking it active, so the pm_runtime_put() at the
end of probe does nothing and mclk and hclk are never released.
Resume first, mark the device active, then enable runtime PM.
Found by checks derived from the spec2patch kernel API specifications,
with the help of an AI coding assistant (Claude); I reviewed the
analysis and the fix.
---
sound/soc/rockchip/rockchip_sai.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/sound/soc/rockchip/rockchip_sai.c b/sound/soc/rockchip/rockchip_sai.c
index b625d69f76c8..866b68cc706c 100644
--- a/sound/soc/rockchip/rockchip_sai.c
+++ b/sound/soc/rockchip/rockchip_sai.c
@@ -1459,20 +1459,30 @@ static int rockchip_sai_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(sai->mclk),
"Failed to get mclk\n");
- sai->hclk = devm_clk_get_enabled(&pdev->dev, "hclk");
+ sai->hclk = devm_clk_get(&pdev->dev, "hclk");
if (IS_ERR(sai->hclk))
return dev_err_probe(&pdev->dev, PTR_ERR(sai->hclk),
"Failed to get hclk\n");
+ /*
+ * hclk is only needed until runtime PM takes over below, so it is
+ * enabled by hand and not with devm_clk_get_enabled().
+ */
+ ret = clk_prepare_enable(sai->hclk);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to enable hclk\n");
+
regmap_read(sai->regmap, SAI_VERSION, &sai->version);
ret = rockchip_sai_init_dai(sai, res, &dai);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
+ if (ret) {
+ dev_err_probe(&pdev->dev, ret, "Failed to initialize DAI\n");
+ goto err_disable_hclk;
+ }
ret = rockchip_sai_parse_paths(sai, node);
if (ret)
- return ret;
+ goto err_disable_hclk;
/*
* From here on, all register accesses need to be wrapped in
@@ -1480,11 +1490,15 @@ static int rockchip_sai_probe(struct platform_device *pdev)
*
* NB: we don't rely on _resume_and_get in case of !CONFIG_PM
*/
- devm_pm_runtime_enable(&pdev->dev);
- pm_runtime_get_noresume(&pdev->dev);
ret = rockchip_sai_runtime_resume(&pdev->dev);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "Failed to resume device\n");
+ if (ret) {
+ dev_err_probe(&pdev->dev, ret, "Failed to resume device\n");
+ goto err_disable_hclk;
+ }
+
+ pm_runtime_set_active(&pdev->dev);
+ pm_runtime_get_noresume(&pdev->dev);
+ devm_pm_runtime_enable(&pdev->dev);
ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
if (ret)
@@ -1505,9 +1519,11 @@ static int rockchip_sai_probe(struct platform_device *pdev)
err_runtime_suspend:
if (IS_ENABLED(CONFIG_PM))
- pm_runtime_put(&pdev->dev);
+ pm_runtime_put_sync(&pdev->dev);
else
rockchip_sai_runtime_suspend(&pdev->dev);
+err_disable_hclk:
+ clk_disable_unprepare(sai->hclk);
return ret;
}
---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-d08-dd5b1bd68fab
Best regards,
--
Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
More information about the Linux-rockchip
mailing list