Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Christophe JAILLET and committed by
Mark Brown
0a480df0 35b88858

+2 -6
+2 -6
sound/soc/sof/topology.c
··· 1109 1109 const struct sof_token_info *token_list = ipc_tplg_ops->token_list; 1110 1110 struct snd_soc_tplg_private *private = &tw->priv; 1111 1111 int num_tuples = 0; 1112 - size_t size; 1113 1112 int ret, i; 1114 1113 1115 1114 if (count > 0 && !object_token_list) { ··· 1121 1122 num_tuples += token_list[object_token_list[i]].count; 1122 1123 1123 1124 /* allocate memory for tuples array */ 1124 - size = sizeof(struct snd_sof_tuple) * num_tuples; 1125 - swidget->tuples = kzalloc(size, GFP_KERNEL); 1125 + swidget->tuples = kcalloc(num_tuples, sizeof(*swidget->tuples), GFP_KERNEL); 1126 1126 if (!swidget->tuples) 1127 1127 return -ENOMEM; 1128 1128 ··· 1559 1561 const struct sof_token_info *token_list = ipc_tplg_ops->token_list; 1560 1562 struct snd_soc_tplg_private *private = &cfg->priv; 1561 1563 struct snd_sof_dai_link *slink; 1562 - size_t size; 1563 1564 u32 token_id = 0; 1564 1565 int num_tuples = 0; 1565 1566 int ret, num_sets; ··· 1670 1673 } 1671 1674 1672 1675 /* allocate memory for tuples array */ 1673 - size = sizeof(struct snd_sof_tuple) * num_tuples; 1674 - slink->tuples = kzalloc(size, GFP_KERNEL); 1676 + slink->tuples = kcalloc(num_tuples, sizeof(*slink->tuples), GFP_KERNEL); 1675 1677 if (!slink->tuples) { 1676 1678 kfree(slink->hw_configs); 1677 1679 kfree(slink);