lib/bootmem.c: Improve bootmem_allocate_buffer algorithm

Since regions in bootmem are sorted by increasing base address, we may
bail out of the search loop as soon as the region_base is bigger than
the max address allowed.

Signed-off-by: Jan Dabros <jsd@semihalf.com>
Change-Id: I44b44bf9618fd0615103cbf74271235d61d49473
Reviewed-on: https://review.coreboot.org/c/coreboot/+/43512
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Jan Dabros 2020-07-16 13:45:49 +02:00 committed by Angel Pons
parent 1756e10a34
commit 821b1e2f28
1 changed files with 3 additions and 3 deletions

View File

@ -231,15 +231,15 @@ void *bootmem_allocate_buffer(size_t size)
size = ALIGN(size, 4096);
region = NULL;
memranges_each_entry(r, &bootmem) {
if (range_entry_base(r) >= max_addr)
break;
if (range_entry_size(r) < size)
continue;
if (range_entry_tag(r) != BM_MEM_RAM)
continue;
if (range_entry_base(r) >= max_addr)
continue;
end = range_entry_end(r);
if (end > max_addr)
end = max_addr;