Re: [PATCH 1/7] rust: dma: add from-slice constructors for Coherent and CoherentBox

From: Miguel Ojeda

Date: Fri Mar 27 2026 - 06:57:36 EST


On Thu, Mar 26, 2026 at 3:59 PM Alexandre Courbot <acourbot@xxxxxxxxxx> wrote:
>
> Then it looks like this:
>
> let mut slice = Self(Coherent::<T>::alloc_slice_with_attrs(
> dev,
> data.len(),
> gfp_flags,
> dma_attrs,
> )?);
>
> // PANIC: `slice` was created with length `data.len()`.
> slice.copy_from_slice(data);
>
> Ok(slice)

Hmm... I think I prefer this version because (conceptually) it has
less calls, closures and conditionals (i.e. 2 `map`s vs. 1 `?`). Of
course, it should compile to the same thing.

In general, I think removing wrapper types early is better than
carrying them around. It also seems closer spiritually to the early
return style of the kernel in the C side.

For this case, I think both are understandable anyway.

Cheers,
Miguel