On 8/21/25 2:42 PM, Alexandre Courbot wrote:
> + /// Validates that `align` is a power of two at build-time, and returns
> an [`Alignment`] of the
> + /// same value.
> + ///
> + /// A build error is triggered if `align` cannot be asserted to be a
> power of two.
> + ///
> + /// # Examples
> + ///
> + /// ```
> + /// use kernel::ptr::Alignment;
> + ///
> + /// let v = Alignment::new(16);
> + /// assert_eq!(v.as_usize(), 16);
> + /// ```
> + #[inline(always)]
> + pub const fn new(align: usize) -> Self {
> + build_assert!(align.is_power_of_two());
> +
> + // INVARIANT: `align` is a power of two.
> + // SAFETY: `align` is a power of two, and thus non-zero.
> + Self(unsafe { NonZero::new_unchecked(align) })
> + }
For DmaMask::new() we used a const generic instead, which makes it more obvious
to the caller that the argument must be known at compile time. So, I'd prefer
this here as well.
Either way,
Reviewed-by: Danilo Krummrich <[email protected]>