From: Alice Ryhl <alice@ryhl.io>
To: Boqun Feng <boqun.feng@gmail.com>, Alice Ryhl <aliceryhl@google.com>
Cc: "Christian Brauner" <brauner@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jan Kara" <jack@suse.cz>, "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>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
linux-fsdevel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: task: adjust safety comments in Task methods
Date: Tue, 15 Oct 2024 20:37:36 +0200 [thread overview]
Message-ID: <23a73a6f-160d-4d06-8d45-ec77293ff258@ryhl.io> (raw)
In-Reply-To: <Zw6zZ00LOa1fkTTF@boqun-archlinux>
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@google.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.
In fact, I was asked to change the name on File *to* as_ptr.
Alice
next prev parent reply other threads:[~2024-10-15 18:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 14:02 Alice Ryhl
2024-10-15 14:06 ` Christian Brauner
2024-10-15 17:19 ` Alice Ryhl
2024-10-15 14:07 ` Christian Brauner
2024-10-15 18:24 ` Boqun Feng
2024-10-15 18:37 ` Alice Ryhl [this message]
2024-10-15 18:45 ` Boqun Feng
2024-10-15 18:53 ` Alice Ryhl
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=23a73a6f-160d-4d06-8d45-ec77293ff258@ryhl.io \
--to=alice@ryhl.io \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=gary@garyguo.net \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®