Re: [PATCH] dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array

From: Linus Walleij

Date: Wed May 27 2026 - 06:22:29 EST


Hi Rosen,

thanks for your patch!

On Tue, May 26, 2026 at 10:16 PM 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).
>
> Assisted-by: Claude:Opus-4.7
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>

OK!

Please add

unsigned int num_phy_chans

> + struct d40_chan phy_chans[];

and

phy_chans[] __counted_by(num_phy_chans);


> - base = devm_kzalloc(dev,
> - ALIGN(sizeof(struct d40_base), 4) +
> - (num_phy_chans + num_log_chans + num_memcpy_chans) *
> - sizeof(struct d40_chan), GFP_KERNEL);
> + alloc_size = struct_size(base, phy_chans, num_phy_chans);
> + alloc_size += sizeof(*base->log_chans) * (num_log_chans + num_memcpy_chans);
> + base = devm_kzalloc(dev, alloc_size, GFP_KERNEL);

Please describe exactly how the ALIGN(sizeof(struct d40_base), 4) requirement
is met by the new code?

The phy_chans will be read by hardware which depends on this specific
alignment otherwise the data will be corrupted.

Yours,
Linus Walleij