Skip to content

Commit 865052d

Browse files
committed
ASoC: Use kcalloc() instead of kzalloc()
Merge series from Qianfeng Rong <[email protected]>: 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
2 parents 23d7a7e + 96bcb34 commit 865052d

5 files changed

Lines changed: 7 additions & 7 deletions

File tree

sound/soc/codecs/fs-amp-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int fs_parse_scene_tables(struct fs_amp_lib *amp_lib)
111111
if (count <= 0)
112112
return -EFAULT;
113113

114-
scene = devm_kzalloc(amp_lib->dev, count * sizeof(*scene), GFP_KERNEL);
114+
scene = devm_kcalloc(amp_lib->dev, count, sizeof(*scene), GFP_KERNEL);
115115
if (!scene)
116116
return -ENOMEM;
117117

sound/soc/codecs/pcm6240.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,8 @@ static int pcmdev_gain_ctrl_add(struct pcmdevice_priv *pcm_dev,
13531353
return 0;
13541354
}
13551355

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);
13581358
if (!pcmdev_controls)
13591359
return -ENOMEM;
13601360

sound/soc/fsl/fsl_sai.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ static int fsl_sai_read_dlcfg(struct fsl_sai *sai)
13451345

13461346
num_cfg = elems / 3;
13471347
/* 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);
13491349
if (!cfg)
13501350
return -ENOMEM;
13511351

sound/soc/fsl/imx-audmux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static int imx_audmux_probe(struct platform_device *pdev)
305305
return -EINVAL;
306306
}
307307

308-
regcache = devm_kzalloc(&pdev->dev, sizeof(u32) * reg_max, GFP_KERNEL);
308+
regcache = devm_kcalloc(&pdev->dev, reg_max, sizeof(u32), GFP_KERNEL);
309309
if (!regcache)
310310
return -ENOMEM;
311311

sound/soc/generic/test-component.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ static int test_driver_probe(struct platform_device *pdev)
547547

548548
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
549549
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);
552552
if (!priv || !cdriv || !ddriv || !dname || !adata)
553553
return -EINVAL;
554554

0 commit comments

Comments
 (0)