Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dmaengine: jz4780: fix resource leaks on error exit return

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>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>

authored by

Colin Ian King and committed by
Vinod Koul
fc878efe 9f0df936

+6 -2
+6 -2
drivers/dma/dma-jz4780.c
··· 324 324 sg_dma_address(&sgl[i]), 325 325 sg_dma_len(&sgl[i]), 326 326 direction); 327 - if (err < 0) 327 + if (err < 0) { 328 + jz4780_dma_desc_free(&jzchan->desc->vdesc); 328 329 return NULL; 330 + } 329 331 330 332 desc->desc[i].dcm |= JZ_DMA_DCM_TIE; 331 333 ··· 370 368 for (i = 0; i < periods; i++) { 371 369 err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i], buf_addr, 372 370 period_len, direction); 373 - if (err < 0) 371 + if (err < 0) { 372 + jz4780_dma_desc_free(&jzchan->desc->vdesc); 374 373 return NULL; 374 + } 375 375 376 376 buf_addr += period_len; 377 377