From 68cc3aedaea621ff4f90f9ebc9ae4b6b06da4213 Mon Sep 17 00:00:00 2001 From: Ramla-I Date: Tue, 3 Sep 2024 19:21:51 -0400 Subject: [PATCH] Frame Allocator: avoid creating duplicate free regions during init (#1105) The duplicate region was created due to a bug in the `check_and_add_free_region` function: After returning from a recursive call, the original area's end frame should be updated to *not include* th region that was just added to the free list. --- kernel/frame_allocator/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/frame_allocator/src/lib.rs b/kernel/frame_allocator/src/lib.rs index a9c09425d7..428b9cdd5c 100644 --- a/kernel/frame_allocator/src/lib.rs +++ b/kernel/frame_allocator/src/lib.rs @@ -196,6 +196,7 @@ fn check_and_add_free_region( where P: Borrow, R: IntoIterator + Clone, { + let mut area = area.clone(); // This will be set to the frame that is the start of the current free region. let mut current_start = *area.start(); // This will be set to the frame that is the end of the current free region. @@ -229,11 +230,14 @@ fn check_and_add_free_region( free_list_idx, reserved_physical_memory_areas.clone(), ); + area = FrameRange::new(*area.start(), current_end); + // info!("Updating original region after exiting recursive function: {:X?}", area); } } } let new_area = FrameRange::new(current_start, current_end); + // info!("Adding new area: {:X?}", new_area); if new_area.size_in_frames() > 0 { free_list[*free_list_idx] = Some(PhysicalMemoryRegion { typ: MemoryRegionType::Free,