* [PATCH] rust: irq: move 'static bounds to traits
@ 2026-02-19 9:12 Alice Ryhl
2026-02-19 14:44 ` Gary Guo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-02-19 9:12 UTC (permalink / raw)
To: Danilo Krummrich, Daniel Almeida, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross
Cc: rust-for-linux, linux-kernel, Alice Ryhl
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@google.com>
---
Follow up to:
https://lore.kernel.org/all/20260214092740.3201946-1-lossin@kernel.org/
---
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@google.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: irq: move 'static bounds to traits
2026-02-19 9:12 [PATCH] rust: irq: move 'static bounds to traits Alice Ryhl
@ 2026-02-19 14:44 ` Gary Guo
2026-02-19 15:47 ` Benno Lossin
2026-03-03 19:55 ` Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Gary Guo @ 2026-02-19 14:44 UTC (permalink / raw)
To: Alice Ryhl
Cc: Danilo Krummrich, Daniel Almeida, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, linux-kernel
On 2026-02-19 09:12, Alice Ryhl wrote:
> 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@google.com>
Thanks, this is much cleaner.
Reviewed-by: Gary Guo <gary@garyguo.net>
Best,
Gary
> ---
> Follow up to:
> https://lore.kernel.org/all/20260214092740.3201946-1-lossin@kernel.org/
> ---
> 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,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: irq: move 'static bounds to traits
2026-02-19 9:12 [PATCH] rust: irq: move 'static bounds to traits Alice Ryhl
2026-02-19 14:44 ` Gary Guo
@ 2026-02-19 15:47 ` Benno Lossin
2026-03-03 19:55 ` Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Benno Lossin @ 2026-02-19 15:47 UTC (permalink / raw)
To: Alice Ryhl, Danilo Krummrich, Daniel Almeida, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg,
Trevor Gross
Cc: rust-for-linux, linux-kernel
On Thu Feb 19, 2026 at 10:12 AM CET, Alice Ryhl wrote:
> 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@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Cheers,
Benno
> ---
> Follow up to:
> https://lore.kernel.org/all/20260214092740.3201946-1-lossin@kernel.org/
> ---
> rust/kernel/irq/request.rs | 28 +++++++++++-----------------
> 1 file changed, 11 insertions(+), 17 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: irq: move 'static bounds to traits
2026-02-19 9:12 [PATCH] rust: irq: move 'static bounds to traits Alice Ryhl
2026-02-19 14:44 ` Gary Guo
2026-02-19 15:47 ` Benno Lossin
@ 2026-03-03 19:55 ` Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-03-03 19:55 UTC (permalink / raw)
To: Alice Ryhl
Cc: Daniel Almeida, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, linux-kernel
On Thu Feb 19, 2026 at 10:12 AM CET, Alice Ryhl wrote:
> 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@google.com>
Applied to driver-core-testing, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-03 19:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-19 9:12 [PATCH] rust: irq: move 'static bounds to traits Alice Ryhl
2026-02-19 14:44 ` Gary Guo
2026-02-19 15:47 ` Benno Lossin
2026-03-03 19:55 ` Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox