From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Greg KH" <gregkh@linuxfoundation.org>
Cc: "Onur Özkan" <work@onurozkan.dev>,
rust-for-linux@vger.kernel.org, rafael@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: Tue, 20 Jan 2026 15:01:32 +0000 [thread overview]
Message-ID: <DFTI9J7TZRYT.CT88BWE920DU@garyguo.net> (raw)
In-Reply-To: <DFQVNVYZCDPB.3IB8IA2KWUD4B@kernel.org>
On Sat Jan 17, 2026 at 12:53 PM GMT, Danilo Krummrich wrote:
> On Sat Jan 17, 2026 at 1:07 PM CET, Greg KH wrote:
>> Does clippy complain about this one?
>
> No, it does not.
>
>> I don't have strong feelings either, but the original is "easier" for
>> those of us used to C code.
>
> I think it's a matter of preference. Personally, I like those functional
> characteristics of Rust and the corresponding possibility of compact expressions
> as long as it is not overdone.
>
> This case seems pretty simple though. :)
>
> In comparison, this is code from allocating the level 1 page directory for the
> GSP (radix3) firmware, which is probably a bit too much.
>
> level1 <- {
> // Allocate the level 1 page table, map the level 2 page table onto it, and map it
> // into the device address space.
> VVec::<u8>::with_capacity(
> level2.iter().count() * size_of::<u64>(),
> GFP_KERNEL,
> )
> .map_err(|_| ENOMEM)
> .and_then(|level1| map_into_lvl(&level2, level1))
> .map(|level1| SGTable::new(dev, level1, DataDirection::ToDevice, GFP_KERNEL))?
For this specific instance, it looks like it could just be
let level1 = VVec::<u8>::with_capacity(
level2.iter().count() * size_of::<u64>(),
GFP_KERNEL,
)?;
let level1 = map_into_lvl(&level2, level1)?;
SGTable::new(dev, level1, DataDirection::ToDevice, GFP_KENREL)?
which IMO looks clearer.
I suspect what people want is Elixir's pipe operator so the above is like this
(non-existent, imaginary syntax):
VVec::<u8>::with_capacity(
level2.iter().count() * size_of::<u64>(),
GFP_KERNEL,
)?
|> map_into_lvl(&level2, _)?
|> SGTable::new(dev, _, DataDirection::ToDevice, GFP_KERNEL)?
But I think keeping things as `Result` (and not using `?`) just to use the
functional combinatiors is probably a bad idea.
Best,
Gary
next prev parent reply other threads:[~2026-01-20 15:01 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
2026-01-17 12:07 ` Greg KH
2026-01-17 12:53 ` Danilo Krummrich
2026-01-20 15:01 ` Gary Guo [this message]
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=DFTI9J7TZRYT.CT88BWE920DU@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--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 \
--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