From 2fa8caba507aca56af1b1d225043ecae1011fd3c Mon Sep 17 00:00:00 2001 From: Arthur Heymans <arthur@aheymans.xyz> Date: Tue, 25 Oct 2022 21:09:58 +0200 Subject: lib/ramdetect: Limit probe size to function argument This avoids probing above the function argument where other things than DRAM could be mapped. Change-Id: Ie7f915c6e150629eff235ee94719172467a54db2 Signed-off-by: Arthur Heymans <arthur@aheymans.xyz> Reviewed-on: https://review.coreboot.org/c/coreboot/+/68842 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: ron minnich <rminnich@gmail.com> Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com> --- src/lib/ramdetect.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/ramdetect.c b/src/lib/ramdetect.c index cfec0296e7..9a29d0fe94 100644 --- a/src/lib/ramdetect.c +++ b/src/lib/ramdetect.c @@ -57,9 +57,12 @@ size_t probe_ramsize(const uintptr_t dram_start, const size_t probe_size) msb = MIN(msb, MAX_ADDRESSABLE_SPACE); /* Compact binary search. */ - for (i = msb; i >= 0; i--) + for (i = msb; i >= 0; i--) { + if ((discovered | (1ULL << i)) > probe_size) + continue; if (probe_mb(dram_start, (discovered | (1ULL << i)))) discovered |= (1ULL << i); + } saved_result = discovered; printk(BIOS_DEBUG, "RAMDETECT: Found %zu MiB RAM\n", discovered); -- cgit v1.2.3