Skip to content

Commit a556cfe

Browse files
yunfeimmwilldeacon
authored andcommitted
iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure
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. Fixes: 29859ae ("iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE") Signed-off-by: Yunfei Wang <[email protected]> Cc: <[email protected]> # 5.10.* Acked-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 17d9a4b commit a556cfe

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/iommu/io-pgtable-arm-v7s.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
246246
__GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
247247
else if (lvl == 2)
248248
table = kmem_cache_zalloc(data->l2_tables, gfp);
249+
250+
if (!table)
251+
return NULL;
252+
249253
phys = virt_to_phys(table);
250254
if (phys != (arm_v7s_iopte)phys) {
251255
/* Doesn't fit in PTE */
252256
dev_err(dev, "Page table does not fit in PTE: %pa", &phys);
253257
goto out_free;
254258
}
255-
if (table && !cfg->coherent_walk) {
259+
if (!cfg->coherent_walk) {
256260
dma = dma_map_single(dev, table, size, DMA_TO_DEVICE);
257261
if (dma_mapping_error(dev, dma))
258262
goto out_free;

0 commit comments

Comments
 (0)