[PATCH 04/11] dmaengine: imx-sdma: make use of devm_kzalloc for script_addrs

Frank Li Frank.li at nxp.com
Wed Sep 3 08:00:31 PDT 2025


On Wed, Sep 03, 2025 at 03:06:12PM +0200, Marco Felsch wrote:
> Shuffle the allocation of script_addrs and make use of devm_kzalloc() to
> drop the local error handling as well as the kfree() during the remove.
>
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> ---

Reviewed-by: Frank Li <Frank.Li at nxp.com>

>  drivers/dma/imx-sdma.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index a85739d279f51fdb517fce90b3dc67673cf2b56c..b6e649fda71dbce12a2106c94887f90d0aaaf600 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -2253,6 +2253,10 @@ static int sdma_probe(struct platform_device *pdev)
>  	if (!sdma)
>  		return -ENOMEM;
>
> +	sdma->script_addrs = devm_kzalloc(dev, sizeof(*sdma->script_addrs), GFP_KERNEL);
> +	if (!sdma->script_addrs)
> +		return -ENOMEM;
> +
>  	spin_lock_init(&sdma->channel_0_lock);
>
>  	sdma->dev = dev;
> @@ -2289,12 +2293,6 @@ static int sdma_probe(struct platform_device *pdev)
>
>  	sdma->irq = irq;
>
> -	sdma->script_addrs = kzalloc(sizeof(*sdma->script_addrs), GFP_KERNEL);
> -	if (!sdma->script_addrs) {
> -		ret = -ENOMEM;
> -		goto err_irq;
> -	}
> -
>  	/* initially no scripts available */
>  	saddr_arr = (s32 *)sdma->script_addrs;
>  	for (i = 0; i < sizeof(*sdma->script_addrs) / sizeof(s32); i++)
> @@ -2332,11 +2330,11 @@ static int sdma_probe(struct platform_device *pdev)
>
>  	ret = sdma_init(sdma);
>  	if (ret)
> -		goto err_init;
> +		goto err_irq;
>
>  	ret = sdma_event_remap(sdma);
>  	if (ret)
> -		goto err_init;
> +		goto err_irq;
>
>  	if (sdma->drvdata->script_addrs)
>  		sdma_add_scripts(sdma, sdma->drvdata->script_addrs);
> @@ -2365,7 +2363,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_init;
> +		goto err_irq;
>  	}
>
>  	ret = of_dma_controller_register(np, sdma_xlate, sdma);
> @@ -2401,8 +2399,6 @@ static int sdma_probe(struct platform_device *pdev)
>
>  err_register:
>  	dma_async_device_unregister(&sdma->dma_device);
> -err_init:
> -	kfree(sdma->script_addrs);
>  err_irq:
>  	clk_unprepare(sdma->clk_ahb);
>  err_clk:
> @@ -2417,7 +2413,6 @@ static void sdma_remove(struct platform_device *pdev)
>
>  	devm_free_irq(&pdev->dev, sdma->irq, sdma);
>  	dma_async_device_unregister(&sdma->dma_device);
> -	kfree(sdma->script_addrs);
>  	clk_unprepare(sdma->clk_ahb);
>  	clk_unprepare(sdma->clk_ipg);
>  	/* Kill the tasklet */
>
> --
> 2.47.2
>



More information about the linux-arm-kernel mailing list