]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/iova: Add NULL check in iova_magazine_free()
authorlynn <liulynn@google.com>
Sat, 14 Feb 2026 08:09:19 +0000 (08:09 +0000)
committerJoerg Roedel <joerg.roedel@amd.com>
Tue, 17 Mar 2026 12:28:37 +0000 (13:28 +0100)
When iova_domain_init_rcaches() fails to allocate an iova_magazine
during the initialization of per-cpu rcaches, it jumps to out_err and
calls free_iova_rcaches() for cleanup.

In free_iova_rcaches(), the code iterates through all possible CPUs to
free both cpu_rcache->loaded and cpu_rcache->prev. However, if the
original allocation failed mid-way through the CPU loop, the pointers
for the remaining CPUs remain NULL.

Since kmem_cache_free() does not explicitly handle NULL pointers like
kfree() does, passing these NULL pointers leads to a kernel paging
request fault.

Add a NULL check in iova_magazine_free() to safely handle partially
initialized rcaches in error paths.

Signed-off-by: lynn <liulynn@google.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/iova.c

index f9cd18316d16b12b2f5f1777a184449ffa59b3d0..021daf6528de18a26d73ab2b8d21ad7e493f29c3 100644 (file)
@@ -611,7 +611,8 @@ static struct iova_magazine *iova_magazine_alloc(gfp_t flags)
 
 static void iova_magazine_free(struct iova_magazine *mag)
 {
-       kmem_cache_free(iova_magazine_cache, mag);
+       if (mag)
+               kmem_cache_free(iova_magazine_cache, mag);
 }
 
 static void