From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org
Subject: Re: [PATCH v4 1/2] rust: add `Alignment` type
Date: Mon, 08 Sep 2025 21:06:08 +0900 [thread overview]
Message-ID: <DCNEM8ECAQED.1CTI4N9WE311P@nvidia.com> (raw)
In-Reply-To: <c3e8e0fc-5582-49ce-99fe-6dea37c39ddb@kernel.org>
On Mon Sep 8, 2025 at 9:02 PM JST, Danilo Krummrich wrote:
> 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.
Ah, being consistent is good, and I think I prefer the const generic as
well. Let's do the same thing here.
next prev parent reply other threads:[~2025-09-08 12:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 12:42 [PATCH v4 0/2] rust: add `Alignment` type Alexandre Courbot
2025-08-21 12:42 ` [PATCH v4 1/2] " Alexandre Courbot
2025-08-22 7:58 ` Alice Ryhl
2025-09-08 12:02 ` Danilo Krummrich
2025-09-08 12:06 ` Alexandre Courbot [this message]
2025-09-08 12:18 ` Miguel Ojeda
2025-09-08 12:36 ` Alexandre Courbot
2025-08-21 12:42 ` [PATCH v4 2/2] gpu: nova-core: use Alignment for alignment-related operations Alexandre Courbot
2025-09-08 11:55 ` [PATCH v4 0/2] rust: add `Alignment` type Alexandre Courbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DCNEM8ECAQED.1CTI4N9WE311P@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).