Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: irq: add `'static` bounds to irq callbacks

These callback functions take a generic `T` that is used in the body as
the generic argument in `Registration` and `ThreadedRegistration`. Those
types require `T: 'static`, but due to a compiler bug this requirement
isn't propagated to the function. Thus add the bound. This was caught in
the upstream Rust CI [1].

[ The three errors looked similar and will start appearing with Rust
1.95.0 (expected 2026-04-16). The first one was:

error[E0310]: the parameter type `T` may not live long enough
Error: --> rust/kernel/irq/request.rs:266:43
|
266 | let registration = unsafe { &*(ptr as *const Registration<T>) };
| ^^^^^^^^^^^^^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
264 | unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>(_irq: i32, ptr: *mut c_void) -> c_uint {
| +++++++++

- Miguel ]

Link: https://github.com/rust-lang/rust/pull/149389 [1]
Signed-off-by: Benno Lossin <lossin@kernel.org>
Cc: stable@vger.kernel.org
Fixes: 29e16fcd67ee ("rust: irq: add &Device<Bound> argument to irq callbacks")
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/rust-for-linux/20260217222425.8755-1-cole@unwrap.rs/
Link: https://patch.msgid.link/20260214092740.3201946-1-lossin@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Benno Lossin and committed by
Miguel Ojeda
621609f1 c431b00c

+9 -3
+9 -3
rust/kernel/irq/request.rs
··· 261 261 /// # Safety 262 262 /// 263 263 /// This function should be only used as the callback in `request_irq`. 264 - unsafe extern "C" fn handle_irq_callback<T: Handler>(_irq: i32, ptr: *mut c_void) -> c_uint { 264 + unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>( 265 + _irq: i32, 266 + ptr: *mut c_void, 267 + ) -> c_uint { 265 268 // SAFETY: `ptr` is a pointer to `Registration<T>` set in `Registration::new` 266 269 let registration = unsafe { &*(ptr as *const Registration<T>) }; 267 270 // SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq ··· 483 480 /// # Safety 484 481 /// 485 482 /// This function should be only used as the callback in `request_threaded_irq`. 486 - unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>( 483 + unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>( 487 484 _irq: i32, 488 485 ptr: *mut c_void, 489 486 ) -> c_uint { ··· 499 496 /// # Safety 500 497 /// 501 498 /// This function should be only used as the callback in `request_threaded_irq`. 502 - unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler>(_irq: i32, ptr: *mut c_void) -> c_uint { 499 + unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>( 500 + _irq: i32, 501 + ptr: *mut c_void, 502 + ) -> c_uint { 503 503 // SAFETY: `ptr` is a pointer to `ThreadedRegistration<T>` set in `ThreadedRegistration::new` 504 504 let registration = unsafe { &*(ptr as *const ThreadedRegistration<T>) }; 505 505 // SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq