Re: [PATCH v2] ALSA: core: Use flexible array for card private data
From: Takashi Iwai
Date: Mon Jun 01 2026 - 05:33:44 EST
On Mon, 01 Jun 2026 03:23:35 +0200,
Cássio Gabriel wrote:
>
> snd_card_new() and snd_devm_card_new() allocate struct snd_card
> together with optional driver-private storage. The storage is currently
> described only by open-coded sizeof(*card) + extra_size arithmetic, and
> snd_card_init() reaches it by manually adding sizeof(struct snd_card) to
> the card pointer.
>
> Make the trailing storage explicit with a flexible array member. Use
> kzalloc_flex() for the regular allocation path and struct_size() for the
> devres allocation size. This documents the layout and avoids open-coded
> variable-size object arithmetic.
>
> Align the flexible array to unsigned long long so the driver-private area
> does not become less aligned than the old sizeof(struct snd_card) tail
> address on 32-bit ABIs.
>
> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@xxxxxxxxx>
Applied to for-next branch now. Thanks.
Takashi