Skip to content

Commit c83b4f0

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]
1 parent 7590718 commit c83b4f0

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
@@ -333,8 +333,10 @@ pub trait WorkItem<const ID: u64 = 0> {
333333
/// Wraps the kernel's C `struct work_struct`.
334334
///
335335
/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
336+
#[pin_data]
336337
#[repr(transparent)]
337338
pub struct Work<T: ?Sized, const ID: u64 = 0> {
339+
#[pin]
338340
work: Opaque<bindings::work_struct>,
339341
_inner: PhantomData<T>,
340342
}
@@ -356,21 +358,22 @@ impl<T: ?Sized, const ID: u64> Work<T, ID> {
356358
where
357359
T: WorkItem<ID>,
358360
{
359-
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work
360-
// item function.
361-
unsafe {
362-
kernel::init::pin_init_from_closure(move |slot| {
363-
let slot = Self::raw_get(slot);
364-
bindings::init_work_with_key(
365-
slot,
366-
Some(T::Pointer::run),
367-
false,
368-
name.as_char_ptr(),
369-
key.as_ptr(),
370-
);
371-
Ok(())
372-
})
373-
}
361+
pin_init!(Self {
362+
work <- Opaque::ffi_init(|slot| {
363+
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as
364+
// the work item function.
365+
unsafe {
366+
bindings::init_work_with_key(
367+
slot,
368+
Some(T::Pointer::run),
369+
false,
370+
name.as_char_ptr(),
371+
key.as_ptr(),
372+
)
373+
}
374+
}),
375+
_inner: PhantomData,
376+
})
374377
}
375378

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

0 commit comments

Comments
 (0)