lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <707352A3-B026-4A8A-9D8E-5E0E7BDA2F19@collabora.com>
Date: Wed, 27 Aug 2025 15:06:59 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Onur Özkan <work@...rozkan.dev>
Cc: rust-for-linux@...r.kernel.org,
 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
Subject: Re: [PATCH] rust: regulator: use `to_result` for error handling



> On 21 Aug 2025, at 06:07, Onur Özkan <work@...rozkan.dev> wrote:
> 
> 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
> 
> 

Reviewed-by: Daniel Almeida <daniel.almeida@...labora.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ