[PATCH] rust: regulator: use `to_result` for error handling

From: Onur Özkan
Date: Thu Aug 21 2025 - 05:19:15 EST


Simplifies error handling by replacing the manual check
of the return value with the `to_result` helper.

Signed-off-by: Onur Özkan <work@xxxxxxxxxxxxx>
---
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 65f3a125348f..73ad4ad4747d 100644
--- a/rust/kernel/regulator.rs
+++ b/rust/kernel/regulator.rs
@@ -267,11 +267,8 @@ pub fn set_voltage(&self, min_voltage: Voltage, max_voltage: Voltage) -> Result
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>> {
--
2.50.0