pmm: Fix sanitise_entries() bugs

This commit is contained in:
mintsuki 2021-07-25 14:18:35 +02:00
parent 2a4f9eb0c4
commit 5089bafaf8
1 changed files with 5 additions and 5 deletions

View File

@ -113,7 +113,7 @@ static bool align_entry(uint64_t *base, uint64_t *length) {
static void sanitise_entries(struct e820_entry_t *m, size_t *_count, bool align_entries) {
size_t count = *_count;
for (size_t i = 0; i < memmap_entries; i++) {
for (size_t i = 0; i < count; i++) {
if (m[i].type != MEMMAP_USABLE)
continue;
@ -151,8 +151,8 @@ static void sanitise_entries(struct e820_entry_t *m, size_t *_count, bool align_
if (!m[i].length
|| (align_entries && !align_entry(&m[i].base, &m[i].length))) {
// Eradicate from memmap
for (size_t j = i; j < count - 1; j++) {
m[j] = m[j+1];
for (size_t j = i + 1; j < count; j++) {
m[j - 1] = m[j];
}
count--;
i--;
@ -185,8 +185,8 @@ static void sanitise_entries(struct e820_entry_t *m, size_t *_count, bool align_
m[i].length += m[i+1].length;
// Eradicate from memmap
for (size_t j = i+1; j < count - 1; j++) {
m[j] = m[j+1];
for (size_t j = i + 2; j < count; j++) {
m[j - 1] = m[j];
}
count--;
i--;