From: Daniel Almeida <daniel.almeida@collabora.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
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" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Fiona Behrens" <me@kloenk.dev>
Subject: Re: [PATCH v5] rust: kernel: add support for bits/genmask macros
Date: Tue, 13 May 2025 15:52:12 -0300 [thread overview]
Message-ID: <8998B971-BB46-4624-8077-5C85FE5FA97A@collabora.com> (raw)
In-Reply-To: <CANiq72kkgBtEWNQtu_tZpUYC+b-_3RsnWFO2biHPB74mrKE=AQ@mail.gmail.com>
Hi Miguel,
> On 27 Mar 2025, at 18:27, Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
>
> Hi Daniel,
>
> My usual docs-only review... I hope that helps!
>
> On Wed, Mar 26, 2025 at 3:07 PM Daniel Almeida
> <daniel.almeida@collabora.com> wrote:
>>
>> +/// Equivalent to the kernel's `BIT` macro.
>
> "To the C `BIT` macro" or "The C side ..." or similar -- these one
> would be also the kernel's :)
>
>> +/// Create a contiguous bitmask starting at bit position `l` and ending at
>> +/// position `h`, where `h >= l`.
>
> The first paragraph is a "short description" / title -- you may want
> to leave the details to a second sentence, i.e. in a second paragraph.
> Please check in any case how it looks in the rendered docs -- it may
> be fine to have all in the title.
>
> In fact, given you `assert!`, we should probably mention that very
> prominently e.g. in a `# Panics` section. Or, better, avoid the panics
> to begin with if it makes sense.
I have been staring at this for a little while.
I wonder what is everyone's opinions on an extra set of:
// e.g.: for u32
const fn const_genmask_u32<const H: u32, const L: u32>() -> u32 {
crate::build_assert!(H >= L);
...
}
..on top of the current genmask functions we already have?
This lets us move the checks to compile time for most cases, because for the
majority of users, h and l are simply integer literals.
For the rest, we can probably modify the current functions:
fn genmask_u32(h: u32, l: u32) -> Result<u32> {
if(h < l) {
return Err(EINVAL);
}
..
}
The implementation can probably be shared by using macros like kernel::io::Io,
for example, and the panics would be gone.
— Daniel
next prev parent reply other threads:[~2025-05-13 18:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 14:06 Daniel Almeida
2025-03-27 21:27 ` Miguel Ojeda
2025-05-13 18:52 ` Daniel Almeida [this message]
2025-05-19 17:57 ` Miguel Ojeda
2025-05-22 5:01 ` Alexandre Courbot
2025-05-21 7:53 ` Alexandre Courbot
2025-05-22 3:17 ` Alexandre Courbot
2025-05-22 8:21 ` Miguel Ojeda
2025-05-22 8:23 ` Alexandre Courbot
2025-05-22 8:37 ` Miguel Ojeda
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=8998B971-BB46-4624-8077-5C85FE5FA97A@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--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=me@kloenk.dev \
--cc=miguel.ojeda.sandonis@gmail.com \
--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
all inboxes | Powered by JetHome®