Skip to content

Commit 989acbf

Browse files
BennoLossinfbq
authored andcommitted
rust: workqueue: add #[pin_data] to Work
The previous two patches made it possible to add `#[pin_data]` on structs with default generic parameter values. This patch makes `Work` use `#[pin_data]` and removes an invocation of `pin_init_from_closure`. This function is intended as a low level manual escape hatch, so it is better to rely on the safe `pin_init!` macro. Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [boqun: Resolves the conflicts with doc changes]
1 parent a74e5eb commit 989acbf

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

rust/kernel/workqueue.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,10 @@ pub trait WorkItem<const ID: u64 = 0> {
342342
/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
343343
///
344344
/// [`run`]: WorkItemPointer::run
345+
#[pin_data]
345346
#[repr(transparent)]
346347
pub struct Work<T: ?Sized, const ID: u64 = 0> {
348+
#[pin]
347349
work: Opaque<bindings::work_struct>,
348350
_inner: PhantomData<T>,
349351
}
@@ -365,21 +367,22 @@ impl<T: ?Sized, const ID: u64> Work<T, ID> {
365367
where
366368
T: WorkItem<ID>,
367369
{
368-
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work
369-
// item function.
370-
unsafe {
371-
kernel::init::pin_init_from_closure(move |slot| {
372-
let slot = Self::raw_get(slot);
373-
bindings::init_work_with_key(
374-
slot,
375-
Some(T::Pointer::run),
376-
false,
377-
name.as_char_ptr(),
378-
key.as_ptr(),
379-
);
380-
Ok(())
381-
})
382-
}
370+
pin_init!(Self {
371+
work <- Opaque::ffi_init(|slot| {
372+
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as
373+
// the work item function.
374+
unsafe {
375+
bindings::init_work_with_key(
376+
slot,
377+
Some(T::Pointer::run),
378+
false,
379+
name.as_char_ptr(),
380+
key.as_ptr(),
381+
)
382+
}
383+
}),
384+
_inner: PhantomData,
385+
})
383386
}
384387

385388
/// Get a pointer to the inner `work_struct`.

0 commit comments

Comments
 (0)