Re: [PATCH] dmaengine: imx-sdma: Fix a possible memory leak in sdma_transfer_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 30, 2022 at 12:42:37PM +0800, Hui Wang wrote:
> If the function sdma_load_context() fails, the sdma_desc will be
> freed, but the allocated desc->bd is forgot to be freed.
> 
> We already met the sdma_load_context() failure case and the log as
> below:
> [ 450.699064] imx-sdma 30bd0000.dma-controller: Timeout waiting for CH0 ready
> ...
> 
> In this case, the desc->bd will not be freed without this change.
> 
> Signed-off-by: Hui Wang <hui.wang@xxxxxxxxxxxxx>
> ---
>  drivers/dma/imx-sdma.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index fbea5f62dd98..235a4e12d660 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -1520,8 +1520,10 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
>  	if (direction == DMA_MEM_TO_MEM)
>  		sdma_config_ownership(sdmac, false, true, false);
>  
> -	if (sdma_load_context(sdmac))
> +	if (sdma_load_context(sdmac)) {
> +		sdma_free_bd(desc);
>  		goto err_desc_out;
> +	}

We have an error path at the end of the function. For consistency you
should follow that pattern and add another label where you call
sdma_free_bd().

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux PCI]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux