All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: boqun.feng@gmail.com
Cc: a.hindborg@kernel.org, alex.gaynor@gmail.com,
	aliceryhl@google.com, benno.lossin@proton.me,
	bjorn3_gh@protonmail.com, gary@garyguo.net,
	linux-kernel@vger.kernel.org, longman@redhat.com,
	mingo@redhat.com, ojeda@kernel.org, peterz@infradead.org,
	rust-for-linux@vger.kernel.org, tmgross@umich.edu,
	trintaeoitogc@gmail.com, will@kernel.org
Subject: Re: [PATCH] rust: sync: create the `get_mut()` function
Date: Fri, 31 Jan 2025 13:02:35 -0300	[thread overview]
Message-ID: <20250131160235.305557-1-trintaeoitogc@gmail.com> (raw)
In-Reply-To: <Z5vrhpp9Idc3tiUy@boqun-archlinux>

Boqun Feng <boqun.feng@gmail.com> wrotes:
> 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

Ok, I make this changes and sent a new patch:

https://lore.kernel.org/all/20250131155940.305403-1-trintaeoitogc@gmail.com

Thanks,
Guilherme

  reply	other threads:[~2025-01-31 16:02 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
2025-01-31 16:02   ` Guilherme Giacomo Simoes [this message]
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=20250131160235.305557-1-trintaeoitogc@gmail.com \
    --to=trintaeoitogc@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=boqun.feng@gmail.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=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 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.