From e2ab5f600bb01d3625d667d97b3eb7538e388336 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Onur=20=C3=96zkan?= Date: Thu, 21 Aug 2025 12:07:20 +0300 Subject: [PATCH] rust: regulator: use `to_result` for error handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Simplifies error handling by replacing the manual check of the return value with the `to_result` helper. Signed-off-by: Onur Özkan Reviewed-by: Daniel Almeida Message-ID: <20250821090720.23939-1-work@onurozkan.dev> Signed-off-by: Mark Brown --- rust/kernel/regulator.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs index 704147e18bfc9..34bb24ec8d4d4 100644 --- a/rust/kernel/regulator.rs +++ b/rust/kernel/regulator.rs @@ -267,11 +267,8 @@ impl Regulator { pub fn get_voltage(&self) -> Result { // 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> { -- 2.47.3