[PATCH] drivers: dma-coherent: free memory when failed to init DMA memory pool
Duan Andy
fugang.duan at freescale.com
Thu Dec 3 05:54:05 PST 2015
From: Mike Nazarewicz <mpn at google.com> Sent: Thursday, December 03, 2015 8:51 PM
> To: Duan Fugang-B38611; torvalds at linux-foundation.org;
> gregkh at linuxfoundation.org; m.szyprowski at samsung.com
> Cc: linux-arm-kernel at lists.infradead.org; arnd at arndb.de;
> iamjoonsoo.kim at lge.com; Duan Fugang-B38611
> Subject: Re: [PATCH] drivers: dma-coherent: free memory when failed to
> init DMA memory pool
>
> 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.
>
Kfree() will check mem NULL condition, so no need to add check in here.
> > 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