Re: [PATCH v11 1/4] rust: io: add resource abstraction

From: Daniel Almeida
Date: Wed Jul 02 2025 - 14:12:01 EST


Hi Danilo

> On 2 Jul 2025, at 07:21, Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
>
>> +#[cfg(CONFIG_HAS_IOPORT)]
>> +/// Returns a reference to the global `ioport_resource` variable.
>> +pub fn ioport_resource() -> &'static Resource {
>> + // SAFETY: `bindings::ioport_resoure` has global lifetime and is of type Resource.
>> + unsafe { Resource::as_ref(&raw mut bindings::ioport_resource) }
>> +}
>> +
>> +#[cfg(CONFIG_HAS_IOMEM)]
>> +/// Returns a reference to the global `iomem_resource` variable.
>> +pub fn iomem_resource() -> &'static Resource {
>> + // SAFETY: `bindings::iomem_resoure` has global lifetime and is of type Resource.
>> + unsafe { Resource::as_ref(&raw mut bindings::iomem_resource) }
>> +}
>
> This caught my attention, and I have a few questions:
>
> 1) What do you need them for? I don't see any methods that would usually
> consume those.
>
> 2) Why are they behind CONFIG_HAS_IOPORT and CONFIG_HAS_IOMEM, even though the
> C instances are not?
>
> 3) What happens if we pass them to IoMem::new()? Is this really safe, or do we
> need them to be a special Resource type?
>

Good catch, actually.

I worked on this patch with Fiona and IIRC, she needed access to these two for
her LED abstractions. This patch has seen a few iterations already and this may
or may not be obsolete by now. I must say I've never used these before so I
don't really know how they work nor do I need this at all.

Fiona, do you still need these two accessors?

— Daniel