[PATCH 1/6] dmaengine: zynqmp_dma: Fix alloc_chan_resources error cleanup
Frank Li
Frank.li at oss.nxp.com
Thu Aug 6 08:39:51 PDT 2026
On Thu, Aug 06, 2026 at 06:00:09PM +0530, Golla Nagendra wrote:
> Channel resource allocation can fail after runtime PM has been acquired
> and after part of the descriptor state has been initialized. Without
> proper rollback, the error path leaks a runtime PM reference and, on
> coherent allocation failure, also leaks the software descriptor pool.
>
> Fix this by balancing runtime PM usage before returning an error and
> releasing any partially allocated software descriptor pool.
>
> Fixes: 8982d48af36d ("dmaengine: zynqmp_dma: Fix PM reference leak in zynqmp_dma_alloc_chan_resourc()")
> Signed-off-by: Golla Nagendra <nagendra.golla at amd.com>
> ---
> drivers/dma/xilinx/zynqmp_dma.c | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
> index f6a812e49ddc..b7c561280694 100644
> --- a/drivers/dma/xilinx/zynqmp_dma.c
> +++ b/drivers/dma/xilinx/zynqmp_dma.c
> @@ -483,8 +483,10 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan)
> return ret;
>
> chan->sw_desc_pool = kzalloc_objs(*desc, ZYNQMP_DMA_NUM_DESCS);
> - if (!chan->sw_desc_pool)
> - return -ENOMEM;
> + if (!chan->sw_desc_pool) {
> + ret = -ENOMEM;
> + goto err_pm;
> + }
>
> chan->idle = true;
> chan->desc_free_cnt = ZYNQMP_DMA_NUM_DESCS;
> @@ -502,8 +504,10 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan)
> (2 * ZYNQMP_DMA_DESC_SIZE(chan) *
> ZYNQMP_DMA_NUM_DESCS),
> &chan->desc_pool_p, GFP_KERNEL);
> - if (!chan->desc_pool_v)
> - return -ENOMEM;
> + if (!chan->desc_pool_v) {
> + ret = -ENOMEM;
> + goto err_free_sw_desc_pool;
This is seperated problem. Need use new patch to fix it.
Frank
> + }
>
> for (i = 0; i < ZYNQMP_DMA_NUM_DESCS; i++) {
> desc = chan->sw_desc_pool + i;
> @@ -516,6 +520,13 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan)
> }
>
> return ZYNQMP_DMA_NUM_DESCS;
> +
> +err_free_sw_desc_pool:
> + kfree(chan->sw_desc_pool);
> + chan->sw_desc_pool = NULL;
> +err_pm:
> + pm_runtime_put_autosuspend(chan->dev);
> + return ret;
> }
>
> /**
> --
> 2.43.7
>
More information about the linux-arm-kernel
mailing list