From 6ad54d03fcc46fda723ee561c6c1f91f1dd42659 Mon Sep 17 00:00:00 2001 From: Osama Abdelkader Date: Sat, 14 Mar 2026 23:28:14 +0100 Subject: [PATCH] riscv: mm: add null check for find_vm_area in set_memory find_vm_area() can return NULL. Add a null check to avoid potential null pointer dereference, matching the pattern used by other arches. Signed-off-by: Osama Abdelkader Signed-off-by: Linux RISC-V bot --- arch/riscv/mm/pageattr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c index 3f76db3d276992..46a999c86b26e6 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -289,6 +289,10 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask, int i, page_start; area = find_vm_area((void *)start); + if (!area) { + ret = -EINVAL; + goto unlock; + } page_start = (start - (unsigned long)area->addr) >> PAGE_SHIFT; for (i = page_start; i < page_start + numpages; ++i) {