[PATCH] rust: irq: move 'static bounds to traits

From: Alice Ryhl

Date: Thu Feb 19 2026 - 04:13:00 EST


The 'static bound is required by all irq handlers, so it is simpler to
specify it on the trait declaration instead of repeating it every time
the trait is used as a where clause. Note that we already list Sync on
the trait bound for the same reason.

Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
Follow up to:
https://lore.kernel.org/all/20260214092740.3201946-1-lossin@xxxxxxxxxx/
---
rust/kernel/irq/request.rs | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/rust/kernel/irq/request.rs b/rust/kernel/irq/request.rs
index 2ceeaeb0543a4ef0d4f25ca600dc4770f97085c5..e207707156094b1bbf1af0292cff8ed27ea64207 100644
--- a/rust/kernel/irq/request.rs
+++ b/rust/kernel/irq/request.rs
@@ -27,7 +27,7 @@ pub enum IrqReturn {
}

/// Callbacks for an IRQ handler.
-pub trait Handler: Sync {
+pub trait Handler: Sync + 'static {
/// The hard IRQ handler.
///
/// This is executed in interrupt context, hence all corresponding
@@ -45,7 +45,7 @@ fn handle(&self, device: &Device<Bound>) -> IrqReturn {
}
}

-impl<T: ?Sized + Handler, A: Allocator> Handler for Box<T, A> {
+impl<T: ?Sized + Handler, A: Allocator + 'static> Handler for Box<T, A> {
fn handle(&self, device: &Device<Bound>) -> IrqReturn {
T::handle(self, device)
}
@@ -182,7 +182,7 @@ pub fn irq(&self) -> u32 {
///
/// * We own an irq handler whose cookie is a pointer to `Self`.
#[pin_data]
-pub struct Registration<T: Handler + 'static> {
+pub struct Registration<T: Handler> {
#[pin]
inner: Devres<RegistrationInner>,

@@ -195,7 +195,7 @@ pub struct Registration<T: Handler + 'static> {
_pin: PhantomPinned,
}

-impl<T: Handler + 'static> Registration<T> {
+impl<T: Handler> Registration<T> {
/// Registers the IRQ handler with the system for the given IRQ number.
pub fn new<'a>(
request: IrqRequest<'a>,
@@ -261,10 +261,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
/// # Safety
///
/// This function should be only used as the callback in `request_irq`.
-unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>(
- _irq: i32,
- ptr: *mut c_void,
-) -> c_uint {
+unsafe extern "C" fn handle_irq_callback<T: Handler>(_irq: i32, ptr: *mut c_void) -> c_uint {
// SAFETY: `ptr` is a pointer to `Registration<T>` set in `Registration::new`
let registration = unsafe { &*(ptr as *const Registration<T>) };
// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq
@@ -288,7 +285,7 @@ pub enum ThreadedIrqReturn {
}

/// Callbacks for a threaded IRQ handler.
-pub trait ThreadedHandler: Sync {
+pub trait ThreadedHandler: Sync + 'static {
/// The hard IRQ handler.
///
/// This is executed in interrupt context, hence all corresponding
@@ -319,7 +316,7 @@ fn handle_threaded(&self, device: &Device<Bound>) -> IrqReturn {
}
}

-impl<T: ?Sized + ThreadedHandler, A: Allocator> ThreadedHandler for Box<T, A> {
+impl<T: ?Sized + ThreadedHandler, A: Allocator + 'static> ThreadedHandler for Box<T, A> {
fn handle(&self, device: &Device<Bound>) -> ThreadedIrqReturn {
T::handle(self, device)
}
@@ -403,7 +400,7 @@ fn handle_threaded(&self, device: &Device<Bound>) -> IrqReturn {
///
/// * We own an irq handler whose cookie is a pointer to `Self`.
#[pin_data]
-pub struct ThreadedRegistration<T: ThreadedHandler + 'static> {
+pub struct ThreadedRegistration<T: ThreadedHandler> {
#[pin]
inner: Devres<RegistrationInner>,

@@ -416,7 +413,7 @@ pub struct ThreadedRegistration<T: ThreadedHandler + 'static> {
_pin: PhantomPinned,
}

-impl<T: ThreadedHandler + 'static> ThreadedRegistration<T> {
+impl<T: ThreadedHandler> ThreadedRegistration<T> {
/// Registers the IRQ handler with the system for the given IRQ number.
pub fn new<'a>(
request: IrqRequest<'a>,
@@ -483,7 +480,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
/// # Safety
///
/// This function should be only used as the callback in `request_threaded_irq`.
-unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>(
+unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>(
_irq: i32,
ptr: *mut c_void,
) -> c_uint {
@@ -499,10 +496,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
/// # Safety
///
/// This function should be only used as the callback in `request_threaded_irq`.
-unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>(
- _irq: i32,
- ptr: *mut c_void,
-) -> c_uint {
+unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler>(_irq: i32, ptr: *mut c_void) -> c_uint {
// SAFETY: `ptr` is a pointer to `ThreadedRegistration<T>` set in `ThreadedRegistration::new`
let registration = unsafe { &*(ptr as *const ThreadedRegistration<T>) };
// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq

---
base-commit: a58b8764aed9648357b1c5b6368c9943ba33b7f9
change-id: 20260219-irq-static-on-trait-5b267c7a4375

Best regards,
--
Alice Ryhl <aliceryhl@xxxxxxxxxx>