[PATCH] arm: dma-mapping: don't call folio_next() beyond the requested region

From: Marek Szyprowski
Date: Thu Aug 10 2023 - 06:12:54 EST


Add a check for the non-zero offset case to avoid calling folio_next()
beyond the requested region and relying on its parameters.

Fixes: cc24e9c0895c ("arm: implement the new page table range API")
Signed-off-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
Suggested-by: Matthew Wilcox <willy@xxxxxxxxxxxxx>
---
arch/arm/mm/dma-mapping.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 0474840224d9..6c952d6899f2 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -715,6 +715,8 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off,

if (offset) {
left -= folio_size(folio) - offset;
+ if (left <= 0)
+ return;
folio = folio_next(folio);
}

--
2.34.1