Skip to content

Commit e2ab5f6

Browse files
onur-ozkanbroonie
authored andcommitted
rust: regulator: use to_result for error handling
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>
1 parent ec0be3c commit e2ab5f6

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

rust/kernel/regulator.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,8 @@ impl<T: RegulatorState> Regulator<T> {
267267
pub fn get_voltage(&self) -> Result<Voltage> {
268268
// SAFETY: Safe as per the type invariants of `Regulator`.
269269
let voltage = unsafe { bindings::regulator_get_voltage(self.inner.as_ptr()) };
270-
if voltage < 0 {
271-
Err(kernel::error::Error::from_errno(voltage))
272-
} else {
273-
Ok(Voltage::from_microvolts(voltage))
274-
}
270+
271+
to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
275272
}
276273

277274
fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {

0 commit comments

Comments
 (0)