summaryrefslogtreecommitdiffstats
path: root/sound/soc/sof/topology.c
diff options
context:
space:
mode:
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>2022-03-20 07:22:26 +0100
committerMark Brown <broonie@kernel.org>2022-04-06 23:37:56 +0100
commit0a480df0b87a75b315cc6eef62bfb597111ee630 (patch)
treef4c5e3816753e8d9c3e15929bcbb3622152c870a /sound/soc/sof/topology.c
parent35b8885805002564906086cbd691e88850257294 (diff)
downloadlinux-stable-0a480df0b87a75b315cc6eef62bfb597111ee630.tar.gz
linux-stable-0a480df0b87a75b315cc6eef62bfb597111ee630.tar.bz2
linux-stable-0a480df0b87a75b315cc6eef62bfb597111ee630.zip
ASoC: SOF: topology: Avoid open coded arithmetic in memory allocation
Use kcalloc() instead of kzalloc()+open coded multiplication. This is safer and saves a few lines of code. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Link: https://lore.kernel.org/r/3bbf03cfd1966bc6fb6dd0939e039fc161078a61.1647757329.git.christophe.jaillet@wanadoo.fr Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/sof/topology.c')
-rw-r--r--sound/soc/sof/topology.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index f7e1de860931..6ab760256fc5 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -1109,7 +1109,6 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
const struct sof_token_info *token_list = ipc_tplg_ops->token_list;
struct snd_soc_tplg_private *private = &tw->priv;
int num_tuples = 0;
- size_t size;
int ret, i;
if (count > 0 && !object_token_list) {
@@ -1122,8 +1121,7 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
num_tuples += token_list[object_token_list[i]].count;
/* allocate memory for tuples array */
- size = sizeof(struct snd_sof_tuple) * num_tuples;
- swidget->tuples = kzalloc(size, GFP_KERNEL);
+ swidget->tuples = kcalloc(num_tuples, sizeof(*swidget->tuples), GFP_KERNEL);
if (!swidget->tuples)
return -ENOMEM;
@@ -1561,7 +1559,6 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
const struct sof_token_info *token_list = ipc_tplg_ops->token_list;
struct snd_soc_tplg_private *private = &cfg->priv;
struct snd_sof_dai_link *slink;
- size_t size;
u32 token_id = 0;
int num_tuples = 0;
int ret, num_sets;
@@ -1673,8 +1670,7 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
}
/* allocate memory for tuples array */
- size = sizeof(struct snd_sof_tuple) * num_tuples;
- slink->tuples = kzalloc(size, GFP_KERNEL);
+ slink->tuples = kcalloc(num_tuples, sizeof(*slink->tuples), GFP_KERNEL);
if (!slink->tuples) {
kfree(slink->hw_configs);
kfree(slink);