diff options
| author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-08-25 09:18:23 +0200 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-08-25 09:18:23 +0200 |
| commit | b71763a0a3305b685e0378b7f7a4c4c16d4c66ba (patch) | |
| tree | f8677c6fd61abcf92f5dc30ce2029acc02f2ba91 /rust/kernel/devres.rs | |
| parent | 349a64256534aa2c73787b22f7bc0517a211cdab (diff) | |
| parent | 1b237f190eb3d36f52dffe07a40b5eb210280e00 (diff) | |
| download | linux-next-b71763a0a3305b685e0378b7f7a4c4c16d4c66ba.tar.gz linux-next-b71763a0a3305b685e0378b7f7a4c4c16d4c66ba.zip | |
Merge 6.17-rc3 into driver-core-next
We need the driver core and rust fixes in here as well to build on top
of.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'rust/kernel/devres.rs')
| -rw-r--r-- | rust/kernel/devres.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 99b7520019f0..132545962218 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -115,10 +115,11 @@ pub struct Devres<T: Send> { /// Contains all the fields shared with [`Self::callback`]. // TODO: Replace with `UnsafePinned`, once available. // - // Subsequently, the `drop_in_place()` in `Devres::drop` and the explicit `Send` and `Sync' - // impls can be removed. + // Subsequently, the `drop_in_place()` in `Devres::drop` and `Devres::new` as well as the + // explicit `Send` and `Sync' impls can be removed. #[pin] inner: Opaque<Inner<T>>, + _add_action: (), } impl<T: Send> Devres<T> { @@ -140,7 +141,15 @@ impl<T: Send> Devres<T> { dev: dev.into(), callback, // INVARIANT: `inner` is properly initialized. - inner <- { + inner <- Opaque::pin_init(try_pin_init!(Inner { + devm <- Completion::new(), + revoke <- Completion::new(), + data <- Revocable::new(data), + })), + // TODO: Replace with "initializer code blocks" [1] once available. + // + // [1] https://github.com/Rust-for-Linux/pin-init/pull/69 + _add_action: { // SAFETY: `this` is a valid pointer to uninitialized memory. let inner = unsafe { &raw mut (*this.as_ptr()).inner }; @@ -152,13 +161,13 @@ impl<T: Send> Devres<T> { // 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()) - })?; + }).inspect_err(|_| { + let inner = Opaque::cast_into(inner); - Opaque::pin_init(try_pin_init!(Inner { - devm <- Completion::new(), - revoke <- Completion::new(), - data <- Revocable::new(data), - })) + // SAFETY: `inner` is a valid pointer to an `Inner<T>` and valid for both reads + // and writes. + unsafe { core::ptr::drop_in_place(inner) }; + })?; }, }) } |
