[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c3e8e0fc-5582-49ce-99fe-6dea37c39ddb@kernel.org>
Date: Mon, 8 Sep 2025 14:02:38 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Alexandre Courbot <acourbot@...dia.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
nouveau@...ts.freedesktop.org
Subject: Re: [PATCH v4 1/2] rust: add `Alignment` type
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 <dakr@...nel.org>
Powered by blists - more mailing lists