[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72kM0X3fGNvD2WKBUHxg=fau+m6dqz+gq5rPyzax_3-ZVw@mail.gmail.com>
Date: Thu, 28 Aug 2025 12:15:20 +0200
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.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 Thu, Aug 21, 2025 at 11:08 AM Onur Özkan <work@...rozkan.dev> wrote:
>
> - if voltage < 0 {
> - Err(kernel::error::Error::from_errno(voltage))
> - } else {
> - Ok(Voltage::from_microvolts(voltage))
> - }
> +
> + to_result(voltage).map(|()| Voltage::from_microvolts(voltage))
No big deal either way, but our usual idiom for this so far is:
to_result(voltage)?;
Ok(Voltage::from_microvolts(voltage))
which, in a way, uses early return to put the happy path in a less
indented / more visible place.
(I noticed a few similar patches lately)
Cheers,
Miguel
Powered by blists - more mailing lists