Commit f56ccc32 authored by Kevin Lourenco's avatar Kevin Lourenco Committed by Mike Rapoport (Microsoft)
Browse files

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: default avatarMike Rapoport <rppt@kernel.org>
Signed-off-by: default avatarKevin Lourenco <klourencodev@gmail.com>
Link: https://patch.msgid.link/20251229161321.9079-1-klourencodev@gmail.com


Signed-off-by: default avatarMike Rapoport (Microsoft) <rppt@kernel.org>
parent 58e3e526
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);