[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zw64XYHtjGmbnfTO@boqun-archlinux>
Date: Tue, 15 Oct 2024 11:45:49 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Alice Ryhl <alice@...l.io>
Cc: Alice Ryhl <aliceryhl@...gle.com>,
Christian Brauner <brauner@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>,
Alexander Viro <viro@...iv.linux.org.uk>, Jan Kara <jack@...e.cz>,
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>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, linux-fsdevel@...r.kernel.org,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: task: adjust safety comments in Task methods
On Tue, Oct 15, 2024 at 08:37:36PM +0200, Alice Ryhl wrote:
> On 10/15/24 8:24 PM, Boqun Feng wrote:
> > On Tue, Oct 15, 2024 at 02:02:12PM +0000, Alice Ryhl wrote:
> > > The `Task` struct has several safety comments that aren't so great. For
> > > example, the reason that it's okay to read the `pid` is that the field
> > > is immutable, so there is no data race, which is not what the safety
> > > comment says.
> > >
> > > Thus, improve the safety comments. Also add an `as_ptr` helper. This
> > > makes it easier to read the various accessors on Task, as `self.0` may
> > > be confusing syntax for new Rust users.
> > >
> > > Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
> > > ---
> > > This is based on top of vfs.rust.file as the file series adds some new
> > > task methods. Christian, can you take this through that tree?
> > > ---
> > > rust/kernel/task.rs | 43 ++++++++++++++++++++++++-------------------
> > > 1 file changed, 24 insertions(+), 19 deletions(-)
> > >
> > > diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> > > index 1a36a9f19368..080599075875 100644
> > > --- a/rust/kernel/task.rs
> > > +++ b/rust/kernel/task.rs
> > > @@ -145,11 +145,17 @@ fn deref(&self) -> &Self::Target {
> > > }
> > > }
> > > + /// Returns a raw pointer to the task.
> > > + #[inline]
> > > + pub fn as_ptr(&self) -> *mut bindings::task_struct {
> >
> > FWIW, I think the name convention is `as_raw()` for a wrapper type of
> > `Opaque<T>` to return `*mut T`, e.g. `kernel::device::Device`.
> >
> > Otherwise this looks good to me.
> Both names are in use. See e.g. Page and File that use as_ptr.
>
`Page` is a different case because it currently is a pointer.
> In fact, I was asked to change the name on File *to* as_ptr.
>
I'm not able to find the discussion on that ask. Appreciate it if you
can share a link.
Anyway, this is not important for now, and might not be in the future.
So:
Reviewed-by: Boqun Feng <boqun.feng@...il.com>
Regards,
Boqun
> Alice
Powered by blists - more mailing lists