Skip to content

Commit

Permalink
ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multipl…
Browse files Browse the repository at this point in the history
…e allocation

Let the kmemdup_array() take care about multiplication
and possible overflows.

Using kmemdup_array() is more appropriate and makes the code
easier to audit.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
Link: https://patch.msgid.link/20240826054402.58396-1-shenlichuan@vivo.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Shen Lichuan authored and Mark Brown committed Aug 26, 2024
1 parent 0225d3b commit 69a8d0e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sound/soc/sof/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ static int sof_parse_pin_binding(struct snd_sof_widget *swidget,

/* copy pin binding array to swidget only if it is defined in topology */
if (pin_binding[0]) {
pb = kmemdup(pin_binding, num_pins * sizeof(char *), GFP_KERNEL);
pb = kmemdup_array(pin_binding, num_pins, sizeof(char *), GFP_KERNEL);
if (!pb) {
ret = -ENOMEM;
goto err;
Expand Down Expand Up @@ -1889,9 +1889,9 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
return -ENOMEM;

slink->num_hw_configs = le32_to_cpu(cfg->num_hw_configs);
slink->hw_configs = kmemdup(cfg->hw_config,
sizeof(*slink->hw_configs) * slink->num_hw_configs,
GFP_KERNEL);
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;
Expand Down

0 comments on commit 69a8d0e

Please sign in to comment.