@@ -111,7 +111,7 @@ impl BuddyAllocatorCore {
111111 let page = & mut * self . pages . add ( pfn) ;
112112 page. flags . insert ( PageFlags :: FREE ) ;
113113 page. order = order as u8 ;
114- self . free_lists [ order] . push ( page) ;
114+ unsafe { self . free_lists [ order] . push ( page) ; }
115115
116116 pfn += 1 << order;
117117 }
@@ -134,7 +134,10 @@ impl BuddyAllocatorCore {
134134 }
135135
136136 for o in search_order..=MAX_ORDER {
137- let page_ptr = self . free_lists [ o] . pop ( ) ?;
137+ let page_ptr = match unsafe { self . free_lists [ o] . pop ( ) } {
138+ Some ( p) => p,
139+ None => continue ,
140+ } ;
138141 let mut current_order = o;
139142
140143 while current_order > order {
@@ -143,7 +146,7 @@ impl BuddyAllocatorCore {
143146 let buddy = unsafe { & mut * self . page_at_mut ( buddy_pfn) } ;
144147 buddy. flags . insert ( PageFlags :: FREE ) ;
145148 buddy. order = current_order as u8 ;
146- self . free_lists [ current_order] . push ( buddy) ;
149+ unsafe { self . free_lists [ current_order] . push ( buddy) ; }
147150 }
148151
149152 let page = unsafe { & mut * page_ptr } ;
@@ -202,7 +205,8 @@ impl BuddyAllocatorCore {
202205 self . base_addr + ( pfn << PAGE_SHIFT )
203206 }
204207
205- fn page_at_mut ( & mut self , pfn : usize ) -> * mut Page {
208+ /// Get a mutable pointer to the `Page` descriptor for `pfn`.
209+ pub ( crate ) fn page_at_mut ( & mut self , pfn : usize ) -> * mut Page {
206210 debug_assert ! ( pfn < self . total_pages) ;
207211 unsafe { self . pages . add ( pfn) }
208212 }
@@ -215,7 +219,8 @@ impl BuddyAllocatorCore {
215219 let mut node = self . free_lists [ order] . peek ( ) ;
216220 while let Some ( ptr) = node {
217221 count += 1 ;
218- node = unsafe { ( * ptr) . list . next } ;
222+ let next = unsafe { ( * ptr) . list . next } ;
223+ node = if next. is_null ( ) { None } else { Some ( next) } ;
219224 }
220225 free_pages += count * ( 1 << order) ;
221226 }
0 commit comments