From 792b82e7cdf6a0e3fec955e38502b4bfc7eedb6e Mon Sep 17 00:00:00 2001 From: Esteban Blanc Date: Wed, 2 Jun 2021 09:52:53 +0200 Subject: [PATCH 1/2] spi: Apply second batch of review comments spi: Keep Ok path outside of match pattern spi: Use then_some() instead of maybe_get_function Co-developed-by: Martin Schmidt Signed-off-by: Martin Schmidt Co-developed-by: Arthur Cohen Signed-off-by: Arthur Cohen Signed-off-by: Esteban Blanc --- rust/kernel/lib.rs | 3 ++- rust/kernel/spi.rs | 35 ++++++++++++++--------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index f3118070d38c872..cd81a62c9170b27 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -21,7 +21,8 @@ const_panic, const_raw_ptr_deref, const_unreachable_unchecked, - try_reserve + try_reserve, + bool_to_option, )] #![deny(clippy::complexity)] #![deny(clippy::correctness)] diff --git a/rust/kernel/spi.rs b/rust/kernel/spi.rs index 2cbada751e32e1f..32404c71ee36091 100644 --- a/rust/kernel/spi.rs +++ b/rust/kernel/spi.rs @@ -140,38 +140,31 @@ impl DriverRegistration { // FIXME: Add documentation pub fn register(self: Pin<&mut Self>) -> Result { - fn maybe_get_wrapper(vtable_value: bool, func: F) -> Option { - match vtable_value { - false => None, - true => Some(func), - } - } - let this = unsafe { self.get_unchecked_mut() }; if this.registered { return Err(Error::EINVAL); } this.spi_driver.driver.name = this.name.as_ptr() as *const c_types::c_char; - this.spi_driver.probe = - maybe_get_wrapper(T::TO_USE.probe, DriverRegistration::probe_wrapper::); - this.spi_driver.remove = - maybe_get_wrapper(T::TO_USE.remove, DriverRegistration::remove_wrapper::); - this.spi_driver.shutdown = maybe_get_wrapper( - T::TO_USE.shutdown, - DriverRegistration::shutdown_wrapper::, - ); + this.spi_driver.probe = T::TO_USE + .probe + .then_some(DriverRegistration::probe_wrapper::); + this.spi_driver.remove = T::TO_USE + .remove + .then_some(DriverRegistration::remove_wrapper::); + this.spi_driver.shutdown = T::TO_USE + .shutdown + .then_some(DriverRegistration::shutdown_wrapper::); let res = unsafe { bindings::__spi_register_driver(this.this_module.0, &mut this.spi_driver) }; - match res { - 0 => { - this.registered = true; - Ok(()) - } - _ => Err(Error::from_kernel_errno(res)), + if res != 0 { + return Err(Error::from_kernel_errno(res)); } + + this.registered = true; + Ok(()) } } From 3bf79e99341e7c0134faac7784b64773e508daf5 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Fri, 4 Jun 2021 09:14:44 +0200 Subject: [PATCH 2/2] kernel: Fix formatting on #![feature] --- rust/kernel/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index cd81a62c9170b27..28ecf49d3885621 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -22,7 +22,7 @@ const_raw_ptr_deref, const_unreachable_unchecked, try_reserve, - bool_to_option, + bool_to_option )] #![deny(clippy::complexity)] #![deny(clippy::correctness)]