]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
rust: regulator: use `to_result` for error handling
authorOnur Özkan <work@onurozkan.dev>
Thu, 21 Aug 2025 09:07:20 +0000 (12:07 +0300)
committerMark Brown <broonie@kernel.org>
Thu, 28 Aug 2025 09:08:39 +0000 (11:08 +0200)
Simplifies error handling by replacing the manual check
of the return value with the `to_result` helper.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Message-ID: <20250821090720.23939-1-work@onurozkan.dev>
Signed-off-by: Mark Brown <broonie@kernel.org>
rust/kernel/regulator.rs

index 704147e18bfc9c993a00f7a187105360ad1d4956..34bb24ec8d4d436437d92a344c61fc3a46de0b5d 100644 (file)
@@ -267,11 +267,8 @@ impl<T: RegulatorState> Regulator<T> {
     pub fn get_voltage(&self) -> Result<Voltage> {
         // SAFETY: Safe as per the type invariants of `Regulator`.
         let voltage = unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) };
-        if voltage < 0 {
-            Err(kernel::error::Error::from_errno(voltage))
-        } else {
-            Ok(Voltage::from_microvolts(voltage))
-        }
+
+        to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
     }
 
     fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {