From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Mark Brown <broonie@kernel.org>
Cc: <tiwai@suse.com>, <perex@perex.cz>, <amade@asmblr.net>,
<linux-sound@vger.kernel.org>
Subject: Re: [PATCH v3 09/10] ASoC: Intel: avs: Refactor and fix init_config access
Date: Tue, 1 Sep 2026 10:57:38 +0200 [thread overview]
Message-ID: <3f2c2a7b-72cc-49da-bd19-09b1d5fa7275@intel.com> (raw)
In-Reply-To: <1f928229-1c43-4260-90e9-9e1bd1cd776b@sirena.org.uk>
On 9/1/2026 12:30 AM, Mark Brown wrote:
> On Mon, Aug 31, 2026 at 06:42:32PM +0200, Cezary Rojewski wrote:
>> Existing code accesses enties found in ->init_configs array through
>> indexes that are part of ->config_ids array. Those two are limited by:
>> ->num_init_configs and ->num_config_ids respectively. Using ID larger
>> or equal to ->num_init_configs leads to out-of-bounds access:
>
> ...
>
>> Rather than adding another if-statement, refactor the code. There is no
>> need to store the IDs, have a list of pointers to actual config-entries
>> instead. As the verification of ->init_config entries does not differ from
>> verification of other types that are part of the topology.c file, simply
>> reuse the code.
>
>> static int avs_path_module_send_init_configs(struct avs_dev *adev, struct avs_path_module *mod)
>
>> + for (int i = 0; i < template->num_init_configs; i++) {
>> + struct avs_tplg_init_config *config = template->init_configs[i];
>> size_t len = config->length;
>
> This will dereference every init_configs entry...
>
>> + cfgs = devm_kcalloc(comp->card->dev, module->num_init_configs, sizeof(*cfgs), GFP_KERNEL);
>> + if (!cfgs)
>> + return -ENOMEM;
>> +
>> + ret = parse_dictionary_entries(comp, tuples, block_size, cfgs, module->num_init_configs,
>> + sizeof(*cfgs), AVS_TKN_MOD_INIT_CONFIG_ID_U32,
>> + init_config_parsers, ARRAY_SIZE(init_config_parsers));
>
> ...but IIRC this ignores things it doesn't understand so will leave NULL
> entries behind. You'd presumably need malformed firwmare or something
> but still, we're parsing data from userspace.
Thank you for the review! Yes, the parser will ignore unknown entries
but these are two separate dictionaries. TBH I'm not seeing the problem
but the technical background first:
struct avs_tplg holds the array of init_configs:
struct avs_tplg {
(...)
u32 num_init_configs;
struct avs_tplg_init_config *init_configs;
};
That memory block gets allocated when the topology manifest is being loaded.
Now, struct avs_tplg_module holds the array of references to existing
entries in tplg->init_configs:
struct avs_tplg_module {
(...)
u32 num_init_configs;
struct avs_tplg_init_config **init_configs;
};
tplg->num_init_configs != module->num_init_configs
tplg->init_configs != module->init_configs
The memory block gets allocated when the module template is being loaded
(DAI widget). In contract to the manifest, these entries are just
references - parser avs_parse_init_config_ptr() is used (comes from
AVS_DEFINE_PTR_PARSER macro). The parser checks whether the ID exists
in tplg->init_configs and then assigns the reference.
The goal behind this procedure: reduce the amount of memory allocated.
The manifest takes that burden and all other topology components just
reference its entries. No information is duplicated.
As I'm very used to the driver and its files it's quite possible I'm not
seeing something very obvious.
next prev parent reply other threads:[~2026-09-01 8:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 16:42 [PATCH v3 00/10] ALSA/ASoC: Intel: avs: HDAudio bus and general fixes Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 01/10] ALSA: hda: ext: Clean up links if their initialization fails Cezary Rojewski
2026-09-01 11:39 ` Takashi Iwai
2026-09-01 11:58 ` Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 02/10] ALSA: hda: ext: Clean up streams " Cezary Rojewski
2026-09-01 11:42 ` Takashi Iwai
2026-09-01 11:49 ` Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 03/10] ASoC: Intel: avs: Clean up the bus when its " Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 04/10] ASoC: Intel: avs: Clean up the bus when fetching ML caps fails Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 05/10] ASoC: Intel: avs: Clean up streams if their initialization fails Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 06/10] ASoC: Intel: avs: Do not ignore -ENOENT when loading a topology Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 07/10] ASoC: Intel: avs: Cancel d0ix_work asynchrounously during recovery Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 08/10] ASoC: Intel: avs: Fix unbalanced module reference count Cezary Rojewski
2026-08-31 16:42 ` [PATCH v3 09/10] ASoC: Intel: avs: Refactor and fix init_config access Cezary Rojewski
2026-08-31 22:30 ` Mark Brown
2026-09-01 8:57 ` Cezary Rojewski [this message]
2026-09-01 11:28 ` Mark Brown
2026-08-31 16:42 ` [PATCH v3 10/10] ASoC: Intel: avs: hda: Constrain MSBs on startup Cezary Rojewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3f2c2a7b-72cc-49da-bd19-09b1d5fa7275@intel.com \
--to=cezary.rojewski@intel.com \
--cc=amade@asmblr.net \
--cc=broonie@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.