Re: [PATCH v14 2/3] rust: io: mem: add a generic iomem abstraction

From: Daniel Almeida
Date: Wed Jul 16 2025 - 17:53:38 EST


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:

struct resource *r = v, *p;

[…]

seq_printf(m, "%*s%0*llx-%0*llx : %s\n",
depth * 2, "",
width, start,
width, end,
r->name ? r->name : "<BAD>”); <—————


— Daniel