Re: [PATCH 4/8] rust: dma: introduce dma::CoherentInit for memory initialization
From: Danilo Krummrich
Date: Fri Mar 20 2026 - 11:08:14 EST
On 3/20/2026 3:35 PM, Alexandre Courbot wrote:
> On Wed Mar 4, 2026 at 1:22 AM JST, Danilo Krummrich wrote:
>> +/// # fn test(dev: &Device<Bound>) -> Result {
>> +/// let mut dmem: CoherentInit<u64> =
>> +/// CoherentInit::zeroed_with_attrs(dev, GFP_KERNEL, DMA_ATTR_NO_WARN)?;
>
> Since this is an example, shall we use the simpler
> `CoherentInit::zeroed`?
Sure.
>> + /// Initializes the element at `i` using the given initializer.
>> + ///
>> + /// Returns `EINVAL` if `i` is out of bounds.
>> + pub fn init_at<E>(&mut self, i: usize, init: impl Init<T, E>) -> Result
>
> Should this method be introduced in the next patch, or even in its own
> patch? It feels a bit out of place at this stage since the non-array
> `CoherentInit` doesn't have an equivalent.
The non-slice variant doesn't need it.
I don't see an advantage creating a separate patch for this.
> I was also wondering whether we could have an `init` method that
> initializes all the elements without having to zero the whole array
> first, but I guess it might be a bit difficult to implement in a
> flexible enough way.
You have this in the next patch, Coherent::init() works with arrays.