From abfd97b92437ae55532ca8370cd2f546d1c6816f Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 30 Dec 2023 15:29:13 +0000 Subject: [PATCH] memblock: fix bounds being ignored when iterating through total or reserved regions --- vm/memblock.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vm/memblock.c b/vm/memblock.c index cce6dbe..775fa19 100644 --- a/vm/memblock.c +++ b/vm/memblock.c @@ -311,7 +311,10 @@ int memblock_free_phys(phys_addr_t addr, size_t size) return 0; } -void __next_memory_region(struct memblock_iter *it, struct memblock_type *type_a, struct memblock_type *type_b, uintptr_t start, uintptr_t end) +void __next_memory_region( + struct memblock_iter *it, + struct memblock_type *type_a, struct memblock_type *type_b, + uintptr_t start, uintptr_t end) { unsigned int idx_a = IDX_A(it->__idx); unsigned int idx_b = IDX_B(it->__idx); @@ -323,10 +326,14 @@ void __next_memory_region(struct memblock_iter *it, struct memblock_type *type_a uintptr_t m_end = m->limit; if (!type_b) { - it->it_base = m->base; - it->it_limit = m->limit; + it->it_base = MAX(m->base, start); + it->it_limit = MIN(m->limit, end); it->it_status = m->status; + if (it->it_base >= it->it_limit) { + continue; + } + it->__idx = ITER(idx_a + 1, idx_b); return; }