Re: [PATCH] rust: sync: create the `get_mut()` function

From: Guilherme Giacomo Simoes
Date: Fri Jan 31 2025 - 11:16:10 EST


Alice Ryhl <aliceryhl@xxxxxxxxxx> 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