Thread (1 message) 1 message, 1 author, 2021-12-07

Re: [PATCH] iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure

From: Will Deacon <will@kernel.org>
Date: 2021-12-07 09:48:30
Also in: linux-iommu, linux-mediatek, lkml

On Tue, Dec 07, 2021 at 10:47:22AM +0800, yf.wang@mediatek.com wrote:
quoted hunk
From: Yunfei Wang <redacted>

In __arm_v7s_alloc_table function:
iommu call kmem_cache_alloc to allocate page table, this function
allocate memory may fail, when kmem_cache_alloc fails to allocate
table, call virt_to_phys will be abnomal and return unexpected phys
and goto out_free, then call kmem_cache_free to release table will
trigger KE, __get_free_pages and free_pages have similar problem,
so add error handle for page table allocation failure.

Signed-off-by: Yunfei Wang <redacted>
---
 drivers/iommu/io-pgtable-arm-v7s.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
index bfb6acb651e5..d84240308f4b 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -246,6 +246,12 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
 			__GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
 	else if (lvl == 2)
 		table = kmem_cache_zalloc(data->l2_tables, gfp);
+
+	if (!table) {
+		dev_err(dev, "Page table allocation failure lvl:%d\n", lvl);
I'd expect the allocator to shout loudly on failure anyway, so I don't think
we need to print another message here.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help