Skip to content
/ linux Public

Commit dddc9e6

Browse files
BennoLossinSasha Levin
authored andcommitted
rust: irq: add 'static bounds to irq callbacks
[ Upstream commit 621609f ] 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: rust-lang/rust#149389 [1] Signed-off-by: Benno Lossin <lossin@kernel.org> Cc: stable@vger.kernel.org Fixes: 29e16fc ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a94f096 commit dddc9e6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rust/kernel/irq/request.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ impl<T: Handler + 'static> Registration<T> {
261261
/// # Safety
262262
///
263263
/// 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 {
265268
// SAFETY: `ptr` is a pointer to `Registration<T>` set in `Registration::new`
266269
let registration = unsafe { &*(ptr as *const Registration<T>) };
267270
// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq
@@ -480,7 +483,7 @@ impl<T: ThreadedHandler + 'static> ThreadedRegistration<T> {
480483
/// # Safety
481484
///
482485
/// This function should be only used as the callback in `request_threaded_irq`.
483-
unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>(
486+
unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>(
484487
_irq: i32,
485488
ptr: *mut c_void,
486489
) -> c_uint {
@@ -496,7 +499,10 @@ unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>(
496499
/// # Safety
497500
///
498501
/// This function should be only used as the callback in `request_threaded_irq`.
499-
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler>(_irq: i32, ptr: *mut c_void) -> c_uint {
502+
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>(
503+
_irq: i32,
504+
ptr: *mut c_void,
505+
) -> c_uint {
500506
// SAFETY: `ptr` is a pointer to `ThreadedRegistration<T>` set in `ThreadedRegistration::new`
501507
let registration = unsafe { &*(ptr as *const ThreadedRegistration<T>) };
502508
// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq

0 commit comments

Comments
 (0)