devm_work_autocancel(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… devm_work_autocancel πŸ’…

okay so bestie, this is a page from the Kernel API Manual and it's literally about not leaking your workqueue stuff when your driver dips out. no cap, it's a glow-up for cleanup code.


✨ NAME ✨

devm_work_autocancel β€” resource-managed work allocation πŸŽ€

πŸ¦‹ SYNOPSIS πŸ¦‹

int devm_work_autocancel (struct device *dev , struct work_struct *w ,
       work_func_t worker );

like, that's the whole vibe. three args, one int back. slay.

🌸 ARGUMENTS 🌸

  • dev β€” the Device your work's whole lifetime is bound to 🫢 like it's literally tethered to this thing's existence.
  • w β€” the Work to be added (and, key detail, automatically cancelled πŸ’…). yes bestie, the auto-cancel is the whole point.
  • worker β€” the Worker function, aka the main character that actually does the thing πŸ”₯

πŸ‘‘ DESCRIPTION πŸ‘‘

okay so here's the tea πŸ“: this initializes work that gets automatically cancelled when the driver is detached. iconic behavior, honestly.

a few drivers need to queue work which must be cancelled before the driver is detached β€” otherwise you're out here accessing removed resources and it's giving πŸ’€ undefined chaos, we don't want that.

devm_work_autocancel can be used to omit the explicit cancellation when the driver is detached. so instead of you manually writing the cleanup, you just... don't. the devm machinery handles it. periodt. 🧚

no cap: the whole point is that you skip the explicit cancel-on-detach step. don't reinvent it, bestie, just let it cook.

🌈 SEE ALSO 🌈

  • Kernel file ./include/linux/devm-helpers.h β€” go read it, iykyk πŸ“–
  • devm_delayed_work_autocancel(9) β€” the delayed cousin, also iconic ✨

and that's the whole page, bestie πŸ’– this one lives in ./include/linux, it's dated October 2026, and it comes to you courtesy of the Kernel API Manual. go forth and let the kernel clean up after you πŸ«ΆπŸ’…

πŸ“¦ where this page comes from