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] [day] [month] [year] [list]
Message-ID: <D8KAZ2NYJ4C3.STH2PZYCM7X4@proton.me>
Date: Wed, 19 Mar 2025 14:13:00 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Daniel Almeida <daniel.almeida@...labora.com>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v7 3/3] rust: platform: allow ioremap of platform resources

On Wed Mar 19, 2025 at 12:22 PM CET, Danilo Krummrich wrote:
> On Wed, Mar 19, 2025 at 12:48:00AM +0000, Benno Lossin wrote:
>> On Tue Mar 18, 2025 at 7:22 PM CET, Daniel Almeida wrote:
>> > On 18 Mar 2025, at 14:43, Danilo Krummrich <dakr@...nel.org> wrote:
>> >> On Tue, Mar 18, 2025 at 02:20:43PM -0300, Daniel Almeida wrote:
>> >>> +    ///     // Read and write a 32-bit value at `offset`. Calling `try_access()` on
>> >>> +    ///     // the `Devres` makes sure that the resource is still valid.
>> >>> +    ///     let data = iomem.try_access().ok_or(ENODEV)?.readl(offset);
>> >>> +    ///
>> >>> +    ///     iomem.try_access().ok_or(ENODEV)?.writel(data, offset);
>> >> 
>> >> I'd probably write this as
>> >> 
>> >> || -> Result {
>> >> let iomem = iomem.try_access().ok_or(ENODEV)?;
>> >> 
>> >> iomem.read32(offset);
>> >> iomem.write32(data, offset);
>> >> 
>> >> Ok(())
>> >> }()?;
>> 
>> Why use a closure here?
>
> Calling try_access() only once and not having the closure is fine too.
>
> But I also think it would be good practice for an example to explicitly limit
> the scope of the corresponding guard.

Ah you're using the closure to limit the lifetime of the guard. You
don't need a closure, braces suffice.

> Ideally, it uses [1], once available.
>
> [1] https://lore.kernel.org/rust-for-linux/20250313-try_with-v1-1-adcae7ed98a9@nvidia.com/

Yeah that sounds best.

---
Cheers,
Benno


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ