diff options
author | Danilo Krummrich <dakr@kernel.org> | 2025-09-12 20:06:56 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2025-09-12 20:07:15 +0200 |
commit | 3760401981f18c427cacea41921620806c06c4bd (patch) | |
tree | 54c77fbbaa1fc041bef2e962269b48e88ea78351 /rust/kernel | |
parent | cf4fd52e323604ccfa8390917593e1fb965653ee (diff) | |
parent | 42415d163e5df6db799c7de6262d707e402c2c7e (diff) |
Merge tag 'pin-init-v6.18' of https://github.com/Rust-for-Linux/linux into drm-rust-next
pin-init changes for v6.18
Changed:
- `#[pin_data]` now generates a `*Projection` struct similar to the
`pin-project` crate.
- Add initializer code blocks to `[try_][pin_]init!` macros: make
initializer macros accept any number of `_: {/* arbitrary code */},` &
make them run the code at that point.
- Make the `[try_][pin_]init!` macros expose initialized fields via a
`let` binding as `&mut T` or `Pin<&mut T>` for later fields.
Upstream dev news:
- Released v0.0.10 before the changes included in this tag.
- Inform users of the impending rename from `pinned-init` to `pin-init`
(in the kernel the rename already happened).
- More CI improvements.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
From: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250912174148.373530-1-lossin@kernel.org
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/devres.rs | 6 | ||||
-rw-r--r-- | rust/kernel/workqueue.rs | 9 |
2 files changed, 3 insertions, 12 deletions
diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index da18091143a6..91dbf3f4b166 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -134,11 +134,9 @@ impl<T: Send> Devres<T> { T: 'a, Error: From<E>, { - let callback = Self::devres_callback; - try_pin_init!(&this in Self { dev: dev.into(), - callback, + callback: Self::devres_callback, // INVARIANT: `inner` is properly initialized. inner <- { // SAFETY: `this` is a valid pointer to uninitialized memory. @@ -151,7 +149,7 @@ impl<T: Send> Devres<T> { // properly initialized, because we require `dev` (i.e. the *bound* device) to // live at least as long as the returned `impl PinInit<Self, Error>`. to_result(unsafe { - bindings::devm_add_action(dev.as_raw(), Some(callback), inner.cast()) + bindings::devm_add_action(dev.as_raw(), Some(*callback), inner.cast()) })?; Opaque::pin_init(try_pin_init!(Inner { diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index b9343d5bc00f..706e833e9702 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -356,18 +356,11 @@ struct ClosureWork<T> { func: Option<T>, } -impl<T> ClosureWork<T> { - fn project(self: Pin<&mut Self>) -> &mut Option<T> { - // SAFETY: The `func` field is not structurally pinned. - unsafe { &mut self.get_unchecked_mut().func } - } -} - impl<T: FnOnce()> WorkItem for ClosureWork<T> { type Pointer = Pin<KBox<Self>>; fn run(mut this: Pin<KBox<Self>>) { - if let Some(func) = this.as_mut().project().take() { + if let Some(func) = this.as_mut().project().func.take() { (func)() } } |