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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multiple 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>

authored by

Shen Lichuan and committed by
Mark Brown
69a8d0ed 0225d3b9

+4 -4
+4 -4
sound/soc/sof/topology.c
··· 1349 1349 1350 1350 /* copy pin binding array to swidget only if it is defined in topology */ 1351 1351 if (pin_binding[0]) { 1352 - pb = kmemdup(pin_binding, num_pins * sizeof(char *), GFP_KERNEL); 1352 + pb = kmemdup_array(pin_binding, num_pins, sizeof(char *), GFP_KERNEL); 1353 1353 if (!pb) { 1354 1354 ret = -ENOMEM; 1355 1355 goto err; ··· 1889 1889 return -ENOMEM; 1890 1890 1891 1891 slink->num_hw_configs = le32_to_cpu(cfg->num_hw_configs); 1892 - slink->hw_configs = kmemdup(cfg->hw_config, 1893 - sizeof(*slink->hw_configs) * slink->num_hw_configs, 1894 - GFP_KERNEL); 1892 + slink->hw_configs = kmemdup_array(cfg->hw_config, 1893 + slink->num_hw_configs, sizeof(*slink->hw_configs), 1894 + GFP_KERNEL); 1895 1895 if (!slink->hw_configs) { 1896 1896 kfree(slink); 1897 1897 return -ENOMEM;