Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] dmaengine: imx-sdma: Fix potential memory leak on channel zero failure
@ 2026-11-20 17:35 Guangshuo Li
  2026-11-20 18:08 ` Frank Li
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-20 17:35 UTC (permalink / raw)
  To: Vinod Koul, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam
  Cc: dmaengine, imx, linux-arm-kernel, linux-kernel, stable

If allocating the channel zero descriptor fails, sdma_init() disables
the clocks without releasing the already allocated channel control and
context storage. Free that storage with the matching allocator before
returning the error.

This issue was found by our static analysis tool under development.

Fixes: 1ec1e82f2510 ("dmaengine: Add Freescale i.MX SDMA support")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/dma/imx-sdma.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 36368835a845..9c0087b3b805 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -2161,7 +2161,7 @@ static int sdma_init(struct sdma_engine *sdma)
 
 	ret = sdma_request_channel0(sdma);
 	if (ret)
-		goto err_dma_alloc;
+		goto free_channel_control;
 
 	sdma_config_ownership(&sdma->channel[0], false, true, false);
 
@@ -2184,6 +2184,13 @@ static int sdma_init(struct sdma_engine *sdma)
 
 	return 0;
 
+free_channel_control:
+	if (sdma->iram_pool)
+		gen_pool_free(sdma->iram_pool,
+			      (unsigned long)sdma->channel_control, ccbsize);
+	else
+		dma_free_coherent(sdma->dev, ccbsize, sdma->channel_control,
+				  ccb_phys);
 err_dma_alloc:
 	clk_disable(sdma->clk_ahb);
 disable_clk_ipg:

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 17:35 [PATCH] dmaengine: imx-sdma: Fix potential memory leak on channel zero failure Guangshuo Li
2026-11-20 18:08 ` Frank Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox