This is a note to let you know that I've just added the patch titled dma-buf: system_heap: Use 'for_each_sgtable_sg' in pages free flow to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: dma-buf-system_heap-use-for_each_sgtable_sg-in-pages-free-flow.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 679d94cd7d900871e5bc9cf780bd5b73af35ab42 Mon Sep 17 00:00:00 2001 From: Guangming <Guangming.Cao@xxxxxxxxxxxx> Date: Fri, 26 Nov 2021 15:49:04 +0800 Subject: dma-buf: system_heap: Use 'for_each_sgtable_sg' in pages free flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Guangming <Guangming.Cao@xxxxxxxxxxxx> commit 679d94cd7d900871e5bc9cf780bd5b73af35ab42 upstream. For previous version, it uses 'sg_table.nent's to traverse sg_table in pages free flow. However, 'sg_table.nents' is reassigned in 'dma_map_sg', it means the number of created entries in the DMA adderess space. So, use 'sg_table.nents' in pages free flow will case some pages can't be freed. Here we should use sg_table.orig_nents to free pages memory, but use the sgtable helper 'for each_sgtable_sg'(, instead of the previous rather common helper 'for_each_sg' which maybe cause memory leak) is much better. Fixes: d963ab0f15fb0 ("dma-buf: system_heap: Allocate higher order pages if available") Signed-off-by: Guangming <Guangming.Cao@xxxxxxxxxxxx> Reviewed-by: Robin Murphy <robin.murphy@xxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> # 5.11.* Reviewed-by: Christian König <christian.koenig@xxxxxxx> Reviewed-by: John Stultz <john.stultz@xxxxxxxxxx> Signed-off-by: Sumit Semwal <sumit.semwal@xxxxxxxxxx> Link: https://patchwork.freedesktop.org/patch/msgid/20211126074904.88388-1-guangming.cao@xxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/dma-buf/heaps/system_heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -289,7 +289,7 @@ static void system_heap_dma_buf_release( int i; table = &buffer->sg_table; - for_each_sg(table->sgl, sg, table->nents, i) { + for_each_sgtable_sg(table, sg, i) { struct page *page = sg_page(sg); __free_pages(page, compound_order(page)); Patches currently in stable-queue which might be from Guangming.Cao@xxxxxxxxxxxx are queue-5.15/dma-buf-system_heap-use-for_each_sgtable_sg-in-pages-free-flow.patch