lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <F7ED4635-7F50-4D92-B72B-08D000CD6E26@collabora.com>
Date: Fri, 25 Jul 2025 14:53:09 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Alexandre Courbot <acourbot@...dia.com>
Cc: Danilo Krummrich <dakr@...nel.org>,
 David Airlie <airlied@...il.com>,
 Simona Vetter <simona@...ll.ch>,
 Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
 Maxime Ripard <mripard@...nel.org>,
 Thomas Zimmermann <tzimmermann@...e.de>,
 Beata Michalska <beata.michalska@....com>,
 nouveau@...ts.freedesktop.org,
 dri-devel@...ts.freedesktop.org,
 rust-for-linux@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 12/19] gpu: nova-core: register: generate correct
 `Default` implementation



> On 18 Jul 2025, at 04:26, Alexandre Courbot <acourbot@...dia.com> wrote:
> 
> The `Default` implementation of a register should be the aggregate of
> the default values of all its fields, and not simply be zeroed.
> 
> Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
> ---
> drivers/gpu/nova-core/regs/macros.rs | 26 +++++++++++++++++++++++---
> 1 file changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/regs/macros.rs
> index 485cac806e4a6578059c657f3b31f15e361becbd..f0942dc29210f703fddd4d86b758173f75b3477a 100644
> --- a/drivers/gpu/nova-core/regs/macros.rs
> +++ b/drivers/gpu/nova-core/regs/macros.rs
> @@ -112,14 +112,14 @@ macro_rules! register {
> 
>     // All rules below are helpers.
> 
> -    // Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`, `BitOr`,
> -    // and conversion to the value type) and field accessor methods.
> +    // Defines the wrapper `$name` type, as well as its relevant implementations (`Debug`,
> +    // `Default`, `BitOr`, and conversion to the value type) and field accessor methods.
>     (@core $name:ident $(, $comment:literal)? { $($fields:tt)* }) => {
>         $(
>         #[doc=$comment]
>         )?
>         #[repr(transparent)]
> -        #[derive(Clone, Copy, Default)]
> +        #[derive(Clone, Copy)]
>         pub(crate) struct $name(u32);
> 
>         impl ::core::ops::BitOr for $name {
> @@ -162,6 +162,7 @@ fn from(reg: $name) -> u32 {
>             )*
>         });
>         register!(@debug $name { $($field;)* });
> +        register!(@default $name { $($field;)* });
>     };
> 
>     // Defines all the field getter/methods methods for `$name`.
> @@ -321,6 +322,25 @@ fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
>         }
>     };
> 
> +    // Generates the `Default` implementation for `$name`.
> +    (@default $name:ident { $($field:ident;)* }) => {
> +        /// Returns a value for the register where all fields are set to their default value.
> +        impl ::core::default::Default for $name {
> +            fn default() -> Self {
> +                #[allow(unused_mut)]
> +                let mut value = Self(Default::default());
> +
> +                ::kernel::macros::paste!(
> +                $(
> +                value.[<set_ $field>](Default::default());
> +                )*
> +                );
> +
> +                value
> +            }
> +        }
> +    };
> +
>     // Generates the IO accessors for a fixed offset register.
>     (@io $name:ident @ $offset:expr) => {
>         #[allow(dead_code)]
> 
> -- 
> 2.50.1
> 
> 

Also very neat.

Reviewed-by: Daniel Almeida <daniel.almeida@...labora.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ