rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods
@ 2025-11-03 20:30 Danilo Krummrich
  2025-11-03 20:30 ` [PATCH 2/2] rust: platform: " Danilo Krummrich
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Danilo Krummrich @ 2025-11-03 20:30 UTC (permalink / raw)
  To: bhelgaas, kwilczynski, gregkh, rafael, ojeda, alex.gaynor,
	boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
	tmgross
  Cc: linux-kernel, linux-pci, rust-for-linux, 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.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/kernel/pci/irq.rs | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/rust/kernel/pci/irq.rs b/rust/kernel/pci/irq.rs
index 782a524fe11c..03f2de559a8a 100644
--- a/rust/kernel/pci/irq.rs
+++ b/rust/kernel/pci/irq.rs
@@ -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.
-- 
2.51.0


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

* [PATCH 2/2] rust: platform: get rid of redundant Result in IRQ methods
  2025-11-03 20:30 [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods Danilo Krummrich
@ 2025-11-03 20:30 ` Danilo Krummrich
  2025-11-04  8:40   ` Alice Ryhl
  2025-11-04  8:40 ` [PATCH 1/2] rust: pci: " Alice Ryhl
  2025-11-06  9:27 ` Danilo Krummrich
  2 siblings, 1 reply; 5+ messages in thread
From: Danilo Krummrich @ 2025-11-03 20:30 UTC (permalink / raw)
  To: bhelgaas, kwilczynski, gregkh, rafael, ojeda, alex.gaynor,
	boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
	tmgross
  Cc: linux-kernel, linux-pci, rust-for-linux, 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.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/kernel/platform.rs | 42 ++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 8f7522c4cf89..f4b617c570be 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -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,
+                ))
+            })
         }
     };
 }
-- 
2.51.0


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

* Re: [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods
  2025-11-03 20:30 [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods Danilo Krummrich
  2025-11-03 20:30 ` [PATCH 2/2] rust: platform: " Danilo Krummrich
@ 2025-11-04  8:40 ` Alice Ryhl
  2025-11-06  9:27 ` Danilo Krummrich
  2 siblings, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2025-11-04  8:40 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: bhelgaas, kwilczynski, gregkh, rafael, ojeda, alex.gaynor,
	boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
	linux-kernel, linux-pci, rust-for-linux

On Mon, Nov 03, 2025 at 09:30:12PM +0100, Danilo Krummrich wrote:
> 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.
> 
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

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

* Re: [PATCH 2/2] rust: platform: get rid of redundant Result in IRQ methods
  2025-11-03 20:30 ` [PATCH 2/2] rust: platform: " Danilo Krummrich
@ 2025-11-04  8:40   ` Alice Ryhl
  0 siblings, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2025-11-04  8:40 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: bhelgaas, kwilczynski, gregkh, rafael, ojeda, alex.gaynor,
	boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
	linux-kernel, linux-pci, rust-for-linux

On Mon, Nov 03, 2025 at 09:30:13PM +0100, Danilo Krummrich wrote:
> 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.
> 
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

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

* Re: [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods
  2025-11-03 20:30 [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods Danilo Krummrich
  2025-11-03 20:30 ` [PATCH 2/2] rust: platform: " Danilo Krummrich
  2025-11-04  8:40 ` [PATCH 1/2] rust: pci: " Alice Ryhl
@ 2025-11-06  9:27 ` Danilo Krummrich
  2 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2025-11-06  9:27 UTC (permalink / raw)
  To: bhelgaas
  Cc: kwilczynski, gregkh, rafael, ojeda, alex.gaynor, boqun.feng, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, linux-kernel,
	linux-pci, rust-for-linux

On 11/3/25 9:30 PM, Danilo Krummrich wrote:
> 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.
> 
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Applied to driver-core-testing, thanks!

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

end of thread, other threads:[~2025-11-06  9:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 20:30 [PATCH 1/2] rust: pci: get rid of redundant Result in IRQ methods Danilo Krummrich
2025-11-03 20:30 ` [PATCH 2/2] rust: platform: " Danilo Krummrich
2025-11-04  8:40   ` Alice Ryhl
2025-11-04  8:40 ` [PATCH 1/2] rust: pci: " Alice Ryhl
2025-11-06  9:27 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).