Re: [PATCHv3] dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array
From: Linus Walleij
Date: Tue Jun 02 2026 - 05:02:19 EST
On Sun, May 31, 2026 at 4:09 AM Rosen Penev <rosenp@xxxxxxxxx> wrote:
> Convert the separately-offset phy_chans pointer to a C99 flexible array
> member at the end of struct d40_base, and switch the allocation to
> struct_size(). The log_chans and memcpy_chans slots continue to live
> in the same allocation immediately after phy_chans, indexed via
> base->log_chans. This removes the hand-rolled pointer fixup that
> recomputed phy_chans from base + ALIGN(sizeof(struct d40_base), 4).
>
> The ALIGN(sizeof(struct d40_base), 4) requirement is met implicitly by the
> C compiler when using a flexible array member. With struct d40_chan
> phy_chans[] as the last member, the C standard guarantees
> sizeof(struct d40_base) includes trailing padding to satisfy the alignment
> of the flexible array element type (struct d40_chan). Since struct d40_chan
> contains members like spinlock_t, pointers, and struct dma_chan — all with
> alignment ≥ 4 — the compiler ensures sizeof(struct d40_base) is already a
> multiple of _Alignof(struct d40_chan) >= 4. The struct_size() macro then
> computes sizeof(struct d40_base) + sizeof(struct d40_chan) * num_phy_chans,
> so phy_chans[0] lands at a properly aligned offset without needing the manual
> ALIGN.
>
> Assisted-by: Claude:Opus-4.7
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Yours,
Linus Walleij