Skip to contentSkip to conversation

rust: pci: get rid of redundant Result in IRQ methods

PATCH In review Danilo Krummrich 2 participants 5 messages Nov 3, 2025 – Nov 6, 2025

Subsystems (4)
lore
Share & tools
lore

Danilo Krummrich

author maintainer
#0 lore raw

PATCH 1/2 rust: pci: get rid of redundant Result in IRQ methods

Currently request_irq() returns

Result<impl PinInit<irq::Registration<T>, Error> + 'a>

which may carry an error in the Result or the initializer; the same is true for request_threaded_irq().

Use pin_init::pin_init_scope() to get rid of this redundancy.

---
 rust/kernel/pci/irq.rs | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
rust/kernel/pci/irq.rs +13 -9
index 782a524fe11c..03f2de559a8a 100644
@@ -175,10 +175,12 @@ pub fn request_irq<'a, T: crate::irq::Handler + 'static>(
         flags: irq::Flags,
         name: &'static CStr,
         handler: impl PinInit<T, Error> + 'a,
-    ) -> Result<impl PinInit<irq::Registration<T>, Error> + 'a> {
-        let request = vector.try_into()?;
+    ) -> impl PinInit<irq::Registration<T>, Error> + 'a {
+        pin_init::pin_init_scope(move || {
+            let request = vector.try_into()?;
 
-        Ok(irq::Registration::<T>::new(request, flags, name, handler))
+            Ok(irq::Registration::<T>::new(request, flags, name, handler))
+        })
     }
 
     /// Returns a [`kernel::irq::ThreadedRegistration`] for the given IRQ vector.
@@ -188,12 +190,14 @@ pub fn request_threaded_irq<'a, T: crate::irq::ThreadedHandler + 'static>(
         flags: irq::Flags,
         name: &'static CStr,
         handler: impl PinInit<T, Error> + 'a,
-    ) -> Result<impl PinInit<irq::ThreadedRegistration<T>, Error> + 'a> {
-        let request = vector.try_into()?;
-
-        Ok(irq::ThreadedRegistration::<T>::new(
-            request, flags, name, handler,
-        ))
+    ) -> impl PinInit<irq::ThreadedRegistration<T>, Error> + 'a {
+        pin_init::pin_init_scope(move || {
+            let request = vector.try_into()?;
+
+            Ok(irq::ThreadedRegistration::<T>::new(
+                request, flags, name, handler,
+            ))
+        })
     }
 
     /// Allocate IRQ vectors for this PCI device with automatic cleanup.
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 2/2 rust: platform: get rid of redundant Result in IRQ methods

Currently request_irq_by_index() returns

Result<impl PinInit<irq::Registration<T>, Error> + 'a>

which may carry an error in the Result or the initializer; the same is true for the other IRQ methods.

Use pin_init::pin_init_scope() to get rid of this redundancy.

---
 rust/kernel/platform.rs | 42 ++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)
rust/kernel/platform.rs +23 -19
index 8f7522c4cf89..f4b617c570be 100644
@@ -301,15 +301,17 @@ pub fn $fn_name<'a, T: irq::$handler_trait + 'static>(
             index: u32,
             name: &'static CStr,
             handler: impl PinInit<T, Error> + 'a,
-        ) -> Result<impl PinInit<irq::$reg_type<T>, Error> + 'a> {
-            let request = self.$request_fn(index)?;
-
-            Ok(irq::$reg_type::<T>::new(
-                request,
-                flags,
-                name,
-                handler,
-            ))
+        ) -> impl PinInit<irq::$reg_type<T>, Error> + 'a {
+            pin_init::pin_init_scope(move || {
+                let request = self.$request_fn(index)?;
+
+                Ok(irq::$reg_type::<T>::new(
+                    request,
+                    flags,
+                    name,
+                    handler,
+                ))
+            })
         }
     };
 }
@@ -325,18 +327,20 @@ macro_rules! define_irq_accessor_by_name {
         pub fn $fn_name<'a, T: irq::$handler_trait + 'static>(
             &'a self,
             flags: irq::Flags,
-            irq_name: &CStr,
+            irq_name: &'a CStr,
             name: &'static CStr,
             handler: impl PinInit<T, Error> + 'a,
-        ) -> Result<impl PinInit<irq::$reg_type<T>, Error> + 'a> {
-            let request = self.$request_fn(irq_name)?;
-
-            Ok(irq::$reg_type::<T>::new(
-                request,
-                flags,
-                name,
-                handler,
-            ))
+        ) -> impl PinInit<irq::$reg_type<T>, Error> + 'a {
+            pin_init::pin_init_scope(move || {
+                let request = self.$request_fn(irq_name)?;
+
+                Ok(irq::$reg_type::<T>::new(
+                    request,
+                    flags,
+                    name,
+                    handler,
+                ))
+            })
         }
     };
 }
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] rust: platform: get rid of redundant Result in IRQ methods

Quoted 10 lines · Danilo Krummrich

Currently request_irq_by_index() returns

Result<impl PinInit<irq::Registration<T>, Error> + 'a>

which may carry an error in the Result or the initializer; the same is true for the other IRQ methods.

Use pin_init::pin_init_scope() to get rid of this redundancy.

author maintainer
#4 lore raw
In reply to Danilo Krummrich
Quoted 10 lines · Danilo Krummrich

Currently request_irq() returns

Result<impl PinInit<irq::Registration<T>, Error> + 'a>

which may carry an error in the Result or the initializer; the same is true for request_threaded_irq().

Use pin_init::pin_init_scope() to get rid of this redundancy.

Applied to driver-core-testing, thanks!