From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: aliceryhl@google.com
Cc: a.hindborg@kernel.org, alex.gaynor@gmail.com,
benno.lossin@proton.me, bjorn3_gh@protonmail.com,
boqun.feng@gmail.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:15:49 -0300 [thread overview]
Message-ID: <20250131161549.306073-1-trintaeoitogc@gmail.com> (raw)
In-Reply-To: <CAH5fLgjM4SUEmhW334w_o0Zfv3mUZ76Nz4GnE0H7N0Y=e+G5AQ@mail.gmail.com>
Alice Ryhl <aliceryhl@google.com> wrotes:
> 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.
So, I can call this function make anything like:
```
use kernel::sync::{new_mutex, Mutex};
struct Inner {
a: u32,
}
#[pin_data]
struct Example {
#[pin]
d: Mutex<Inner>,
}
impl Example {
fn new() -> impl PinInit<Self> {
pin_init!(Self {
// This new_mutex! can be anothers locks like new_spinlock!()
d <- new_mutex!(Inner { a: 20 })
})
}
}
let mut pin = KBox::pin_init(Example::new(), GFP_KERNEL)?;
let mut_pin = pin.as_mut();
let data = unsafe { Pin::get_unchecked_mut(mut_pin).d.get_mut() };
assert_eq!(data.a, 20);
```
Thanks,
Guilherme
prev parent reply other threads:[~2025-01-31 16:16 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
2025-01-31 9:15 ` Alice Ryhl
2025-01-31 16:15 ` Guilherme Giacomo Simoes [this message]
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=20250131161549.306073-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox