public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: irq: add missing 'static bound to IRQ callback functions
@ 2026-02-17 22:24 Cole Leavitt
  2026-02-17 22:31 ` Daniel Almeida
  2026-02-17 22:56 ` Danilo Krummrich
  0 siblings, 2 replies; 3+ messages in thread
From: Cole Leavitt @ 2026-02-17 22:24 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, Daniel Almeida
  Cc: Miguel Ojeda, rust-for-linux, driver-core, Cole Leavitt

The Registration<T> and ThreadedRegistration<T> structs require
T: Handler + 'static and T: ThreadedHandler + 'static respectively.
However, the callback functions that are used with these registrations
were missing the corresponding 'static bound:

  - handle_irq_callback<T: Handler>
  - handle_threaded_irq_callback<T: ThreadedHandler>
  - thread_fn_callback<T: ThreadedHandler>

This bound inconsistency was previously accepted by rustc, but recent
compiler versions (1.93+) enforce E0310 more strictly when casting
raw pointers to references in generic contexts. The callbacks cast a
*mut c_void to a reference of the registration type, which requires
T to be valid for 'static when the registration struct requires it.

Add the missing 'static bound to all three callback functions to match
their registration struct requirements and fix compilation with recent
rustc versions.

Fixes: 135d40523244 ("rust: irq: add threaded handler support")
Signed-off-by: Cole Leavitt <cole@unwrap.rs>
---
 rust/kernel/irq/request.rs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/irq/request.rs b/rust/kernel/irq/request.rs
index 67769800117c..7a36f790593e 100644
--- a/rust/kernel/irq/request.rs
+++ b/rust/kernel/irq/request.rs
@@ -260,7 +260,10 @@ 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>(_irq: i32, ptr: *mut c_void) -> c_uint {
+unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>(
+    _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
@@ -478,7 +481,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>(
+unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>(
     _irq: i32,
     ptr: *mut c_void,
 ) -> c_uint {
@@ -494,7 +497,10 @@ 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>(_irq: i32, ptr: *mut c_void) -> c_uint {
+unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>(
+    _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
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: irq: add missing 'static bound to IRQ callback functions
  2026-02-17 22:24 [PATCH] rust: irq: add missing 'static bound to IRQ callback functions Cole Leavitt
@ 2026-02-17 22:31 ` Daniel Almeida
  2026-02-17 22:56 ` Danilo Krummrich
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Almeida @ 2026-02-17 22:31 UTC (permalink / raw)
  To: Cole Leavitt
  Cc: Danilo Krummrich, Alice Ryhl, Miguel Ojeda, rust-for-linux,
	driver-core

Hi Cole,

> On 17 Feb 2026, at 19:24, Cole Leavitt <cole@unwrap.rs> wrote:
> 
> The Registration<T> and ThreadedRegistration<T> structs require
> T: Handler + 'static and T: ThreadedHandler + 'static respectively.
> However, the callback functions that are used with these registrations
> were missing the corresponding 'static bound:
> 
>  - handle_irq_callback<T: Handler>
>  - handle_threaded_irq_callback<T: ThreadedHandler>
>  - thread_fn_callback<T: ThreadedHandler>
> 
> This bound inconsistency was previously accepted by rustc, but recent
> compiler versions (1.93+) enforce E0310 more strictly when casting
> raw pointers to references in generic contexts. The callbacks cast a
> *mut c_void to a reference of the registration type, which requires
> T to be valid for 'static when the registration struct requires it.
> 
> Add the missing 'static bound to all three callback functions to match
> their registration struct requirements and fix compilation with recent
> rustc versions.
> 
> Fixes: 135d40523244 ("rust: irq: add threaded handler support")
> Signed-off-by: Cole Leavitt <cole@unwrap.rs>
> ---
> rust/kernel/irq/request.rs | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/rust/kernel/irq/request.rs b/rust/kernel/irq/request.rs
> index 67769800117c..7a36f790593e 100644
> --- a/rust/kernel/irq/request.rs
> +++ b/rust/kernel/irq/request.rs
> @@ -260,7 +260,10 @@ 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>(_irq: i32, ptr: *mut c_void) -> c_uint {
> +unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>(
> +    _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
> @@ -478,7 +481,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>(
> +unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>(
>     _irq: i32,
>     ptr: *mut c_void,
> ) -> c_uint {
> @@ -494,7 +497,10 @@ 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>(_irq: i32, ptr: *mut c_void) -> c_uint {
> +unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>(
> +    _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
> -- 
> 2.52.0
> 
> 

This looks fine to me. Sorry for the oversight and thanks for the fix.

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: irq: add missing 'static bound to IRQ callback functions
  2026-02-17 22:24 [PATCH] rust: irq: add missing 'static bound to IRQ callback functions Cole Leavitt
  2026-02-17 22:31 ` Daniel Almeida
@ 2026-02-17 22:56 ` Danilo Krummrich
  1 sibling, 0 replies; 3+ messages in thread
From: Danilo Krummrich @ 2026-02-17 22:56 UTC (permalink / raw)
  To: Cole Leavitt
  Cc: Alice Ryhl, Daniel Almeida, Miguel Ojeda, rust-for-linux,
	driver-core

On Tue Feb 17, 2026 at 11:24 PM CET, Cole Leavitt wrote:
> The Registration<T> and ThreadedRegistration<T> structs require
> T: Handler + 'static and T: ThreadedHandler + 'static respectively.
> However, the callback functions that are used with these registrations
> were missing the corresponding 'static bound:
>
>   - handle_irq_callback<T: Handler>
>   - handle_threaded_irq_callback<T: ThreadedHandler>
>   - thread_fn_callback<T: ThreadedHandler>
>
> This bound inconsistency was previously accepted by rustc, but recent
> compiler versions (1.93+) enforce E0310 more strictly when casting
> raw pointers to references in generic contexts. The callbacks cast a
> *mut c_void to a reference of the registration type, which requires
> T to be valid for 'static when the registration struct requires it.
>
> Add the missing 'static bound to all three callback functions to match
> their registration struct requirements and fix compilation with recent
> rustc versions.
>
> Fixes: 135d40523244 ("rust: irq: add threaded handler support")
> Signed-off-by: Cole Leavitt <cole@unwrap.rs>

Thanks for the patch! "Unfortunately", there is already an equivalent fix for
this on the list.

Link: https://lore.kernel.org/all/20260214092740.3201946-1-lossin@kernel.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-17 22:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 22:24 [PATCH] rust: irq: add missing 'static bound to IRQ callback functions Cole Leavitt
2026-02-17 22:31 ` Daniel Almeida
2026-02-17 22:56 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox