dmaengine: sun4i: fix resource leak on promise allocation failure
Subsystems (2)
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.
Signed-off-by Osama Abdelkader <[email protected]>
--- drivers/dma/sun4i-dma.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma/sun4i-dma.c +5 -3
@@ -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