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: <DFTI9J7TZRYT.CT88BWE920DU@garyguo.net>
Date: Tue, 20 Jan 2026 15:01:32 +0000
From: "Gary Guo" <gary@...yguo.net>
To: "Danilo Krummrich" <dakr@...nel.org>, "Greg KH"
 <gregkh@...uxfoundation.org>
Cc: Onur Özkan <work@...rozkan.dev>,
 <rust-for-linux@...r.kernel.org>, <rafael@...nel.org>, <ojeda@...nel.org>,
 <boqun.feng@...il.com>, <gary@...yguo.net>, <bjorn3_gh@...tonmail.com>,
 <lossin@...nel.org>, <a.hindborg@...nel.org>, <aliceryhl@...gle.com>,
 <tmgross@...ch.edu>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 1/1] rust: simplify `Adapter::id_info`

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ