[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <7A0457FA-0E09-451E-B035-E739AED7B2C7@collabora.com>
Date: Thu, 10 Jul 2025 10:58:13 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: 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>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
Ying Huang <huang.ying.caritas@...il.com>,
Benno Lossin <lossin@...nel.org>,
linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v12 2/3] rust: io: mem: add a generic iomem abstraction
Hi Alice,
>> +impl<const SIZE: usize> IoMem<SIZE> {
>> + fn ioremap(resource: &Resource) -> Result<Self> {
>> + let size = resource.size();
>> + if size == 0 {
>> + return Err(EINVAL);
>> + }
>> +
>> + let res_start = resource.start();
>> +
>> + let addr = if resource
>> + .flags()
>> + .contains(io::resource::flags::IORESOURCE_MEM_NONPOSTED)
>> + {
>> + // SAFETY:
>> + // - `res_start` and `size` are read from a presumably valid `struct resource`.
>> + // - `size` is known not to be zero at this point.
>> + unsafe { bindings::ioremap_np(res_start, size as usize) }
>
> Here you cast from ResourceSize to usize. Are you sure that is correct?
> I thought those types could be different.
This seems to what C is doing as well, i.e.:
static void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset,
resource_size_t size, <---------
enum devm_ioremap_type type)
{
[…]
case DEVM_IOREMAP_NP:
addr = ioremap_np(offset, size);
break;
}
Where:
`static inline void __iomem *ioremap_np(phys_addr_t offset, size_t size)`
IOW: this stems from the mix and match of types used the C API itself.
What do you suggest here? Maybe a try_into() then?
— Daniel
Powered by blists - more mailing lists