Re: [PATCH v4 3/3] rust: dma: add as_slice/write functions for CoherentAllocation
From: Alexandre Courbot
Date: Sun Jun 15 2025 - 08:52:01 EST
On Fri Jun 13, 2025 at 6:45 PM JST, Abdiel Janulgue wrote:
> 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?
I agree this can be its own follow-up change, especially since `offset`
is already used elsewhere in the code and this patch is consistent with
the existing nomenclature - let's fix them all together as a separate
patch.
>
>>> + /// ```
>>> + 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)?.
Ack, thanks for the explanation!