mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rust: regulator: use `to_result` for error handling
@ 2025-08-21  9:07 Onur Özkan
  2025-08-27 18:06 ` Daniel Almeida
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Onur Özkan @ 2025-08-21  9:07 UTC (permalink / raw)
  To: rust-for-linux
  Cc: lgirdwood, broonie, ojeda, alex.gaynor, boqun.feng, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
	linux-kernel, Onur Özkan

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>
---
 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-28 14:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-21  9:07 [PATCH] rust: regulator: use `to_result` for error handling Onur Özkan
2025-08-27 18:06 ` Daniel Almeida
2025-08-28 10:15 ` Miguel Ojeda
2025-08-28 14:02 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®