diff mbox

dmaengine: jz4780: fix resource leaks on error exit return

Message ID 20160929174505.13913-1-colin.king@canonical.com (mailing list archive)
State Rejected
Headers show

Commit Message

Colin King Sept. 29, 2016, 5:45 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

In two cases when jz4780_dma_setup_hwdesc fails, there is a memory
leak on the allocated desc and associated DMA pools on the error
exit return path.  Fix this by free'ing the resources before
returning.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/dma/dma-jz4780.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Vinod Koul Sept. 30, 2016, 5:52 p.m. UTC | #1
On Thu, Sep 29, 2016 at 06:45:05PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> In two cases when jz4780_dma_setup_hwdesc fails, there is a memory
> leak on the allocated desc and associated DMA pools on the error
> exit return path.  Fix this by free'ing the resources before
> returning.

Applied, thanks
diff mbox

Patch

diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
index c36c14c..7373b7a 100644
--- a/drivers/dma/dma-jz4780.c
+++ b/drivers/dma/dma-jz4780.c
@@ -324,8 +324,10 @@  static struct dma_async_tx_descriptor *jz4780_dma_prep_slave_sg(
 					      sg_dma_address(&sgl[i]),
 					      sg_dma_len(&sgl[i]),
 					      direction);
-		if (err < 0)
+		if (err < 0) {
+			jz4780_dma_desc_free(&jzchan->desc->vdesc);
 			return NULL;
+		}
 
 		desc->desc[i].dcm |= JZ_DMA_DCM_TIE;
 
@@ -368,8 +370,10 @@  static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_cyclic(
 	for (i = 0; i < periods; i++) {
 		err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i], buf_addr,
 					      period_len, direction);
-		if (err < 0)
+		if (err < 0) {
+			jz4780_dma_desc_free(&jzchan->desc->vdesc);
 			return NULL;
+		}
 
 		buf_addr += period_len;