* [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc()
@ 2025-08-20 12:34 Qianfeng Rong
2025-08-20 12:34 ` [PATCH 1/3] ASoC: codecs: " Qianfeng Rong
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-20 12:34 UTC (permalink / raw)
To: Nick Li, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Shengjiu Wang, Xiubo Li, Fabio Estevam,
Nicolin Chen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
Kuninori Morimoto, Andrew Davis, Chen Ni, Linus Walleij,
Qianfeng Rong, Al Viro,
open list:FOURSEMI AUDIO AMPLIFIER DRIVER, open list,
open list:FREESCALE SOC SOUND DRIVERS,
open list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
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
Qianfeng Rong (3):
ASoC: codecs: Use kcalloc() instead of kzalloc()
ASoC: fsl: Use kcalloc() instead of kzalloc()
ASoC: test-component: Use kcalloc() instead of kzalloc()
sound/soc/codecs/fs-amp-lib.c | 2 +-
sound/soc/codecs/pcm6240.c | 4 ++--
sound/soc/fsl/fsl_sai.c | 2 +-
sound/soc/fsl/imx-audmux.c | 2 +-
sound/soc/generic/test-component.c | 4 ++--
5 files changed, 7 insertions(+), 7 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] ASoC: codecs: Use kcalloc() instead of kzalloc()
2025-08-20 12:34 [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc() Qianfeng Rong
@ 2025-08-20 12:34 ` Qianfeng Rong
2025-08-20 12:34 ` [PATCH 2/3] ASoC: fsl: " Qianfeng Rong
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-20 12:34 UTC (permalink / raw)
To: Nick Li, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Andrew Davis, Qianfeng Rong, Chen Ni,
Linus Walleij, Al Viro,
open list:FOURSEMI AUDIO AMPLIFIER DRIVER, open list
Use devm_kcalloc() in fs_parse_scene_tables() and pcmdev_gain_ctrl_add()
to gain built-in overflow protection, making memory allocation safer when
calculating allocation size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
sound/soc/codecs/fs-amp-lib.c | 2 +-
sound/soc/codecs/pcm6240.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/sound/soc/codecs/fs-amp-lib.c b/sound/soc/codecs/fs-amp-lib.c
index 75d8d5082e30..c8f56617e370 100644
--- a/sound/soc/codecs/fs-amp-lib.c
+++ b/sound/soc/codecs/fs-amp-lib.c
@@ -111,7 +111,7 @@ static int fs_parse_scene_tables(struct fs_amp_lib *amp_lib)
if (count <= 0)
return -EFAULT;
- scene = devm_kzalloc(amp_lib->dev, count * sizeof(*scene), GFP_KERNEL);
+ scene = devm_kcalloc(amp_lib->dev, count, sizeof(*scene), GFP_KERNEL);
if (!scene)
return -ENOMEM;
diff --git a/sound/soc/codecs/pcm6240.c b/sound/soc/codecs/pcm6240.c
index 75af12231d1d..08cc52b374a9 100644
--- a/sound/soc/codecs/pcm6240.c
+++ b/sound/soc/codecs/pcm6240.c
@@ -1353,8 +1353,8 @@ static int pcmdev_gain_ctrl_add(struct pcmdevice_priv *pcm_dev,
return 0;
}
- pcmdev_controls = devm_kzalloc(pcm_dev->dev,
- nr_chn * sizeof(struct snd_kcontrol_new), GFP_KERNEL);
+ pcmdev_controls = devm_kcalloc(pcm_dev->dev, nr_chn,
+ sizeof(struct snd_kcontrol_new), GFP_KERNEL);
if (!pcmdev_controls)
return -ENOMEM;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] ASoC: fsl: Use kcalloc() instead of kzalloc()
2025-08-20 12:34 [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-20 12:34 ` [PATCH 1/3] ASoC: codecs: " Qianfeng Rong
@ 2025-08-20 12:34 ` Qianfeng Rong
2025-08-20 12:34 ` [PATCH 3/3] ASoC: test-component: " Qianfeng Rong
2025-08-20 22:17 ` [PATCH 0/3] ASoC: " Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-20 12:34 UTC (permalink / raw)
To: Shengjiu Wang, Xiubo Li, Fabio Estevam, Nicolin Chen,
Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
open list:FREESCALE SOC SOUND DRIVERS,
open list:FREESCALE SOC SOUND DRIVERS, open list,
open list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
Cc: Qianfeng Rong
Use devm_kcalloc() in fsl_sai_read_dlcfg() and imx_audmux_probe() to gain
built-in overflow protection, making memory allocation safer when
calculating allocation size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
sound/soc/fsl/fsl_sai.c | 2 +-
sound/soc/fsl/imx-audmux.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index cac064a60349..757e7868e322 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -1345,7 +1345,7 @@ static int fsl_sai_read_dlcfg(struct fsl_sai *sai)
num_cfg = elems / 3;
/* Add one more for default value */
- cfg = devm_kzalloc(&pdev->dev, (num_cfg + 1) * sizeof(*cfg), GFP_KERNEL);
+ cfg = devm_kcalloc(&pdev->dev, num_cfg + 1, sizeof(*cfg), GFP_KERNEL);
if (!cfg)
return -ENOMEM;
diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index cc2918ee2cf5..f8335a04595a 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -305,7 +305,7 @@ static int imx_audmux_probe(struct platform_device *pdev)
return -EINVAL;
}
- regcache = devm_kzalloc(&pdev->dev, sizeof(u32) * reg_max, GFP_KERNEL);
+ regcache = devm_kcalloc(&pdev->dev, reg_max, sizeof(u32), GFP_KERNEL);
if (!regcache)
return -ENOMEM;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] ASoC: test-component: Use kcalloc() instead of kzalloc()
2025-08-20 12:34 [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-20 12:34 ` [PATCH 1/3] ASoC: codecs: " Qianfeng Rong
2025-08-20 12:34 ` [PATCH 2/3] ASoC: fsl: " Qianfeng Rong
@ 2025-08-20 12:34 ` Qianfeng Rong
2025-08-20 22:17 ` [PATCH 0/3] ASoC: " Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-20 12:34 UTC (permalink / raw)
To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
Takashi Iwai, open list
Cc: Qianfeng Rong
Use devm_kcalloc() in test_driver_probe() to gain built-in overflow
protection, making memory allocation safer when calculating allocation
size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
sound/soc/generic/test-component.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/generic/test-component.c b/sound/soc/generic/test-component.c
index 89b995987e2d..2e49066dedd4 100644
--- a/sound/soc/generic/test-component.c
+++ b/sound/soc/generic/test-component.c
@@ -547,8 +547,8 @@ static int test_driver_probe(struct platform_device *pdev)
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
cdriv = devm_kzalloc(dev, sizeof(*cdriv), GFP_KERNEL);
- ddriv = devm_kzalloc(dev, sizeof(*ddriv) * num, GFP_KERNEL);
- dname = devm_kzalloc(dev, sizeof(*dname) * num, GFP_KERNEL);
+ ddriv = devm_kcalloc(dev, num, sizeof(*ddriv), GFP_KERNEL);
+ dname = devm_kcalloc(dev, num, sizeof(*dname), GFP_KERNEL);
if (!priv || !cdriv || !ddriv || !dname || !adata)
return -EINVAL;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc()
2025-08-20 12:34 [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc() Qianfeng Rong
` (2 preceding siblings ...)
2025-08-20 12:34 ` [PATCH 3/3] ASoC: test-component: " Qianfeng Rong
@ 2025-08-20 22:17 ` Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2025-08-20 22:17 UTC (permalink / raw)
To: Nick Li, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Shengjiu Wang, Xiubo Li, Fabio Estevam, Nicolin Chen, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Kuninori Morimoto,
Andrew Davis, Chen Ni, Linus Walleij, Al Viro, linux-sound,
linux-kernel, linuxppc-dev, imx, linux-arm-kernel, Qianfeng Rong
On Wed, 20 Aug 2025 20:34:17 +0800, Qianfeng Rong wrote:
> 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.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/3] ASoC: codecs: Use kcalloc() instead of kzalloc()
commit: 45441b933cdfb7a018674049f269d7a1bc1688df
[2/3] ASoC: fsl: Use kcalloc() instead of kzalloc()
commit: 3b6f4bd6cda2797b0d999a129376c112d41604f4
[3/3] ASoC: test-component: Use kcalloc() instead of kzalloc()
commit: 96bcb34df55f7fee99795127c796315950c94fed
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-20 22:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-20 12:34 [PATCH 0/3] ASoC: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-20 12:34 ` [PATCH 1/3] ASoC: codecs: " Qianfeng Rong
2025-08-20 12:34 ` [PATCH 2/3] ASoC: fsl: " Qianfeng Rong
2025-08-20 12:34 ` [PATCH 3/3] ASoC: test-component: " Qianfeng Rong
2025-08-20 22:17 ` [PATCH 0/3] ASoC: " Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®