[PATCH] dmaengine: sun4i: fix resource leak on promise allocation failure

Osama Abdelkader posted 1 patch 1 day, 5 hours ago
drivers/dma/sun4i-dma.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
[PATCH] dmaengine: sun4i: fix resource leak on promise allocation failure
Posted by Osama Abdelkader 1 day, 5 hours ago
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.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 drivers/dma/sun4i-dma.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/sun4i-dma.c b/drivers/dma/sun4i-dma.c
index 00d2fd38d17f..d81e705ae91f 100644
--- a/drivers/dma/sun4i-dma.c
+++ b/drivers/dma/sun4i-dma.c
@@ -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;
-- 
2.43.0