mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Onur Özkan" <work@onurozkan.dev>
Cc: rust-for-linux@vger.kernel.org, lgirdwood@gmail.com,
	broonie@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com,
	boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
	lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
	tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: regulator: use `to_result` for error handling
Date: Wed, 27 Aug 2025 15:06:59 -0300	[thread overview]
Message-ID: <707352A3-B026-4A8A-9D8E-5E0E7BDA2F19@collabora.com> (raw)
In-Reply-To: <20250821090720.23939-1-work@onurozkan.dev>



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

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

  reply	other threads:[~2025-08-27 18:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21  9:07 Onur Özkan
2025-08-27 18:06 ` Daniel Almeida [this message]
2025-08-28 10:15 ` Miguel Ojeda
2025-08-28 14:02 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=707352A3-B026-4A8A-9D8E-5E0E7BDA2F19@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®