Re: [PATCH v2 04/16] rust: io: register: handle one register at a time
[email protected] Wed, 05 Aug 2026 16:43:40 +0000
| Newsgroups | org.kernel.vger.linux-pci,org.freedesktop.lists.dri-devel |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The refactored `register!` macro uses a tail-recursive TT-muncher pattern, which increases macro recursion depth linearly with the number of registers defined. This can cause compilation failures (reaching rustc's recursion limit) for macro blocks defining a large number of registers. -- --- Patch [4]: [PATCH v2 04/16] rust: io: register: handle one register at a time --- commit 8ec2a5aa6d4bcb8811ecb0ce6d13218a169b562d Author: Gary Guo <[email protected]> rust: io: register: handle one register at a time This commit refactors the register! macro to match and handle one register definition at a time using a recursive pattern. It aims to simplify the rule definitions by avoiding a single catch-all repetition rule. > diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs > index d898b2b46d521..91804c1ca117d 100644 > --- a/rust/kernel/io/register.rs > +++ b/rust/kernel/io/register.rs [ ... ] > @@ -786,44 +786,25 @@ fn into_io_op(self) -> (FixedRegisterLoc<T>, T) { > /// ``` > #[macro_export] > macro_rules! register { [ ... ] > - // All the rules below are private helpers. > + () => {}; > > // Creates a register at a fixed offset of the MMIO space. > ( > - @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) @ $offset:literal > + $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) @ $offset:literal > { $($fields:tt)* } > + $($rest:tt)* > ) => { > $crate::register!(@bitfield $(#[$attr])* $vis struct $name($storage) { $($fields)* }); > $crate::register!(@io_base $name @ $offset); > $crate::register!(@io_fixed $(#[$attr])* $vis $name); > + $crate::register!($($rest)*); [Severity: Low] Does this recursive pattern increase the macro recursion depth linearly with the number of registers defined? If a single register! block contains a large number of registers, this tail recursion might exceed rustc's default recursion limit and cause compilation failures. While this can be worked around by splitting the definitions into multiple register! invocations, it is a regression compared to the previous repetition pattern. > }; -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4