Skip to content

Commit 03ec649

Browse files
y86-devfbq
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 f43cab8 commit 03ec649

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

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

0 commit comments

Comments
 (0)