devm_request_threaded_irq(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸŽ€ devm_request_threaded_irq(9) β€” from the Kernel API Manual πŸ’…

okay bestie, buckle up, because this is the page you'll be pulling up every single time you wire an interrupt into a driver. this is devm_request_threaded_irq(9) (yes, the (9) means kernel API manual section, iykyk ✨) and it's the managed-device glow-up of the classic interrupt request β€” it allocates an interrupt line for a managed device and logs errors for you. main character energy fr fr 🫢


✨ SYNOPSIS ✨

int devm_request_threaded_irq (struct device *dev , unsigned int irq ,
irq_handler_t handler , irq_handler_t thread_fn , unsigned long irqflags
, const char *devname , void *dev_id );

that's the whole vibe. seven arguments, one int back, no cap πŸ‘‘


🌸 ARGUMENTS 🌸

  • dev β€” the device you're requesting the interrupt for. this is the extra one that makes it managed 🧚
  • irq β€” the interrupt line you wanna allocate.
  • handler β€” the function that gets called when the interrupt occurs. your first responder πŸ’…
  • thread_fn β€” the function called in a threaded interrupt context. pass NULL for devices that handle absolutely everything inside handler (some devices just don't need the thread, and that's valid 🌈).
  • irqflags β€” the interrupt type flags.
  • devname β€” an ascii name for the claiming device. if you pass NULL, it falls back to dev_name(dev) πŸŽ€
  • dev_id β€” a cookie that gets passed back to the handler function. yes, literally a cookie πŸ“

πŸ’– DESCRIPTION πŸ’–

so here's the tea: except for that extra dev argument, this function takes the same arguments and performs the same function as request_threaded_irq. (love a consistent API, honestly.) 🌸

the big deal, the reason you're here:

Interrupts requested with this function will be automatically freed on driver detach.

no manual cleanup, no forgetting, no 3am bug hunt. it's giving responsible adult energy πŸ‘‘

but β€” and hear me out β€” if an interrupt allocated with this function ever needs to be freed separately, you must use devm_free_irq. don't get creative, bestie πŸ™ˆ

and the part everyone skips: when the request fails, an error message is already printed with all the contextual info β€” device name, interrupt number, handler functions, and the error code. so don't add extra error messages at the call sites. it's already handled. it ate. let it cook πŸ’€


⭐ RETURN ⭐

0 on success, or a negative error number. that's it, that's the whole personality.


πŸ¦‹ SEE ALSO πŸ¦‹

kernel file ./kernel/irq/devres.c β€” that's where the magic lives, go read it πŸ’œ


and that's the page!! 🫢 sign-off time: this cutie lives in ./kernel/irq, dated October 2026, and its whole name in the manual is devm_request_threaded_irq(9) β€” remember it, cite it, love it πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from