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

ASoC: Use kcalloc() instead of kzalloc()

Merge series from Qianfeng Rong <rongqianfeng@vivo.com>:

Replace devm_kzalloc() with devm_kcalloc() in sound/soc. As noted in the
kernel documentation [1], open-coded multiplication in allocator arguments
is discouraged because it can lead to integer overflow.

Using devm_kcalloc() provides built-in overflow protection, making the
memory allocation safer when calculating the allocation size compared
to explicit multiplication.

[1]: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

+7 -7
+1 -1
sound/soc/codecs/fs-amp-lib.c
··· 111 111 if (count <= 0) 112 112 return -EFAULT; 113 113 114 - scene = devm_kzalloc(amp_lib->dev, count * sizeof(*scene), GFP_KERNEL); 114 + scene = devm_kcalloc(amp_lib->dev, count, sizeof(*scene), GFP_KERNEL); 115 115 if (!scene) 116 116 return -ENOMEM; 117 117
+2 -2
sound/soc/codecs/pcm6240.c
··· 1353 1353 return 0; 1354 1354 } 1355 1355 1356 - pcmdev_controls = devm_kzalloc(pcm_dev->dev, 1357 - nr_chn * sizeof(struct snd_kcontrol_new), GFP_KERNEL); 1356 + pcmdev_controls = devm_kcalloc(pcm_dev->dev, nr_chn, 1357 + sizeof(struct snd_kcontrol_new), GFP_KERNEL); 1358 1358 if (!pcmdev_controls) 1359 1359 return -ENOMEM; 1360 1360
+1 -1
sound/soc/fsl/fsl_sai.c
··· 1345 1345 1346 1346 num_cfg = elems / 3; 1347 1347 /* Add one more for default value */ 1348 - cfg = devm_kzalloc(&pdev->dev, (num_cfg + 1) * sizeof(*cfg), GFP_KERNEL); 1348 + cfg = devm_kcalloc(&pdev->dev, num_cfg + 1, sizeof(*cfg), GFP_KERNEL); 1349 1349 if (!cfg) 1350 1350 return -ENOMEM; 1351 1351
+1 -1
sound/soc/fsl/imx-audmux.c
··· 305 305 return -EINVAL; 306 306 } 307 307 308 - regcache = devm_kzalloc(&pdev->dev, sizeof(u32) * reg_max, GFP_KERNEL); 308 + regcache = devm_kcalloc(&pdev->dev, reg_max, sizeof(u32), GFP_KERNEL); 309 309 if (!regcache) 310 310 return -ENOMEM; 311 311
+2 -2
sound/soc/generic/test-component.c
··· 547 547 548 548 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 549 549 cdriv = devm_kzalloc(dev, sizeof(*cdriv), GFP_KERNEL); 550 - ddriv = devm_kzalloc(dev, sizeof(*ddriv) * num, GFP_KERNEL); 551 - dname = devm_kzalloc(dev, sizeof(*dname) * num, GFP_KERNEL); 550 + ddriv = devm_kcalloc(dev, num, sizeof(*ddriv), GFP_KERNEL); 551 + dname = devm_kcalloc(dev, num, sizeof(*dname), GFP_KERNEL); 552 552 if (!priv || !cdriv || !ddriv || !dname || !adata) 553 553 return -EINVAL; 554 554