From: Danilo Krummrich <dakr@kernel.org>
To: Benno Lossin <benno.lossin@proton.me>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v7 3/3] rust: platform: allow ioremap of platform resources
Date: Wed, 19 Mar 2025 12:22:51 +0100 [thread overview]
Message-ID: <Z9qpC1EapJFNadME@pollux> (raw)
In-Reply-To: <D8JTUPQ28758.2SKKTA6IL6Y8E@proton.me>
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@kernel.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.
Ideally, it uses [1], once available.
[1] https://lore.kernel.org/rust-for-linux/20250313-try_with-v1-1-adcae7ed98a9@nvidia.com/
next prev parent reply other threads:[~2025-03-19 11:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 17:20 [PATCH v7 0/3] rust: platform: add Io support Daniel Almeida
2025-03-18 17:20 ` [PATCH v7 1/3] rust: io: add resource abstraction Daniel Almeida
2025-03-18 17:20 ` [PATCH v7 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-03-18 17:20 ` [PATCH v7 3/3] rust: platform: allow ioremap of platform resources Daniel Almeida
2025-03-18 17:43 ` Danilo Krummrich
2025-03-18 18:22 ` Daniel Almeida
2025-03-19 0:48 ` Benno Lossin
2025-03-19 11:22 ` Danilo Krummrich [this message]
2025-03-19 14:13 ` Benno Lossin
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=Z9qpC1EapJFNadME@pollux \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.