Re: [PATCH v4 3/3] rust: dma: add as_slice/write functions for CoherentAllocation

From: Abdiel Janulgue
Date: Fri Jun 13 2025 - 05:46:37 EST


On 02/06/2025 16:05, Alexandre Courbot wrote:
On Mon Jun 2, 2025 at 5:53 PM JST, Abdiel Janulgue wrote:
Add unsafe accessors for the region for reading or writing large
blocks of data.

Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
Signed-off-by: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxx>

A couple remaining nits/questions below, but FWIW:

Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
+
+ /// Writes data to the region starting from `offset`. `offset` is in units of `T`, not the
+ /// number of bytes.

Reading this sentence it occured to me that `offset` may be ambiguous
here, as in my mind it rings as being in bytes unit. How about using
`index` throughout the file?

Thanks! I don't have any strong opinion about this, I think it's enough that the subsequent paragraph makes it clear that the unit is in bytes unit? In any case, this could this be updated later after the merge?

+ /// ```
+ pub unsafe fn write(&self, src: &[T], offset: usize) -> Result {

Can this function be written by leveraging `as_slice_mut` and
`clone_from_slice`?

using `slice::clone_from_slice` would enforce the length of the coherent allocation to be always the same as src data. Not sure if that is what we want. Also, instead of just a straight memcpy, this would go through a 2-step layer (a call to `slice::from_raw_parts_mut` and then the `slice::clone_from_slice` itself)?.


Regards,
Abdiel