rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: Asahi Lina <lina@asahilina.net>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: init: Implement Zeroable::zeroed()
Date: Sat, 15 Jul 2023 09:58:48 +0000	[thread overview]
Message-ID: <KGzE8bKBnwN0hJkKd2Cdes4IN7iuBDbKsa9OpVt7Q_pZZRithsnP3ygISozTyGn5UmfrOcd-11ZQ-vElMwrma6sozkXF3t8Jl7DKhdc2TGA=@proton.me> (raw)
In-Reply-To: <20230714-zeroed-v1-1-494d6820d61b@asahilina.net>

> By analogy to Default::default(), this just returns the zeroed
> representation of the type directly. init::zeroed() is the version that
> returns an initializer.
> 
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
>  rust/kernel/init.rs | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
> index b4332a4ec1f4..c300ce39ac10 100644
> --- a/rust/kernel/init.rs
> +++ b/rust/kernel/init.rs
> @@ -1354,7 +1354,14 @@ pub unsafe trait PinnedDrop: __internal::HasPinData {
>  /// ```rust,ignore
>  /// let val: Self = unsafe { core::mem::zeroed() };
>  /// ```
> -pub unsafe trait Zeroable {}
> +pub unsafe trait Zeroable: core::marker::Sized {

Note that `Sized` is in the prelude so you do not need the full path
`core::marker::`. Also same concern as Alice.

> +    /// Create a new zeroed T.
> +    ///
> +    /// Directly returns a zeroed T, analogous to Default::default().

Please add a link to `init::zeroed()` and explain that that is the
initializer version of this function.

> +    fn zeroed() -> Self {
> +        unsafe { core::mem::zeroed() }

Missing `SAFETY` comment.

--
Cheers,
Benno

> +    }
> +}
> 
>  /// Create a new zeroed T.
>  ///
> 
> ---
> base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
> change-id: 20230714-zeroed-dd05bc737f85
> 
> Thank you,
> ~~ Lina
> 


      parent reply	other threads:[~2023-07-15  9:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-14  9:17 [PATCH] rust: init: Implement Zeroable::zeroed() Asahi Lina
2023-07-14  9:44 ` Alice Ryhl
2023-07-15  9:58 ` Benno Lossin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='KGzE8bKBnwN0hJkKd2Cdes4IN7iuBDbKsa9OpVt7Q_pZZRithsnP3ygISozTyGn5UmfrOcd-11ZQ-vElMwrma6sozkXF3t8Jl7DKhdc2TGA=@proton.me' \
    --to=benno.lossin@proton.me \
    --cc=alex.gaynor@gmail.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=lina@asahilina.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).