summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Lourenco <klourencodev@gmail.com>2025-12-29 17:13:21 +0100
committerMike Rapoport (Microsoft) <rppt@kernel.org>2026-01-09 11:53:51 +0200
commitf56ccc32468ee7885d3a9175e7d2cb608d301521 (patch)
tree65e1b0a398d3949843c6abeae1c982293dd2b497
parent58e3e5265484a1bf39569903630a45a924621aaa (diff)
mm/memtest: add underflow detection for size calculation
The computation: end = start + (size - (start_phys_aligned - start_phys)) / incr could theoretically underflow if size < offset, leading to a massive iteration. Add VM_WARN_ON_ONCE() to detect cases where the region size is smaller than the alignment offset. While this should never happen in practice due to memblock guarantees, the warning helps catch potential bugs in early memory initialization code. Suggested-by: Mike Rapoport <rppt@kernel.org> Signed-off-by: Kevin Lourenco <klourencodev@gmail.com> Link: https://patch.msgid.link/20251229161321.9079-1-klourencodev@gmail.com Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
-rw-r--r--mm/memtest.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/mm/memtest.c b/mm/memtest.c
index c2c609c39119..520d41534cfa 100644
--- a/mm/memtest.c
+++ b/mm/memtest.c
@@ -50,6 +50,8 @@ static void __init memtest(u64 pattern, phys_addr_t start_phys, phys_addr_t size
start_bad = 0;
last_bad = 0;
+ VM_WARN_ON_ONCE(size < start_phys_aligned - start_phys);
+
for (p = start; p < end; p++)
WRITE_ONCE(*p, pattern);