Skip to contentSkip to conversation

dmaengine: sun4i: fix resource leak on promise allocation failure

PATCH New Osama Abdelkader 1 participant 1 message Dec 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: sun4i: fix resource leak on promise allocation failure

When promise allocation fails in sun4i_dma_prep_dma_cyclic() or sun4i_dma_prep_slave_sg(), the contract and already-allocated promises are not freed, causing a resource leak.

Fix this by calling sun4i_dma_free_contract() to properly clean up all resources before returning NULL on allocation failure.

This addresses the TODO comments that asked whether we should free everything on error.

---
 drivers/dma/sun4i-dma.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma/sun4i-dma.c +5 -3
index 00d2fd38d17f..d81e705ae91f 100644
@@ -861,7 +861,7 @@ sun4i_dma_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf, size_t len,
 							plength, sconfig, dir);
 
 		if (!promise) {
-			/* TODO: should we free everything? */
+			sun4i_dma_free_contract(&contract->vd);
 			return NULL;
 		}
 		promise->cfg |= endpoints;
@@ -954,8 +954,10 @@ sun4i_dma_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 							sg_dma_len(sg),
 							sconfig, dir);
 
-		if (!promise)
-			return NULL; /* TODO: should we free everything? */
+		if (!promise) {
+			sun4i_dma_free_contract(&contract->vd);
+			return NULL;
+		}
 
 		promise->cfg |= endpoints;
 		promise->para = para;
Signature · 1 line
2.43.0