Skip to content

Commit 68cc3ae

Browse files
authored
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.
1 parent 8a1d149 commit 68cc3ae

File tree

1 file changed

+4
-0
lines changed
  • kernel/frame_allocator/src

1 file changed

+4
-0
lines changed

โ€Žkernel/frame_allocator/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ fn check_and_add_free_region<P, R>(
196196
where P: Borrow<PhysicalMemoryRegion>,
197197
R: IntoIterator<Item = P> + Clone,
198198
{
199+
let mut area = area.clone();
199200
// This will be set to the frame that is the start of the current free region.
200201
let mut current_start = *area.start();
201202
// 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<P, R>(
229230
free_list_idx,
230231
reserved_physical_memory_areas.clone(),
231232
);
233+
area = FrameRange::new(*area.start(), current_end);
234+
// info!("Updating original region after exiting recursive function: {:X?}", area);
232235
}
233236
}
234237
}
235238

236239
let new_area = FrameRange::new(current_start, current_end);
240+
// info!("Adding new area: {:X?}", new_area);
237241
if new_area.size_in_frames() > 0 {
238242
free_list[*free_list_idx] = Some(PhysicalMemoryRegion {
239243
typ: MemoryRegionType::Free,

0 commit comments

Comments
ย (0)