[PATCH] dma-buf: cma_heap: Fix memory leak in CMA heap

Sumit Semwal sumit.semwal at linaro.org
Sat Jan 9 03:44:14 UTC 2021


Hi John,

On Fri, 8 Jan 2021 at 01:56, John Stultz <john.stultz at linaro.org> wrote:
>
> Bing Song noticed the CMA heap was leaking memory due to a flub
> I made in commit a5d2d29e24be ("dma-buf: heaps: Move heap-helper
> logic into the cma_heap implementation"), and provided this fix
> which ensures the pagelist is also freed on release.
Thanks for your patch.
>
> Cc: Bing Song <bing.song at nxp.com>
> Cc: Sumit Semwal <sumit.semwal at linaro.org>
> Cc: Liam Mark <lmark at codeaurora.org>
> Cc: Laura Abbott <labbott at kernel.org>
> Cc: Brian Starkey <Brian.Starkey at arm.com>
> Cc: Hridya Valsaraju <hridya at google.com>
> Cc: Suren Baghdasaryan <surenb at google.com>
> Cc: Sandeep Patil <sspatil at google.com>
> Cc: Daniel Mentz <danielmentz at google.com>
> Cc: Chris Goldsworthy <cgoldswo at codeaurora.org>
> Cc: Ørjan Eide <orjan.eide at arm.com>
> Cc: Robin Murphy <robin.murphy at arm.com>
> Cc: Ezequiel Garcia <ezequiel at collabora.com>
> Cc: Simon Ser <contact at emersion.fr>
> Cc: James Jones <jajones at nvidia.com>
> Cc: linux-media at vger.kernel.org
> Cc: dri-devel at lists.freedesktop.org
> Reported-by: Bing Song <bing.song at nxp.com>
> Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> Signed-off-by: John Stultz <john.stultz at linaro.org>

I will queue it up so it gets in the v5.11 cycle.
> ---
>  drivers/dma-buf/heaps/cma_heap.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
> index 3c4e34301172..364fc2f3e499 100644
> --- a/drivers/dma-buf/heaps/cma_heap.c
> +++ b/drivers/dma-buf/heaps/cma_heap.c
> @@ -251,6 +251,9 @@ static void cma_heap_dma_buf_release(struct dma_buf *dmabuf)
>                 buffer->vaddr = NULL;
>         }
>
> +       /* free page list */
> +       kfree(buffer->pages);
> +       /* release memory */
>         cma_release(cma_heap->cma, buffer->cma_pages, buffer->pagecount);
>         kfree(buffer);
>  }
> --
> 2.17.1
>
Best,
Sumit.


More information about the dri-devel mailing list