Message ID | 20240823101933.9517-4-liaoyuanhong@vivo.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | dma:Use devm_clk_get_enabled() helpers | expand |
On Fri, 23 Aug 2024 18:19:30 +0800 Liao Yuanhong <liaoyuanhong@vivo.com> wrote: > Use devm_clk_get_enabled() instead of clk functions in imx-dma. > > Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com> Straight forward case, but nice to combine this with use of return dev_err_probe() in the paths where you now have direct returns. Other comments below. > --- > drivers/dma/imx-dma.c | 38 +++++++++++++------------------------- > 1 file changed, 13 insertions(+), 25 deletions(-) > > diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c > index ebf7c115d553..1ef926304d0e 100644 > --- a/drivers/dma/imx-dma.c > +++ b/drivers/dma/imx-dma.c > @@ -1039,6 +1039,8 @@ static int __init imxdma_probe(struct platform_device *pdev) > struct imxdma_engine *imxdma; > int ret, i; > int irq, irq_err; > + struct clk *dma_ahb; > + struct clk *dma_ipg; struct clk *dma_ahb, *dma_ipg; should be fine. > > imxdma = devm_kzalloc(&pdev->dev, sizeof(*imxdma), GFP_KERNEL); > if (!imxdma) > @@ -1055,20 +1057,13 @@ static int __init imxdma_probe(struct platform_device *pdev) > if (irq < 0) > return irq; > > - imxdma->dma_ipg = devm_clk_get(&pdev->dev, "ipg"); > - if (IS_ERR(imxdma->dma_ipg)) > - return PTR_ERR(imxdma->dma_ipg); > + dma_ipg = devm_clk_get_enabled(&pdev->dev, "ipg"); > + if (IS_ERR(dma_ipg)) > + return PTR_ERR(dma_ipg); > > - imxdma->dma_ahb = devm_clk_get(&pdev->dev, "ahb"); > - if (IS_ERR(imxdma->dma_ahb)) > - return PTR_ERR(imxdma->dma_ahb); > - > - ret = clk_prepare_enable(imxdma->dma_ipg); > - if (ret) > - return ret; > - ret = clk_prepare_enable(imxdma->dma_ahb); > - if (ret) > - goto disable_dma_ipg_clk; > + dma_ahb = devm_clk_get_enabled(&pdev->dev, "ahb"); > + if (IS_ERR(dma_ahb)) > + return PTR_ERR(dma_ahb); > > /* reset DMA module */ > imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR); > @@ -1078,21 +1073,21 @@ static int __init imxdma_probe(struct platform_device *pdev) > dma_irq_handler, 0, "DMA", imxdma); > if (ret) { > dev_warn(imxdma->dev, "Can't register IRQ for DMA\n"); > - goto disable_dma_ahb_clk; > + return ret; Odd not to make that a dev_error given driver fails to probe as a result. I'd switch to return dev_err_rpobe() > } > imxdma->irq = irq; > > irq_err = platform_get_irq(pdev, 1); > if (irq_err < 0) { > ret = irq_err; > - goto disable_dma_ahb_clk; > + return ret; > } > > ret = devm_request_irq(&pdev->dev, irq_err, > imxdma_err_handler, 0, "DMA", imxdma); > if (ret) { > dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n"); > - goto disable_dma_ahb_clk; > + return ret; Here as well. > } > imxdma->irq_err = irq_err; > } > @@ -1130,7 +1125,7 @@ static int __init imxdma_probe(struct platform_device *pdev) > dev_warn(imxdma->dev, "Can't register IRQ %d " > "for DMA channel %d\n", > irq + i, i); > - goto disable_dma_ahb_clk; > + return ret; and here. > } > > imxdmac->irq = irq + i; > @@ -1174,7 +1169,7 @@ static int __init imxdma_probe(struct platform_device *pdev) > ret = dma_async_device_register(&imxdma->dma_device); > if (ret) { > dev_err(&pdev->dev, "unable to register\n"); > - goto disable_dma_ahb_clk; > + return ret; and finaly here. > } > > if (pdev->dev.of_node) { > @@ -1190,10 +1185,6 @@ static int __init imxdma_probe(struct platform_device *pdev) > > err_of_dma_controller: > dma_async_device_unregister(&imxdma->dma_device); Maybe use a local callback and devm_add_action_or_reset() to get automate handling of this call as well. > -disable_dma_ahb_clk: > - clk_disable_unprepare(imxdma->dma_ahb); > -disable_dma_ipg_clk: > - clk_disable_unprepare(imxdma->dma_ipg); > return ret; > } > > @@ -1226,9 +1217,6 @@ static void imxdma_remove(struct platform_device *pdev) > > if (pdev->dev.of_node) > of_dma_controller_free(pdev->dev.of_node); The ordering of the two items above here looks suspicious as it doesn't reverse order of probably. Maybe worth cleaning that up whilst here. > - > - clk_disable_unprepare(imxdma->dma_ipg); > - clk_disable_unprepare(imxdma->dma_ahb); > } > > static struct platform_driver imxdma_driver = {
diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c index ebf7c115d553..1ef926304d0e 100644 --- a/drivers/dma/imx-dma.c +++ b/drivers/dma/imx-dma.c @@ -1039,6 +1039,8 @@ static int __init imxdma_probe(struct platform_device *pdev) struct imxdma_engine *imxdma; int ret, i; int irq, irq_err; + struct clk *dma_ahb; + struct clk *dma_ipg; imxdma = devm_kzalloc(&pdev->dev, sizeof(*imxdma), GFP_KERNEL); if (!imxdma) @@ -1055,20 +1057,13 @@ static int __init imxdma_probe(struct platform_device *pdev) if (irq < 0) return irq; - imxdma->dma_ipg = devm_clk_get(&pdev->dev, "ipg"); - if (IS_ERR(imxdma->dma_ipg)) - return PTR_ERR(imxdma->dma_ipg); + dma_ipg = devm_clk_get_enabled(&pdev->dev, "ipg"); + if (IS_ERR(dma_ipg)) + return PTR_ERR(dma_ipg); - imxdma->dma_ahb = devm_clk_get(&pdev->dev, "ahb"); - if (IS_ERR(imxdma->dma_ahb)) - return PTR_ERR(imxdma->dma_ahb); - - ret = clk_prepare_enable(imxdma->dma_ipg); - if (ret) - return ret; - ret = clk_prepare_enable(imxdma->dma_ahb); - if (ret) - goto disable_dma_ipg_clk; + dma_ahb = devm_clk_get_enabled(&pdev->dev, "ahb"); + if (IS_ERR(dma_ahb)) + return PTR_ERR(dma_ahb); /* reset DMA module */ imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR); @@ -1078,21 +1073,21 @@ static int __init imxdma_probe(struct platform_device *pdev) dma_irq_handler, 0, "DMA", imxdma); if (ret) { dev_warn(imxdma->dev, "Can't register IRQ for DMA\n"); - goto disable_dma_ahb_clk; + return ret; } imxdma->irq = irq; irq_err = platform_get_irq(pdev, 1); if (irq_err < 0) { ret = irq_err; - goto disable_dma_ahb_clk; + return ret; } ret = devm_request_irq(&pdev->dev, irq_err, imxdma_err_handler, 0, "DMA", imxdma); if (ret) { dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n"); - goto disable_dma_ahb_clk; + return ret; } imxdma->irq_err = irq_err; } @@ -1130,7 +1125,7 @@ static int __init imxdma_probe(struct platform_device *pdev) dev_warn(imxdma->dev, "Can't register IRQ %d " "for DMA channel %d\n", irq + i, i); - goto disable_dma_ahb_clk; + return ret; } imxdmac->irq = irq + i; @@ -1174,7 +1169,7 @@ static int __init imxdma_probe(struct platform_device *pdev) ret = dma_async_device_register(&imxdma->dma_device); if (ret) { dev_err(&pdev->dev, "unable to register\n"); - goto disable_dma_ahb_clk; + return ret; } if (pdev->dev.of_node) { @@ -1190,10 +1185,6 @@ static int __init imxdma_probe(struct platform_device *pdev) err_of_dma_controller: dma_async_device_unregister(&imxdma->dma_device); -disable_dma_ahb_clk: - clk_disable_unprepare(imxdma->dma_ahb); -disable_dma_ipg_clk: - clk_disable_unprepare(imxdma->dma_ipg); return ret; } @@ -1226,9 +1217,6 @@ static void imxdma_remove(struct platform_device *pdev) if (pdev->dev.of_node) of_dma_controller_free(pdev->dev.of_node); - - clk_disable_unprepare(imxdma->dma_ipg); - clk_disable_unprepare(imxdma->dma_ahb); } static struct platform_driver imxdma_driver = {
Use devm_clk_get_enabled() instead of clk functions in imx-dma. Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com> --- drivers/dma/imx-dma.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-)