diff --git a/src/bitmap.rs b/src/bitmap.rs index 0b3e034..a765f80 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -94,16 +94,17 @@ impl PageAllocator for BitmapPageAllocator { if align_pow2 % PAGE_SIZE != 0 { return Err(AllocError::InvalidParam); } - let align_pow2 = align_pow2 / PAGE_SIZE; - if !align_pow2.is_power_of_two() { + + // Check if the base address is aligned to the given alignment and the given PAGE_SIZE. + if !crate::is_aligned(base, align_pow2) || !crate::is_aligned(base, Self::PAGE_SIZE) { return Err(AllocError::InvalidParam); } - let align_log2 = align_pow2.trailing_zeros() as usize; - // Check if the base address is aligned to the given PAGE_SIZE. - if !crate::is_aligned(base, Self::PAGE_SIZE) { + let align_pow2 = align_pow2 / PAGE_SIZE; + if !align_pow2.is_power_of_two() { return Err(AllocError::InvalidParam); } + let align_log2 = align_pow2.trailing_zeros() as usize; let idx = (base - self.base) / PAGE_SIZE;