public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Onur Özkan" <work@onurozkan.dev>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: rust-for-linux@vger.kernel.org, rafael@kernel.org,
	dakr@kernel.org, ojeda@kernel.org, boqun.feng@gmail.com,
	gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
	a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] rust: simplify `Adapter::id_info`
Date: Sat, 17 Jan 2026 14:02:40 +0300	[thread overview]
Message-ID: <20260117140240.15d1120c@nimda> (raw)
In-Reply-To: <2026011725-contour-salary-d3d1@gregkh>

On Sat, 17 Jan 2026 11:00:11 +0100
Greg KH <gregkh@linuxfoundation.org> wrote:

> On Sat, Jan 17, 2026 at 12:47:10PM +0300, Onur Özkan wrote:
> > id_info() checks ACPI first and falls back to OF.
> > 
> > This replaces the unnecessarily verbose approach with a
> > simple or_else() chain and drops temporary variables.
> > 
> > No functional change intended.
> > 
> > Signed-off-by: Onur Özkan <work@onurozkan.dev>
> > ---
> >  rust/kernel/driver.rs | 12 +-----------
> >  1 file changed, 1 insertion(+), 11 deletions(-)
> > 
> > diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
> > index 649d06468f41..6cef792d54e4 100644
> > --- a/rust/kernel/driver.rs
> > +++ b/rust/kernel/driver.rs
> > @@ -307,16 +307,6 @@ fn of_id_info(dev: &device::Device) ->
> > Option<&'static Self::IdInfo> { /// If this returns `None`, it
> > means that there is no match in any of the ID tables directly ///
> > associated with a [`device::Device`]. fn id_info(dev:
> > &device::Device) -> Option<&'static Self::IdInfo> {
> > -        let id = Self::acpi_id_info(dev);
> > -        if id.is_some() {
> > -            return id;
> > -        }
> > -
> > -        let id = Self::of_id_info(dev);
> > -        if id.is_some() {
> > -            return id;
> > -        }
> > -
> > -        None
> > +        Self::acpi_id_info(dev).or_else(|| Self::of_id_info(dev))
> 
> Have we already started the game of "rust golf" on the kernel?  The
> original code here is much easier to read, and the compiler should
> produce the same thing for both, right?
> 
> thanks,
> 
> greg k-h

Hi Greg,

I don't know what "rust golf" means, the main motivation here was to use
a more idiomatic Rust pattern.

Functions called in Adapter::id_info already return the same Result
type and it's quite annoying(IMO) to do "if x.is_some() { return x }"
in cases like this. Clippy would argue on many cases similar to this.
Readability is subjective, but to me the new code is slightly simpler
to follow (as it does the "try X, then Y" thing in a shorter way).

That said, I don't have strong feelings on the new code. The main
motivation was to drop the "annoying" code with more idiomatic one,
but seems like not everyone agrees with it. Feel free to ignore the
patch if you prefer the original code.

Regards,
Onur Özkan

  reply	other threads:[~2026-01-17 11:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-17  9:47 [PATCH v2 0/1] rust: simplify `Adapter::id_info` Onur Özkan
2026-01-17  9:47 ` [PATCH v2 1/1] " Onur Özkan
2026-01-17 10:00   ` Greg KH
2026-01-17 11:02     ` Onur Özkan [this message]
2026-01-17 12:07       ` Greg KH
2026-01-17 12:53         ` Danilo Krummrich
2026-01-20 15:01           ` Gary Guo
2026-01-20 16:00             ` Miguel Ojeda
2026-01-24 13:20           ` Alexandre Courbot
2026-01-17 12:56         ` Onur Özkan
2026-01-17 14:25       ` Miguel Ojeda

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=20260117140240.15d1120c@nimda \
    --to=work@onurozkan.dev \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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