[PATCH] lib/test_hmm: Check alloc_page_vma() return value

From: liuqiangneo

Date: Wed May 13 2026 - 23:24:29 EST


From: Qiang Liu <liuqiang@xxxxxxxxxx>

Return VM_FAULT_OOM if page allocation fails, which
avoids a NULL pointer dereference when calling lock_page().

Signed-off-by: Qiang Liu <liuqiang@xxxxxxxxxx>
---
lib/test_hmm.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index 213504915737..f8b43d6eb261 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -1063,6 +1063,8 @@ static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args,
/* Try with smaller pages if large allocation fails */
if (!dpage && order) {
dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr);
+ if (!dpage)
+ return VM_FAULT_OOM;
lock_page(dpage);
dst[i] = migrate_pfn(page_to_pfn(dpage));
dst_page = pfn_to_page(page_to_pfn(dpage));
--
2.43.0