Re: [PATCH v4 4/7] rust: workqueue: add helper for defining work_struct fields

From: Alice Ryhl
Date: Wed Sep 06 2023 - 05:57:39 EST


Benno Lossin <benno.lossin@xxxxxxxxx> writes:
>> +impl<T: ?Sized, const ID: u64> Work<T, ID> {
>> + /// Creates a new instance of [`Work`].
>> + #[inline]
>> + #[allow(clippy::new_ret_no_self)]
>> + pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl PinInit<Self>
>> + where
>> + T: WorkItem<ID>,
>> + {
>> + // SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work
>> + // item function.
>> + unsafe {
>> + kernel::init::pin_init_from_closure(move |slot| {
>> + let slot = Self::raw_get(slot);
>> + bindings::init_work_with_key(
>> + slot,
>> + Some(T::Pointer::run),
>> + false,
>> + name.as_char_ptr(),
>> + key.as_ptr(),
>> + );
>> + Ok(())
>> + })
>> + }
>
> I would suggest this instead:
> ```
> pin_init!(Self {
> // SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the
> // work item function.
> work <- Opaque::ffi_init(|slot| unsafe {
> bindings::init_work_with_key(
> slot,
> Some(T::Pointer::run),
> false,
> name.as_char_ptr(),
> key.as_ptr(),
> )
> }),
> _inner: PhantomData,
> })
> ```

I thought that I changed this in this patchset ...

Anyway, I don't think it's a big deal. If I need to send a v5 for some
other reason, then I will fix this there. Otherwise, I don't think it's
necessary to send a v5 just for this.

Alice