rust: irq: add missing 'static bound to IRQ callback functions
Subsystems (3)
PATCH 1/1 rust: irq: add missing 'static bound to IRQ callback functions
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.
--- rust/kernel/irq/request.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
rust/kernel/irq/request.rs +9 -3
@@ -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 { &*(ptras *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 { &*(ptras *const ThreadedRegistration <T >) };// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq
Signature · 1 line
2.52.0
Hi Cole,
Quoted 68 lines · 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_voidto 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 <[email protected]>---
rust/kernel/irq/request.rs| 12 +++++++++---1 file changed, 9 insertions(+), 3 deletions(-)rust/kernel/irq/request.rs +9
-3@@ -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 { &*(ptras *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 { &*(ptras *const ThreadedRegistration <T >) };// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq Signature · 1 line
2.52.0
This looks fine to me. Sorry for the oversight and thanks for the fix.
Danilo Krummrich
maintainerQuoted 15 lines · 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_voidto a reference of the registration type, which requires T to be valid for 'static when the registration struct requires it.
Quoted 6 lines
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 <[email protected]>
Thanks for the patch! "Unfortunately", there is already an equivalent fix for this on the list.