From: Boqun Feng <boqun.feng@gmail.com>
To: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
Cc: peterz@infradead.org, mingo@redhat.com, will@kernel.org,
longman@redhat.com, ojeda@kernel.org, alex.gaynor@gmail.com,
gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@kernel.org,
aliceryhl@google.com, tmgross@umich.edu,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: sync: create the `get_mut()` function
Date: Thu, 30 Jan 2025 13:13:42 -0800 [thread overview]
Message-ID: <Z5vrhpp9Idc3tiUy@boqun-archlinux> (raw)
In-Reply-To: <20250130185138.200993-1-trintaeoitogc@gmail.com>
Hi Guilherme,
Thanks for the patch. First I would prefer the title being:
rust: sync: lock: Add Lock::get_mut()
"create" is not a good word to use here, and the parentheses after
"get_mut" already says it's a function.
On Thu, Jan 30, 2025 at 03:51:38PM -0300, Guilherme Giacomo Simoes wrote:
> Create a `get_mut()` function that receive a mutable instance of Lock,
> and return a mutable reference to data because if the instance is
> mutable, the rust compiler guarantee the access control.
>
This commit log doesn't include "why we need this", so please add the
reason or the usage of this function, maybe you or someone need it
because of some initialization/setup code after creating a lock
protected object? Moreover...
> Suggested-by: Björn Roy Baron <bjorn3_gh@protonmail.com>
> Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
> ---
> rust/kernel/sync/lock.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index eb80048e0110..3f9d78bcb37c 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -140,6 +140,12 @@ pub fn new(t: T, name: &'static CStr, key: &'static LockClassKey) -> impl PinIni
> }),
> })
> }
> +
> + /// Get a mutable reference to data
... please provide an example of the usage in the doc.
> + pub fn get_mut(&mut self) -> &mut T {
> + // SAFETY: the caller must guarantee that the instance is only used in one place
SAFETY comments should explain why it's safe, here it's phrased like a
requirement, maybe something like:
// SAFETY: `&mut self` guarantees the exclusive access to the
// underlying data, therefore it's safe to reborrow the inner data.
Regards,
Boqun
> + unsafe { &mut *self.data.get() }
> + }
> }
>
> impl<B: Backend> Lock<(), B> {
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-01-30 21:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 18:51 [PATCH] rust: sync: create the `get_mut()` function Guilherme Giacomo Simoes
2025-01-30 21:13 ` Boqun Feng [this message]
2025-01-31 16:02 ` Guilherme Giacomo Simoes
2025-01-31 9:15 ` Alice Ryhl
2025-01-31 16:15 ` Guilherme Giacomo Simoes
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=Z5vrhpp9Idc3tiUy@boqun-archlinux \
--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=bjorn3_gh@protonmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=trintaeoitogc@gmail.com \
--cc=will@kernel.org \
/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).