Re: [PATCH] ASoC: soc-core: start rtd->num_components at zero
From: Hans de Goede
Date: Thu Nov 12 2026 - 09:02:00 EST
Hi Mark,
I was about to send a regression bug report for 7.4-rc2 but I first
checked the list to see if a fix was already available and I'm happy
to report that this fixes things for me:
Tested-by: Hans de Goede <johannes.goede@xxxxxxxxxxxxxxxx>
Reviewed-by: Hans de Goede <johannes.goede@xxxxxxxxxxxxxxxx>
On 12-Nov-26 12:37, Mark Brown wrote:
>> Since the conversion to devm_kzalloc_flex(), the allocator sets the
>> __counted_by() counter num_components to the allocated length
>> (num_cpus + num_codecs + num_platforms). This only happens when the
>> compiler supports __builtin_counted_by_ref() (GCC 16 here). With
>> older compilers the counter stays zero, as before.
>
> This doesn't apply against current code, I think this is an issue that
> was already fixed. Please check and resend if it's still needed.
This applies cleanly on 7.4-rc2 and fixes a regression breaking
audio on a lot of different devices there.
If some form of this is already in ASoC-next, then that needs to be
send to Linux as a fix ASAP.
Regards,
Hans
p.s.
@Kees, have you seen Dennis' remark about the same problem with
devm_kzalloc_flex() changing the semantics with the num-components
counter now no longer being initialized to zero in at least 2 other
places? :
"""
Kees, the same pattern (a *_flex() allocation followed by code that uses
the counter as a fill index starting from zero) looks to be present in
two places converted by 69050f8d6d07 ("treewide: Replace kmalloc with
kmalloc_obj for non-scalar types"). I have only read the code for these.
I have no hardware for either and have not reproduced them, so please
treat them as possible issues rather than confirmed bugs:
- drivers/spi/spi-axi-spi-engine.c: spi_engine_optimize_message()
allocates p with kzalloc_flex(*p, instructions, p_dry.length + 1),
which presets p->length, and spi_engine_compile_message() then
appends with p->length++ through spi_engine_program_add_cmd().
- drivers/net/wireless/intel/iwlwifi/mld/d3.c:
iwl_mld_process_netdetect_res() allocates netdetect_info with
kzalloc_flex(..., matches, n_matches), presetting n_matches, and
iwl_mld_set_netdetect_info() stores at matches[n_matches] and then
increments it. The per-match kzalloc_flex(..., channels, n_channels)
has the same issue with match->n_channels.
"""