From: "Danilo Krummrich" <dakr@kernel.org>
To: "Daniel Almeida" <daniel.almeida@collabora.com>
Cc: "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>,
"Benno Lossin" <lossin@kernel.org>,
"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 v14 2/3] rust: io: mem: add a generic iomem abstraction
Date: Thu, 17 Jul 2025 00:26:57 +0200 [thread overview]
Message-ID: <DBDU05DKSHHB.SHRSPEM7J6MQ@kernel.org> (raw)
In-Reply-To: <8A8152BD-A314-4A23-B104-AD802F7E2DB6@collabora.com>
On Wed Jul 16, 2025 at 11:52 PM CEST, Daniel Almeida wrote:
> Hi,
>
> […]
>
>> +
>> +/// An exclusive memory-mapped IO region.
>> +///
>> +/// # Invariants
>> +///
>> +/// - [`ExclusiveIoMem`] has exclusive access to the underlying [`IoMem`].
>> +pub struct ExclusiveIoMem<const SIZE: usize> {
>> + /// The underlying `IoMem` instance.
>> + iomem: IoMem<SIZE>,
>> +
>> + /// The region abstraction. This represents exclusive access to the
>> + /// range represented by the underlying `iomem`.
>> + ///
>> + /// This field is needed for ownership of the region.
>> + _region: Region,
>> +}
>> +
>> +impl<const SIZE: usize> ExclusiveIoMem<SIZE> {
>> + /// Creates a new `ExclusiveIoMem` instance.
>> + fn ioremap(resource: &Resource) -> Result<Self> {
>> + let start = resource.start();
>> + let size = resource.size();
>> + let name = resource.name().ok_or(EINVAL)?;
>
> Note the change above. If there’s no name, we fail.
>
> I just noticed that this may not be the right approach, but OTOH we should note that
> “not having a name” is apparently considered a bug in the C code under some
> circumstances:
If we'd consider it to be a bug strictly speaking we should not make it an
Option and fix the bugs instead.
However, I don't think this is a bug, there are plenty of "constructor" macros
that create resource structures with a NULL pointer for the name field
(DEFINE_RES_IRQ(), DEFINE_RES_REG(), etc.).
Besides that, also the C APIs do the name check, __devm_ioremap_resource() [1]
is such an example.
Busses often assign the corresponding device name later on, but I wouldn't bet
on this to be a hard rule and nothing this abstraction can rely on anyways.
I think we should just pick a fallback string.
[1] https://elixir.bootlin.com/linux/v6.15.6/source/lib/devres.c#L144
next prev parent reply other threads:[~2025-07-16 22:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-16 21:45 [PATCH v14 0/3] rust: platform: add Io support Daniel Almeida
2025-07-16 21:45 ` [PATCH v14 1/3] rust: io: add resource abstraction Daniel Almeida
2025-07-16 21:45 ` [PATCH v14 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-07-16 21:52 ` Daniel Almeida
2025-07-16 22:26 ` Danilo Krummrich [this message]
2025-07-16 21:45 ` [PATCH v14 3/3] rust: platform: add resource accessors Daniel Almeida
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=DBDU05DKSHHB.SHRSPEM7J6MQ@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--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=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 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.