Re: [PATCH v1] rust: workqueue: add cancel_sync support
From: Danilo Krummrich
Date: Fri May 22 2026 - 09:25:09 EST
On Sun May 10, 2026 at 10:21 AM CEST, Onur Özkan wrote:
> Drivers can use this during teardown to cancel pending work and wait for
> running work to finish before dropping related resources.
If you need this for driver teardown and the work uses device resources, you
should rather create a new type of work that internally synchronizes with driver
unbind.
This also allows you to provide a &Device<Bound> within the work function itself
directly.
Instead you now have to fall back to unsafe code in your work callback
implementation making it a driver responsibility to call cancel_sync() at the
correct point of time:
// SAFETY: `Controller` is part of driver-private data and only exists
// while the platform device is bound.
let pdev = unsafe { self.pdev.as_ref().as_bound() };
I already mentioned this a couple of times in the past that we want "managed"
work for drivers for this exact reason.
More in general, please don't use Device::as_bound() from driver code; if it is
needed it implies a design issue or that we're missing a proper solution.