From: Boqun Feng <boqun.feng@gmail.com>
To: Antonio Hickey <contact@antoniohickey.com>
Cc: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <davidgow@google.com>, "Rae Moar" <rmoar@google.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, netdev@vger.kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 2/3] rust: replace `addr_of[_mut]!` with `&raw [mut]`
Date: Fri, 14 Mar 2025 17:18:17 -0700 [thread overview]
Message-ID: <67d4c74d.050a0220.66d0.b23d@mx.google.com> (raw)
In-Reply-To: <0100019597092d67-0da59c6d-9680-413f-bbce-109ef95724cc-000000@email.amazonses.com>
On Fri, Mar 14, 2025 at 11:41:55PM +0000, Antonio Hickey wrote:
[...]
> /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::into_raw`].
> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> index 49012e711942..b2ac768eed23 100644
> --- a/rust/kernel/task.rs
> +++ b/rust/kernel/task.rs
> @@ -257,7 +257,7 @@ pub fn as_ptr(&self) -> *mut bindings::task_struct {
> pub fn group_leader(&self) -> &Task {
> // SAFETY: The group leader of a task never changes after initialization, so reading this
> // field is not a data race.
> - let ptr = unsafe { *ptr::addr_of!((*self.as_ptr()).group_leader) };
> + let ptr = unsafe { *(&raw const (*self.as_ptr()).group_leader) };
This can be a
let ptr = unsafe { (*self.as_ptr()).group_leader };
>
> // SAFETY: The lifetime of the returned task reference is tied to the lifetime of `self`,
> // and given that a task has a reference to its group leader, we know it must be valid for
> @@ -269,7 +269,7 @@ pub fn group_leader(&self) -> &Task {
> pub fn pid(&self) -> Pid {
> // SAFETY: The pid of a task never changes after initialization, so reading this field is
> // not a data race.
> - unsafe { *ptr::addr_of!((*self.as_ptr()).pid) }
> + unsafe { *(&raw const (*self.as_ptr()).pid) }
ditto:
unsafe { (*self.as_ptr()).pid }
because `*self.as_ptr()` is a place expression and won't create
temporary references.
There are also a few clippy warnings, you can check them with CLIPPY=1.
Besides, it'll be easy to review if you can split the changes into
multiple patches. Thanks!
Regards,
Boqun
> }
>
> /// Returns the UID of the given task.
[...]
next prev parent reply other threads:[~2025-03-15 0:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250314234148.599196-1-contact@antoniohickey.com>
2025-03-14 23:41 ` [PATCH v3 1/3] rust: enable `raw_ref_op` feature Antonio Hickey
2025-03-15 9:58 ` Benno Lossin
2025-03-14 23:41 ` [PATCH v3 2/3] rust: replace `addr_of[_mut]!` with `&raw [mut]` Antonio Hickey
2025-03-15 0:18 ` Boqun Feng [this message]
2025-03-16 2:57 ` Antonio Hickey
2025-03-16 4:15 ` Boqun Feng
2025-03-15 0:23 ` Boqun Feng
2025-03-15 9:47 ` Benno Lossin
2025-03-15 12:42 ` Boqun Feng
2025-03-14 23:41 ` [PATCH v3 3/3] rust: clippy: disable `addr_of!` and `addr_of_mut` macros Antonio Hickey
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=67d4c74d.050a0220.66d0.b23d@mx.google.com \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=brendan.higgins@linux.dev \
--cc=contact@antoniohickey.com \
--cc=dakr@kernel.org \
--cc=davidgow@google.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rmoar@google.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.