Skip to content

Commit b325c5a

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]> Reviewed-by: Alice Ryhl <[email protected]> Tested-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7e49a09 commit b325c5a

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
@@ -350,8 +350,10 @@ pub trait WorkItem<const ID: u64 = 0> {
350350
/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
351351
///
352352
/// [`run`]: WorkItemPointer::run
353+
#[pin_data]
353354
#[repr(transparent)]
354355
pub struct Work<T: ?Sized, const ID: u64 = 0> {
356+
#[pin]
355357
work: Opaque<bindings::work_struct>,
356358
_inner: PhantomData<T>,
357359
}
@@ -373,21 +375,22 @@ impl<T: ?Sized, const ID: u64> Work<T, ID> {
373375
where
374376
T: WorkItem<ID>,
375377
{
376-
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work
377-
// item function.
378-
unsafe {
379-
kernel::init::pin_init_from_closure(move |slot| {
380-
let slot = Self::raw_get(slot);
381-
bindings::init_work_with_key(
382-
slot,
383-
Some(T::Pointer::run),
384-
false,
385-
name.as_char_ptr(),
386-
key.as_ptr(),
387-
);
388-
Ok(())
389-
})
390-
}
378+
pin_init!(Self {
379+
work <- Opaque::ffi_init(|slot| {
380+
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as
381+
// the work item function.
382+
unsafe {
383+
bindings::init_work_with_key(
384+
slot,
385+
Some(T::Pointer::run),
386+
false,
387+
name.as_char_ptr(),
388+
key.as_ptr(),
389+
)
390+
}
391+
}),
392+
_inner: PhantomData,
393+
})
391394
}
392395

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

0 commit comments

Comments
 (0)