Re: [PATCH] rust: platform: add Io support
From: Alice Ryhl
Date: Wed Nov 06 2024 - 05:32:13 EST
On Thu, Oct 24, 2024 at 4:20 PM Daniel Almeida
<daniel.almeida@xxxxxxxxxxxxx> wrote:
> + /// Maps a platform resource through ioremap() where the size is known at
> + /// compile time.
> + pub fn ioremap_resource_sized<const SIZE: usize>(
> + &self,
> + resource: u32,
> + ) -> Result<Devres<IoMem<SIZE>>> {
> + let res = self.resource(resource)?;
> + let size = self.resource_len(resource)? as usize;
> +
> + // SAFETY: `res` is guaranteed to be a valid MMIO address and the size
> + // is given by the kernel as per `self.resource_len()`.
> + let io = unsafe { IoMem::new(res as _, size) }?;
This cast looks wrong to me. You're taking a pointer to `struct
resource` and casting that to an MMIO address? Shouldn't the address
be (*res).start?
Danilo already mentioned this, but I think you're missing a call to
`request_mem_region` as well.
> + let devres = Devres::new(self.as_ref(), io, GFP_KERNEL)?;
What purpose does the Devres serve?
Alice