Re: [PATCH 6/7] rust: workqueue: add Work::cancel_work_sync()
From: Onur Özkan
Date: Fri Aug 07 2026 - 03:52:42 EST
On Tue, 04 Aug 2026 21:52:08 +0200
Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
> Add a method to cancel a work item and wait for it to finish if it is
> currently running.
>
> This will also be used by ScopedWork's destructor to synchronously
> cancel work before dropping borrowed data.
>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> rust/kernel/workqueue/mod.rs | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/rust/kernel/workqueue/mod.rs b/rust/kernel/workqueue/mod.rs
> index 5de88c59b2e5..2b87f935712a 100644
> --- a/rust/kernel/workqueue/mod.rs
> +++ b/rust/kernel/workqueue/mod.rs
> @@ -585,6 +585,14 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct {
> // the compiler does not complain that the `work` field is unused.
> unsafe { Opaque::cast_into(core::ptr::addr_of!((*ptr).work)) }
> }
> +
> + /// Cancels the work item and waits for it to finish if it is running.
> + ///
> + /// Returns `true` if the work was pending, `false` otherwise.
> + pub fn cancel_work_sync(&self) -> bool {
> + // SAFETY: We have a reference to a valid, initialized Work, so the pointer is valid.
> + unsafe { bindings::cancel_work_sync(Self::raw_get(self)) }
> + }
> }
We can't directly add cancel_sync support to every work items. Perhaps you could
pull the exiting effort for `cancel_sync` support [1] which is also used by the
tyr reset implementation [2]?
[1]: https://lore.kernel.org/all/20260617131731.145337-2-work@xxxxxxxxxxxxx
[2]: https://lore.kernel.org/all/20260708114358.957305-1-work@xxxxxxxxxxxxx
>
> /// Declares that a type contains a [`Work<T, ID>`].
> --
> 2.55.0
>