[PATCH v2 3/4] rust: add Work::disable_sync

Onur Özkan
2026-04-16T17:17:43Z

Adds Work::disable_sync() as a safe wrapper for disable_work_sync().

Drivers can use this during teardown to stop new queueing and wait for
queued or running work to finish before dropping related resources.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
rust/kernel/workqueue/mod.rs | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/rust/kernel/workqueue/mod.rs b/rust/kernel/workqueue/mod.rs
index e30c21214a81..7f63d778146e 100644
--- a/rust/kernel/workqueue/mod.rs
+++ b/rust/kernel/workqueue/mod.rs
@@ -582,6 +582,21 @@ 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)) }
}
+
+ /// Disables this work item and waits for queued/running executions to finish.
+ ///
+ /// # Note
+ ///
+ /// Should be called from a sleepable context if the work was last queued on a non-BH
+ /// workqueue.
+ #[inline]
+ pub fn disable_sync(&self) {
+ let ptr: *const Self = self;
+ // SAFETY: `self` points to a valid initialized work.
+ let raw_work = unsafe { Self::raw_get(ptr) };
+ // SAFETY: `raw_work` is a valid embedded `work_struct`.
+ unsafe { bindings::disable_work_sync(raw_work) };
+ }
}

/// Declares that a type contains a [`Work<T, ID>`].
--
2.51.2