[PATCH v5 12/17] spi: stm32-qspi: Simplify clock handling with devm_clk_get_enabled()

Pei Xiao
2026-03-19T22:38:25Z

devm_clk_get_enabled() for the clock. This removes the need for
explicit clock enable and disable calls, as the managed API automatically
handles clock disabling on device removal or probe failure.

Remove the now-unnecessary clk_disable_unprepare() calls from the probe
error path and the remove callback. Adjust error labels accordingly.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-stm32-qspi.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
index df1bbacec90a..a8436f70fdfd 100644
--- a/drivers/spi/spi-stm32-qspi.c
+++ b/drivers/spi/spi-stm32-qspi.c
@@ -819,25 +819,19 @@ static int stm32_qspi_probe(struct platform_device *pdev)

init_completion(&qspi->match_completion);

- qspi->clk = devm_clk_get(dev, NULL);
+ qspi->clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(qspi->clk))
- return PTR_ERR(qspi->clk);
-
+ return dev_err_probe(dev, PTR_ERR(qspi->clk),
+ "can not enable the clock\n");
qspi->clk_rate = clk_get_rate(qspi->clk);
if (!qspi->clk_rate)
return -EINVAL;

- ret = clk_prepare_enable(qspi->clk);
- if (ret) {
- dev_err(dev, "can not enable the clock\n");
- return ret;
- }
-
rstc = devm_reset_control_get_exclusive(dev, NULL);
if (IS_ERR(rstc)) {
ret = PTR_ERR(rstc);
if (ret == -EPROBE_DEFER)
- goto err_clk_disable;
+ goto err_defer;
} else {
reset_control_assert(rstc);
udelay(2);
@@ -886,8 +880,7 @@ static int stm32_qspi_probe(struct platform_device *pdev)
pm_runtime_dont_use_autosuspend(qspi->dev);
err_dma_free:
stm32_qspi_dma_free(qspi);
-err_clk_disable:
- clk_disable_unprepare(qspi->clk);
+err_defer:

return ret;
}
@@ -906,7 +899,6 @@ static void stm32_qspi_remove(struct platform_device *pdev)
pm_runtime_disable(qspi->dev);
pm_runtime_set_suspended(qspi->dev);
pm_runtime_dont_use_autosuspend(qspi->dev);
- clk_disable_unprepare(qspi->clk);
}

static int stm32_qspi_runtime_suspend(struct device *dev)
--
2.25.1