public inbox for driver-core@lists.linux.dev
 help / color / mirror / Atom feed
From: Cole Leavitt <cole@unwrap.rs>
To: Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	Daniel Almeida <daniel.almeida@collabora.com>
Cc: Miguel Ojeda <ojeda@kernel.org>,
	rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
	Cole Leavitt <cole@unwrap.rs>
Subject: [PATCH] rust: irq: add missing 'static bound to IRQ callback functions
Date: Tue, 17 Feb 2026 15:24:25 -0700	[thread overview]
Message-ID: <20260217222425.8755-1-cole@unwrap.rs> (raw)

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


             reply	other threads:[~2026-02-17 22:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-17 22:24 Cole Leavitt [this message]
2026-02-17 22:31 ` [PATCH] rust: irq: add missing 'static bound to IRQ callback functions Daniel Almeida
2026-02-17 22:56 ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260217222425.8755-1-cole@unwrap.rs \
    --to=cole@unwrap.rs \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=driver-core@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox