Re: [PATCH v5] rust: kernel: add support for bits/genmask macros

Alexandre Courbot
2025-05-22T05:01:37Z

On Wed May 14, 2025 at 3:52 AM JST, Daniel Almeida wrote:
> 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?

Do we need to make this generic? IIUC `build_assert` should enforce that
the condition can be guaranteed at build time, even without the const
generics (which a quick test seems to confirm).