[PATCH v5 06/17] spi: npcm-pspi: Simplify clock handling with devm_clk_get_enabled()

Pei Xiao
2026-03-19T22:39:35Z

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

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

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-npcm-pspi.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-npcm-pspi.c b/drivers/spi/spi-npcm-pspi.c
index e60b3cc398ec..ae7f9a70fbcf 100644
--- a/drivers/spi/spi-npcm-pspi.c
+++ b/drivers/spi/spi-npcm-pspi.c
@@ -361,27 +361,23 @@ static int npcm_pspi_probe(struct platform_device *pdev)
goto out_host_put;
}

- priv->clk = devm_clk_get(&pdev->dev, NULL);
+ priv->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(priv->clk)) {
- dev_err(&pdev->dev, "failed to get clock\n");
+ dev_err(&pdev->dev, "failed to enable clock\n");
ret = PTR_ERR(priv->clk);
goto out_host_put;
}

- ret = clk_prepare_enable(priv->clk);
- if (ret)
- goto out_host_put;
-
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
ret = irq;
- goto out_disable_clk;
+ goto out_host_put;
}

priv->reset = devm_reset_control_get(&pdev->dev, NULL);
if (IS_ERR(priv->reset)) {
ret = PTR_ERR(priv->reset);
- goto out_disable_clk;
+ goto out_host_put;
}

/* reset SPI-HW block */
@@ -391,7 +387,7 @@ static int npcm_pspi_probe(struct platform_device *pdev)
"npcm-pspi", priv);
if (ret) {
dev_err(&pdev->dev, "failed to request IRQ\n");
- goto out_disable_clk;
+ goto out_host_put;
}

init_completion(&priv->xfer_done);
@@ -415,15 +411,12 @@ static int npcm_pspi_probe(struct platform_device *pdev)

ret = devm_spi_register_controller(&pdev->dev, host);
if (ret)
- goto out_disable_clk;
+ goto out_host_put;

pr_info("NPCM Peripheral SPI %d probed\n", host->bus_num);

return 0;

-out_disable_clk:
- clk_disable_unprepare(priv->clk);
-
out_host_put:
spi_controller_put(host);
return ret;
@@ -435,7 +428,6 @@ static void npcm_pspi_remove(struct platform_device *pdev)
struct npcm_pspi *priv = spi_controller_get_devdata(host);

npcm_pspi_reset_hw(priv);
- clk_disable_unprepare(priv->clk);
}

static const struct of_device_id npcm_pspi_match[] = {
--
2.25.1