Re: [PATCH 1/3] rust: uaccess: generalize write_dma() to accept any Coherent<T>
From: Gary Guo
Date: Wed Mar 25 2026 - 11:17:18 EST
On Wed Mar 25, 2026 at 1:46 PM GMT, Danilo Krummrich wrote:
> On Wed Mar 25, 2026 at 2:01 PM CET, Gary Guo wrote:
>> I think there is a reason, which is that it weakens the strong typing that we
>> have. I think it'll be better to have this be
>>
>> fn write_dma<T>(&mut self, view: View<'_, Coherent<T>, [u8]>, offset: usize) -> Result
Correcting myself, this will be
fn write_dma<T>(&mut self, view: View<'_, Coherent<T>, [u8]>) -> Result
(without offset, similar to the write_slice).
>>
>> once we have I/O view and expect people to create cast views into bytes
>> explicitly.
>>
>
> There is technically no difference between the above and the below, except that
> for the above the user has to create the View first, i.e. it needs additional
> code. What's the advantage?
It prevents misuses. If you have a `[u8]` or `[u8; SIZE]` already, the change is
going to be small:
u.write_dma(c, offset, count)
vs.
u.write_dma(io_project!(c, [offset..][..count]))
[
PS. it looks like with current proposals w/ virtual places, we might be able
to get this written as
u.write_dma(c[offset..][..count])
a few years down the road if we're successful.
]
However, using a view will prevent you from feeding an arbitary
`Coherent<FooBar>` and just write it to user space. `offset` and `count` in the
API really doesn't make too much sense at all if `T` is not array/slice of u8.
Best,
Gary
>
>>> + pub fn write_dma<T: KnownSize + AsBytes + ?Sized>(
>>> + &mut self,
>>> + alloc: &Coherent<T>,
>>> + offset: usize,
>>> + count: usize,
>>> + ) -> Result {