[PATCH v2 07/10] dmaengine: imx-sdma: make use of devm_clk_get_prepared()

Marco Felsch
2025-09-11T21:59:50Z

Make use of the devm_clk_get_prepared() to cleanup the error handling
during probe() and to automatically unprepare the clock during remove.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/dma/imx-sdma.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index d6239900ba12063bdb7d807db1bdbdc2b446a94c..d39589c20c4b2a26d0239feb86cce8d5a0f5acdd 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -2300,26 +2300,18 @@ static int sdma_probe(struct platform_device *pdev)
if (IS_ERR(sdma->regs))
return PTR_ERR(sdma->regs);

- sdma->clk_ipg = devm_clk_get(dev, "ipg");
+ sdma->clk_ipg = devm_clk_get_prepared(dev, "ipg");
if (IS_ERR(sdma->clk_ipg))
return PTR_ERR(sdma->clk_ipg);

- sdma->clk_ahb = devm_clk_get(dev, "ahb");
+ sdma->clk_ahb = devm_clk_get_prepared(dev, "ahb");
if (IS_ERR(sdma->clk_ahb))
return PTR_ERR(sdma->clk_ahb);

- ret = clk_prepare(sdma->clk_ipg);
- if (ret)
- return ret;
-
- ret = clk_prepare(sdma->clk_ahb);
- if (ret)
- goto err_clk;
-
ret = devm_request_irq(dev, irq, sdma_int_handler, 0,
dev_name(dev), sdma);
if (ret)
- goto err_irq;
+ return ret;

sdma->irq = irq;

@@ -2360,11 +2352,11 @@ static int sdma_probe(struct platform_device *pdev)

ret = sdma_init(sdma);
if (ret)
- goto err_irq;
+ return ret;

ret = sdma_event_remap(sdma);
if (ret)
- goto err_irq;
+ return ret;

if (sdma->drvdata->script_addrs)
sdma_add_scripts(sdma, sdma->drvdata->script_addrs);
@@ -2393,7 +2385,7 @@ static int sdma_probe(struct platform_device *pdev)
ret = dma_async_device_register(&sdma->dma_device);
if (ret) {
dev_err(dev, "unable to register\n");
- goto err_irq;
+ return ret;
}

ret = of_dma_controller_register(np, sdma_xlate, sdma);
@@ -2421,10 +2413,7 @@ static int sdma_probe(struct platform_device *pdev)

err_register:
dma_async_device_unregister(&sdma->dma_device);
-err_irq:
- clk_unprepare(sdma->clk_ahb);
-err_clk:
- clk_unprepare(sdma->clk_ipg);
+
return ret;
}

@@ -2436,8 +2425,6 @@ static void sdma_remove(struct platform_device *pdev)
of_dma_controller_free(sdma->dev->of_node);
devm_free_irq(&pdev->dev, sdma->irq, sdma);
dma_async_device_unregister(&sdma->dma_device);
- clk_unprepare(sdma->clk_ahb);
- clk_unprepare(sdma->clk_ipg);
/* Kill the tasklet */
for (i = 0; i < MAX_DMA_CHANNELS; i++) {
struct sdma_channel *sdmac = &sdma->channel[i];

--
2.47.3