[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250821090720.23939-1-work@onurozkan.dev>
Date: Thu, 21 Aug 2025 12:07:20 +0300
From: Onur Özkan <work@...rozkan.dev>
To: rust-for-linux@...r.kernel.org
Cc: lgirdwood@...il.com,
broonie@...nel.org,
ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
lossin@...nel.org,
a.hindborg@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu,
dakr@...nel.org,
linux-kernel@...r.kernel.org,
Onur Özkan <work@...rozkan.dev>
Subject: [PATCH] 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@...rozkan.dev>
---
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
Powered by blists - more mailing lists