[PATCH v5 04/17] spi: img-spfi: Simplify clock handling with devm_clk_get_enabled()

From: Pei Xiao

Date: Wed Mar 18 2026 - 22:06:01 EST


Replace devm_clk_get() followed by clk_prepare_enable() with
devm_clk_get_enabled() for both "sys" and "spfi" clocks. 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.

Signed-off-by: Pei Xiao <xiaopei01@xxxxxxxxxx>
---
drivers/spi/spi-img-spfi.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/drivers/spi/spi-img-spfi.c b/drivers/spi/spi-img-spfi.c
index 902fb64815c9..b45c6ceaffe2 100644
--- a/drivers/spi/spi-img-spfi.c
+++ b/drivers/spi/spi-img-spfi.c
@@ -557,24 +557,17 @@ static int img_spfi_probe(struct platform_device *pdev)
if (ret)
goto put_spi;

- spfi->sys_clk = devm_clk_get(spfi->dev, "sys");
+ spfi->sys_clk = devm_clk_get_enabled(spfi->dev, "sys");
if (IS_ERR(spfi->sys_clk)) {
ret = PTR_ERR(spfi->sys_clk);
goto put_spi;
}
- spfi->spfi_clk = devm_clk_get(spfi->dev, "spfi");
+ spfi->spfi_clk = devm_clk_get_enabled(spfi->dev, "spfi");
if (IS_ERR(spfi->spfi_clk)) {
ret = PTR_ERR(spfi->spfi_clk);
goto put_spi;
}

- ret = clk_prepare_enable(spfi->sys_clk);
- if (ret)
- goto put_spi;
- ret = clk_prepare_enable(spfi->spfi_clk);
- if (ret)
- goto disable_pclk;
-
spfi_reset(spfi);
/*
* Only enable the error (IACCESS) interrupt. In PIO mode we'll
@@ -655,9 +648,6 @@ static int img_spfi_probe(struct platform_device *pdev)
dma_release_channel(spfi->rx_ch);
if (spfi->tx_ch)
dma_release_channel(spfi->tx_ch);
- clk_disable_unprepare(spfi->spfi_clk);
-disable_pclk:
- clk_disable_unprepare(spfi->sys_clk);
put_spi:
spi_controller_put(host);

@@ -675,10 +665,6 @@ static void img_spfi_remove(struct platform_device *pdev)
dma_release_channel(spfi->rx_ch);

pm_runtime_disable(spfi->dev);
- if (!pm_runtime_status_suspended(spfi->dev)) {
- clk_disable_unprepare(spfi->spfi_clk);
- clk_disable_unprepare(spfi->sys_clk);
- }
}

#ifdef CONFIG_PM
--
2.25.1