[PATCH] drivers: dma-coherent: free memory when failed to init DMA memory pool

Michal Nazarewicz mina86 at mina86.com
Thu Dec 3 04:50:55 PST 2015


On Thu, Dec 03 2015, Fugang Duan wrote:
> Free dma coherent memory when it failed to init DMA memory pool after
> calling .dma_init_coherent_memory(), otherwise it causes memmory leak.
>
> Signed-off-by: Fugang Duan <B38611 at freescale.com>
> ---
>  drivers/base/dma-coherent.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
> index 55b8398..beb6bbe 100644
> --- a/drivers/base/dma-coherent.c
> +++ b/drivers/base/dma-coherent.c
> @@ -286,6 +286,7 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)
>  				     &mem) != DMA_MEMORY_MAP) {
>  		pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n",
>  			&rmem->base, (unsigned long)rmem->size / SZ_1M);
> +		kfree(mem);

mem == NULL at this point.  If dma_init_coherent_memory doesn’t return
DMA_MEMORY_MAP, mem pointer is not assigned any value.  If you think
there is a memory leak, please demonstrate a path of it happening.

>  		return -ENODEV;
>  	}
>  	rmem->priv = mem;
> -- 
> 1.9.1
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  ミハウ “mina86” ナザレヴイツ  (o o)
ooo +--<mpn at google.com>--<xmpp:mina86 at jabber.org>--ooO--(_)--Ooo--



More information about the linux-arm-kernel mailing list