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

From: Abdiel Janulgue
Date: Thu Apr 10 2025 - 05:08:31 EST


Hi Alex,

On 08/04/2025 06:08, Alexandre Courbot wrote:
+ }
+ // SAFETY:
+ // - The pointer is valid due to type invariant on `CoherentAllocation`
+ // and we've just checked that the range and index is within bounds.
+ // - `offset` can't overflow since it is smaller than `self.count` and we've checked
+ // that `self.count` won't overflow early in the constructor.
+ unsafe {
+ core::ptr::copy_nonoverlapping(src.as_ptr(), self.cpu_addr.add(offset), src.len())
+ };

How about leveraging as_slice_mut() so this unsafe block can be removed?

as_slice_mut is still unsafe, no? So we couldn't remove unsafe block still?

Thanks,
Abdiel