Re: [PATCH v3 11/16] rust: io: register: support fixed offset register without bitfield

"Alexandre Courbot" <[email protected]>
Newsgroups dev.linux.lists.nova-gpu,dev.linux.lists.driver-core,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Wed Aug 19, 2026 at 8:09 PM JST, Gary Guo wrote:
> Add a rule to allow creating `IoLoc` in `register!()` using an existing
> type and not create a bitfield. Add an example to demonstrate this for FIFO
> registers.
>
> This rule is also going to be used to create subregions for registers; the
> example of doing so will be added later when relative registers are
> removed.
>
> Signed-off-by: Gary Guo <[email protected]>

Reviewed-by: Alexandre Courbot <[email protected]>

> ---
>  rust/kernel/io/register.rs | 30 ++++++++++++++++
>  rust/macros/io/register.rs | 86 +++++++++++++++++++++++++++++++---------------
>  2 files changed, 89 insertions(+), 27 deletions(-)
>
> diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
> index f622057f7346..63c054162e54 100644
> --- a/rust/kernel/io/register.rs
> +++ b/rust/kernel/io/register.rs
> @@ -182,6 +182,23 @@ fn offset(self) -> usize {
>      }
>  }
>  
> +#[doc(hidden)]
> +pub struct OffsetLoc<Base: ?Sized, T>(usize, PhantomData<(T, Base)>);

A short comment (not doccomment) quickly explaining the purpose of this
type would be helpful to readers.

<...>
> diff --git a/rust/macros/io/register.rs b/rust/macros/io/register.rs
> index cb02e850b23f..0b4e0d1903dd 100644
> --- a/rust/macros/io/register.rs
> +++ b/rust/macros/io/register.rs
> @@ -14,9 +14,11 @@
>      bracketed,
>      parenthesized,
>      parse::Parse,
> +    parse_quote,
>      spanned::Spanned,
>      token,
>      Attribute,
> +    Error,
>      Expr,
>      Ident,
>      Path,
> @@ -49,11 +51,11 @@ struct Reg {
>      attrs: Vec<Attribute>,
>      vis: Visibility,
>      name: Ident,
> -    storage: Type,
> +    ty: Type,
>      array: Option<RegArrayDef>,
>      relative_base: Option<Path>,
>      offset: RegOffset,
> -    bitfield_args: Group,
> +    bitfield: Option<(Type, Group)>,
>  }
>  
>  impl Parse for Reg {
> @@ -61,11 +63,23 @@ fn parse(input: syn::parse::ParseStream<'_>) -> Result<Self> {
>          let attrs = input.call(Attribute::parse_outer)?;
>          let vis = input.parse()?;
>          let name = input.parse()?;
> -        let storage = {
> +
> +        let lh = input.lookahead1();
> +        let mut bitfield_storage = None;

You can avoid using `mut` if you turn the next line into `let
(bitfield_storage, ty) = ...`. The final form of the patchset already
uses a tuple due to `unique` anyway.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.