[PATCH v5 08/17] spi: rockchip-sfc: Simplify clock handling with devm_clk_get_enabled()

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

devm_clk_get_enabled() for both the interface clock "clk_sfc" and the
AHB clock "hclk_sfc". This reduces boilerplate code and error handling,
as the managed API automatically disables the clocks when the device is
removed or if probe fails.

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

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-rockchip-sfc.c | 22 ++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-rockchip-sfc.c b/drivers/spi/spi-rockchip-sfc.c
index 174995042f53..b32b7c015edb 100644
--- a/drivers/spi/spi-rockchip-sfc.c
+++ b/drivers/spi/spi-rockchip-sfc.c
@@ -635,13 +635,13 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
return PTR_ERR(sfc->regbase);

if (!has_acpi_companion(&pdev->dev))
- sfc->clk = devm_clk_get(&pdev->dev, "clk_sfc");
+ sfc->clk = devm_clk_get_enabled(&pdev->dev, "clk_sfc");
if (IS_ERR(sfc->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(sfc->clk),
"Failed to get sfc interface clk\n");

if (!has_acpi_companion(&pdev->dev))
- sfc->hclk = devm_clk_get(&pdev->dev, "hclk_sfc");
+ sfc->hclk = devm_clk_get_enabled(&pdev->dev, "hclk_sfc");
if (IS_ERR(sfc->hclk))
return dev_err_probe(&pdev->dev, PTR_ERR(sfc->hclk),
"Failed to get sfc ahb clk\n");
@@ -657,18 +657,6 @@ static int rockchip_sfc_probe(struct platform_device *pdev)

sfc->use_dma = !of_property_read_bool(sfc->dev->of_node, "rockchip,sfc-no-dma");

- ret = clk_prepare_enable(sfc->hclk);
- if (ret) {
- dev_err(&pdev->dev, "Failed to enable ahb clk\n");
- goto err_hclk;
- }
-
- ret = clk_prepare_enable(sfc->clk);
- if (ret) {
- dev_err(&pdev->dev, "Failed to enable interface clk\n");
- goto err_clk;
- }
-
/* Find the irq */
ret = platform_get_irq(pdev, 0);
if (ret < 0)
@@ -730,10 +718,6 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
pm_runtime_set_suspended(dev);
pm_runtime_dont_use_autosuspend(dev);
err_irq:
- clk_disable_unprepare(sfc->clk);
-err_clk:
- clk_disable_unprepare(sfc->hclk);
-err_hclk:
return ret;
}

@@ -747,8 +731,6 @@ static void rockchip_sfc_remove(struct platform_device *pdev)
DMA_BIDIRECTIONAL);
free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));

- clk_disable_unprepare(sfc->clk);
- clk_disable_unprepare(sfc->hclk);
}

#ifdef CONFIG_PM
--
2.25.1