On Tue Aug 12, 2025 at 1:15 AM CEST, Danilo Krummrich wrote:
On Tue Aug 12, 2025 at 12:45 AM CEST, Benno Lossin wrote:
On Mon Aug 11, 2025 at 11:44 PM CEST, Danilo Krummrich wrote: One solution would be to use `pin_chain` on the initializer for `Inner` (not opaque). Another one would be to not use opaque, `UnsafePinned` actually looks like the better fit for this use-case.
Yeah, the problem should go away with UnsafePinned. Maybe, until we have it, we can just do the following:
diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index bfccf4177644..1981201fa7f9 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -161,6 +161,9 @@ pub fn new<'a, E>( // 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(|_| {
// SAFETY: `inner` is valid for dropping.
unsafe { core::ptr::drop_in_place(inner) };
Yeah that works too. Though I'd add a comment & improve the safety comment.
--- Cheers, Benno