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

Miguel Ojeda
2025-03-27T21:27:46Z

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.

> +/// # Examples
> +/// ```

(Multiple instances) Newline between these.

> +/// use kernel::bits::genmask_u64;

(Multiple instances) You can hide this one with `#` -- when the `use`
is just for a single free function, I think it is not very useful to
show in the rendered docs, i.e. it is clear that you are showing that
one since the docs go with it.

> +/// let mask = genmask_u64(39, 21);
> +/// assert_eq!(mask, 0x000000ffffe00000);

(Multiple instances) The example is overindented, as if it was inside
a function.

> +///
> +pub const fn genmask_u32(h: u32, l: u32) -> u32 {

(Multiple instances) Extra `///` line.

Thanks!

Cheers,
Miguel