[PATCH] ARM: dma-mapping: Fix wrong free function in __iommu_alloc_simple() error path

From: lirongqing

Date: Fri Jun 26 2026 - 06:12:44 EST


From: Li RongQing <lirongqing@xxxxxxxxx>

In __iommu_alloc_simple(), when IOMMU mapping creation fails, the error
path unconditionally called __free_from_pool() regardless of the
allocation path taken.

For the COHERENT case, memory is allocated via __alloc_simple_buffer(),
which does not use the atomic pool. Calling __free_from_pool() on such
memory silently returns without freeing, causing a page memory leak.

Fix this by matching the free function to the allocation path:
- COHERENT: use __dma_free_buffer(virt_to_page(addr), size)
- non-COHERENT: use __free_from_pool(addr, size)

Fixes: 565068221b905 ("ARM: 8561/4: dma-mapping: Fix the coherent case when iommu is used")
Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
arch/arm/mm/dma-mapping.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f9bc53b..55d3d3b 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1056,7 +1056,10 @@ static void *__iommu_alloc_simple(struct device *dev, size_t size, gfp_t gfp,
return addr;

err_mapping:
- __free_from_pool(addr, size);
+ if (coherent_flag == COHERENT)
+ __dma_free_buffer(virt_to_page(addr), size);
+ else
+ __free_from_pool(addr, size);
return NULL;
}

--
2.9.4