diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index f3118070d38c87..28ecf49d388562 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 2cbada751e32e1..32404c71ee3609 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(()) } }