spi: imx: Use devm_clk_get_enabled() calls in spi_imx_probe()
Subsystems (3)
PATCH 1/1 spi: imx: Use devm_clk_get_enabled() calls in spi_imx_probe()
From: Markus Elfring <[email protected]>
Date: Mon, 23 Nov 2026 17:07:22 +0100
* Reuse existing functionality from devm_clk_get_enabled() instead of keeping duplicate source code.
* Delete clk_disable_unprepare() calls on error handling paths.
* Omit the label “out_put_per”.
This issue was detected by using the Coccinelle software.
--- drivers/spi/spi-imx.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/spi/spi-imx.c +2 -15
@@ -2319,22 +2319,14 @@ static int spi_imx_probe(struct platform_device *pdev)if (ret)return dev_err_probe (&pdev->dev, ret,"can't get irq%d\n" , irq); - spi_imx->clk_ipg =devm_clk_get (&pdev->dev,"ipg" ); + spi_imx->clk_ipg =devm_clk_get_enabled (&pdev->dev,"ipg" );if (IS_ERR (spi_imx->clk_ipg))return PTR_ERR (spi_imx->clk_ipg); - spi_imx->clk_per =devm_clk_get (&pdev->dev,"per" ); + spi_imx->clk_per =devm_clk_get_enabled (&pdev->dev,"per" );if (IS_ERR (spi_imx->clk_per))return PTR_ERR (spi_imx->clk_per); - ret =clk_prepare_enable (spi_imx->clk_per); -if (ret) -return ret; - - ret =clk_prepare_enable (spi_imx->clk_ipg); -if (ret) - goto out_put_per; -pm_runtime_set_autosuspend_delay (spi_imx->dev,MXC_RPM_TIMEOUT );pm_runtime_use_autosuspend (spi_imx->dev);pm_runtime_get_noresume (spi_imx->dev);
@@ -2378,11 +2370,6 @@ static int spi_imx_probe(struct platform_device *pdev)pm_runtime_disable (spi_imx->dev);pm_runtime_put_noidle (spi_imx->dev);pm_runtime_set_suspended (&pdev->dev); - -clk_disable_unprepare (spi_imx->clk_ipg); -out_put_per: -clk_disable_unprepare (spi_imx->clk_per); -return ret; }
Signature · 1 line
2.56.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] spi: imx: double clk_disable_unprepare() on unbind in spi_imx_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] spi: imx: double clk_disable_unprepare() on unbind in spi_imx_probe()
--
commit e7cc62f9e52ed65ab0fb34e0d12c2e19021d535c
Author: Markus Elfring <[email protected]>
spi: imx: Use devm_clk_get_enabled() calls in spi_imx_probe()
This commit replaces devm_clk_get() and clk_prepare_enable() for clk_ipg and clk_per in spi_imx_probe() with devm_clk_get_enabled() and removes the clk_disable_unprepare() calls from the probe error path.
Quoted 19 lines
drivers/spi/spi-imx.c +2
-3@@ -2320,22 +2320,14 @@ static int spi_imx_probe(struct platform_device *pdev)if (ret)return dev_err_probe (&pdev->dev, ret,"can't get irq%d\n" , irq); - spi_imx->clk_ipg =devm_clk_get (&pdev->dev,"ipg" ); + spi_imx->clk_ipg =devm_clk_get_enabled (&pdev->dev,"ipg" );if (IS_ERR (spi_imx->clk_ipg))return PTR_ERR (spi_imx->clk_ipg); - spi_imx->clk_per =devm_clk_get (&pdev->dev,"per" ); + spi_imx->clk_per =devm_clk_get_enabled (&pdev->dev,"per" );if (IS_ERR (spi_imx->clk_per))return PTR_ERR (spi_imx->clk_per); - ret =clk_prepare_enable (spi_imx->clk_per);
drivers/spi/spi-imx.c static int spi_imx_probe(struct platform_device *pdev) · line 2333
Quoted 10 lines
drivers/spi/spi-imx.c +0
-7-if (ret) -return ret; - - ret =clk_prepare_enable (spi_imx->clk_ipg); -if (ret) - goto out_put_per; -pm_runtime_set_autosuspend_delay (spi_imx->dev,MXC_RPM_TIMEOUT );pm_runtime_use_autosuspend (spi_imx->dev);pm_runtime_get_noresume (spi_imx->dev);
[Severity: High]
Does using devm_clk_get_enabled() here cause a double clk_disable_unprepare() on clk_per and clk_ipg when the device is unbound?
spi_imx_probe() calls pm_runtime_set_active() right after enabling the clocks, handing ownership of that initial prepare/enable reference to runtime PM:
drivers/spi/spi-imx.c:spi_imx_remove() {
...
pm_runtime_dont_use_autosuspend(spi_imx->dev);
pm_runtime_put_sync(spi_imx->dev);
pm_runtime_disable(spi_imx->dev);
...
}drivers/spi/spi-imx.c:spi_imx_runtime_suspend() {
...
clk_disable_unprepare(spi_imx->clk_per);
clk_disable_unprepare(spi_imx->clk_ipg);
return 0;
}When spi_imx_remove() runs with CONFIG_PM enabled, pm_runtime_put_sync() invokes spi_imx_runtime_suspend() and disables both clocks. The devm_clk_get_enabled() release action then calls clk_disable_unprepare() a second time on already-disabled clk_per and clk_ipg, triggering clock enable/prepare count underflow warnings.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · Markus Elfring
* Reuse existing functionality from
devm_clk_get_enabled()instead of keeping duplicate source code.* Delete
clk_disable_unprepare()calls on error handling paths.* Omit the label “out_put_per”.
This issue was detected by using the Coccinelle software.
This now messes up with the PM callbacks at remove stage. It's not trivial how to make it correct.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines
Quoted 8 lines
* Reuse existing functionality from
devm_clk_get_enabled()instead of keeping duplicate source code.* Delete
clk_disable_unprepare()calls on error handling paths.* Omit the label “out_put_per”.
This issue was detected by using the Coccinelle software.
This now messes up with the PM callbacks at remove stage. It's not trivial how to make it correct.
Is there a need to adjust and extend devres programming interfaces any more?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/driver-model/devres.rst?h=v7.4-rc4#n242
Regards,
Markus
Quoted 5 lines · Markus Elfring
Quoted 5 lines
Quoted 5 lines
* Reuse existing functionality from
devm_clk_get_enabled()instead of keeping duplicate source code.* Delete
clk_disable_unprepare()calls on error handling paths.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
* Omit the label “out_put_per”.
This issue was detected by using the Coccinelle software.
This now messes up with the PM callbacks at remove stage. It's not trivial how to make it correct.
Is there a need to adjust and extend devres programming interfaces any more?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/driver-model/devres.rst?h=v7.4-rc4#n242
I guess you did get my point. You can't simply do what you have done in this patch, because the devm*() will do something with clock reference counting on remove stage _after_ the driver.
NAK to this change.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mark Brown
maintainerQuoted 10 lines · Andy Shevchenko
Quoted 9 lines · Markus Elfring
Quoted 9 lines
Quoted 8 lines
* Reuse existing functionality from
devm_clk_get_enabled()instead of keeping duplicate source code.* Delete
clk_disable_unprepare()calls on error handling paths.* Omit the label “out_put_per”.
This issue was detected by using the Coccinelle software.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
This now messes up with the PM callbacks at remove stage. It's not trivial how to make it correct.
Is there a need to adjust and extend devres programming interfaces any more?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/driver-model/devres.rst?h=v7.4-rc4#n242I guess you did get my point. You can't simply do what you have done in this patch, because the devm*() will do something with clock reference counting on remove stage _after_ the driver.
Feel free to ignore Markus, he has a long history of sending unhelpful review comments and continues to ignore repeated requests to stop.