Skip to content

Commit c2dfb3e

Browse files
committed
mm/pmm: fix random slots math
Signed-off-by: NOTMASTER08 <41077257+NOTMASTER08@users.noreply.github.com>
1 parent 5fb718f commit c2dfb3e

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

common/mm/pmm.s2.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ bool ext_mem_alloc_find_slot_random(uint64_t count, size_t alignment, uint64_t l
681681
uint64_t first_slot = ALIGN_UP(entry_base, alignment, continue);
682682
uint64_t last_slot = ALIGN_DOWN(entry_top - count, alignment);
683683

684-
memmap[i].slot_count = (last_slot - first_slot) / alignment;
684+
memmap[i].slot_count = (last_slot - first_slot) / alignment + 1;
685685
total_slots += memmap[i].slot_count;
686686
}
687687

@@ -700,13 +700,10 @@ bool ext_mem_alloc_find_slot_random(uint64_t count, size_t alignment, uint64_t l
700700
continue;
701701
}
702702

703-
uint64_t entry_base = memmap[i].base;
703+
uint64_t entry_top = memmap[i].base + memmap[i].length;
704704

705-
alloc_base = ALIGN_UP(entry_base, alignment,
706-
panic(false, "ext_mem_alloc_random: unreachable alignment fail"));
707-
alloc_top = ALIGN_UP(alloc_base + count, alignment,
708-
panic(false, "ext_mem_alloc_random: unreachable alignment fail"));
709-
alloc_top -= alignment * slot;
705+
alloc_top = entry_top - alignment * slot;
706+
alloc_base = ALIGN_DOWN(alloc_top - count, alignment);
710707
}
711708

712709
if (_alloc_base) {

0 commit comments

Comments
 (0)