[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <67d4c74d.050a0220.66d0.b23d@mx.google.com>
Date: Fri, 14 Mar 2025 17:18:17 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Antonio Hickey <contact@...oniohickey.com>
Cc: Andreas Hindborg <a.hindborg@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Brendan Higgins <brendan.higgins@...ux.dev>,
David Gow <davidgow@...gle.com>, Rae Moar <rmoar@...gle.com>,
FUJITA Tomonori <fujita.tomonori@...il.com>,
Bjorn Helgaas <bhelgaas@...gle.com>, linux-block@...r.kernel.org,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com,
netdev@...r.kernel.org, linux-pci@...r.kernel.org
Subject: Re: [PATCH v3 2/3] rust: replace `addr_of[_mut]!` with `&raw [mut]`
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.
[...]
Powered by blists - more mailing lists