* [PATCH] ASoC: SOF: topology: use kzalloc_flex
@ 2026-03-26 2:30 Rosen Penev
2026-03-30 19:11 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-26 2:30 UTC (permalink / raw)
To: linux-sound
Cc: Liam Girdwood, Peter Ujfalusi, Bard Liao, Ranjani Sridharan,
Daniel Baluta, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Kees Cook, Gustavo A. R. Silva,
moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Simplify allocation by using a flexible array member.
Add __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
sound/soc/sof/sof-audio.h | 2 +-
sound/soc/sof/topology.c | 14 ++------------
2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h
index 80b11625915d..138e5fcc2dd0 100644
--- a/sound/soc/sof/sof-audio.h
+++ b/sound/soc/sof/sof-audio.h
@@ -411,11 +411,11 @@ struct snd_sof_dai_link {
struct snd_sof_tuple *tuples;
int num_tuples;
struct snd_soc_dai_link *link;
- struct snd_soc_tplg_hw_config *hw_configs;
int num_hw_configs;
int default_hw_cfg_id;
int type;
struct list_head list;
+ struct snd_soc_tplg_hw_config hw_configs[] __counted_by(num_hw_configs);
};
/* ASoC SOF DAPM widget */
diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index 63d637db7053..413003e86f6c 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -1908,18 +1908,12 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
return -EINVAL;
}
- slink = kzalloc_obj(*slink);
+ slink = kzalloc_flex(*slink, hw_configs, le32_to_cpu(cfg->num_hw_configs));
if (!slink)
return -ENOMEM;
slink->num_hw_configs = le32_to_cpu(cfg->num_hw_configs);
- slink->hw_configs = kmemdup_array(cfg->hw_config,
- slink->num_hw_configs, sizeof(*slink->hw_configs),
- GFP_KERNEL);
- if (!slink->hw_configs) {
- kfree(slink);
- return -ENOMEM;
- }
+ memcpy(slink->hw_configs, cfg->hw_config, le32_to_cpu(cfg->num_hw_configs) * sizeof(*slink->hw_configs));
slink->default_hw_cfg_id = le32_to_cpu(cfg->default_hw_config_id);
slink->link = link;
@@ -1932,7 +1926,6 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
private->array, le32_to_cpu(private->size));
if (ret < 0) {
dev_err(scomp->dev, "Failed tp parse common DAI link tokens\n");
- kfree(slink->hw_configs);
kfree(slink);
return ret;
}
@@ -2003,7 +1996,6 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
/* allocate memory for tuples array */
slink->tuples = kzalloc_objs(*slink->tuples, num_tuples);
if (!slink->tuples) {
- kfree(slink->hw_configs);
kfree(slink);
return -ENOMEM;
}
@@ -2061,7 +2053,6 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
err:
kfree(slink->tuples);
- kfree(slink->hw_configs);
kfree(slink);
return ret;
@@ -2078,7 +2069,6 @@ static int sof_link_unload(struct snd_soc_component *scomp, struct snd_soc_dobj
kfree(slink->tuples);
list_del(&slink->list);
- kfree(slink->hw_configs);
kfree(slink);
dobj->private = NULL;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ASoC: SOF: topology: use kzalloc_flex
2026-03-26 2:30 [PATCH] ASoC: SOF: topology: use kzalloc_flex Rosen Penev
@ 2026-03-30 19:11 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-03-30 19:11 UTC (permalink / raw)
To: linux-sound, Rosen Penev
Cc: Liam Girdwood, Peter Ujfalusi, Bard Liao, Ranjani Sridharan,
Daniel Baluta, Kai Vehmanen, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, Kees Cook, Gustavo A. R. Silva,
sound-open-firmware, linux-kernel, linux-hardening
On Wed, 25 Mar 2026 19:30:53 -0700, Rosen Penev wrote:
> ASoC: SOF: topology: use kzalloc_flex
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.1
Thanks!
[1/1] ASoC: SOF: topology: use kzalloc_flex
https://git.kernel.org/broonie/sound/c/d3d75c767680
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-30 22:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 2:30 [PATCH] ASoC: SOF: topology: use kzalloc_flex Rosen Penev
2026-03-30 19:11 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox