rust: pci: get rid of redundant Result in IRQ methods
Subsystems (4)
Danilo Krummrich
maintainerPATCH 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
@@ -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
Danilo Krummrich
maintainerPATCH 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
@@ -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: &'aCStr , name: &'staticCStr , 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
Quoted 10 lines · Danilo Krummrich
Currently
request_irq()returnsResult<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 <[email protected]>
Re: [PATCH 2/2] rust: platform: get rid of redundant Result in IRQ methods
In reply to Danilo KrummrichQuoted 10 lines · Danilo Krummrich
Currently
request_irq_by_index()returnsResult<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 <[email protected]>
Danilo Krummrich
maintainerQuoted 10 lines · Danilo Krummrich
Currently
request_irq()returnsResult<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 <[email protected]>
Applied to driver-core-testing, thanks!