Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iommu/iova: Add NULL check in iova_magazine_free()

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>

authored by

lynn and committed by
Joerg Roedel
fa8fb60d 199036ae

+2 -1
+2 -1
drivers/iommu/iova.c
··· 611 611 612 612 static void iova_magazine_free(struct iova_magazine *mag) 613 613 { 614 - kmem_cache_free(iova_magazine_cache, mag); 614 + if (mag) 615 + kmem_cache_free(iova_magazine_cache, mag); 615 616 } 616 617 617 618 static void