[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjM4SUEmhW334w_o0Zfv3mUZ76Nz4GnE0H7N0Y=e+G5AQ@mail.gmail.com>
Date: Fri, 31 Jan 2025 10:15:54 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
Cc: peterz@...radead.org, mingo@...hat.com, will@...nel.org,
boqun.feng@...il.com, longman@...hat.com, ojeda@...nel.org,
alex.gaynor@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me, a.hindborg@...nel.org, tmgross@...ch.edu,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH] rust: sync: create the `get_mut()` function
On Thu, Jan 30, 2025 at 7:52 PM Guilherme Giacomo Simoes
<trintaeoitogc@...il.com> 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.
>
> Suggested-by: Björn Roy Baron <bjorn3_gh@...tonmail.com>
> Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@...il.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
> + pub fn get_mut(&mut self) -> &mut T {
> + // SAFETY: the caller must guarantee that the instance is only used in one place
> + unsafe { &mut *self.data.get() }
> + }
As far as I can tell, it's impossible to call this function because
you cannot obtain a bare mutable reference to a pinned value.
Alice
Powered by blists - more mailing lists