]> www.infradead.org Git - users/hch/misc.git/commitdiff
ASoC: codecs: Use kcalloc() instead of kzalloc()
authorQianfeng Rong <rongqianfeng@vivo.com>
Wed, 20 Aug 2025 12:34:18 +0000 (20:34 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 20 Aug 2025 14:09:22 +0000 (15:09 +0100)
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>
Link: https://patch.msgid.link/20250820123423.470486-2-rongqianfeng@vivo.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/fs-amp-lib.c
sound/soc/codecs/pcm6240.c

index 75d8d5082e30bd9231168ea12fa42ad895a676e2..c8f56617e370b25ab0b67b63d415408cc9c8812f 100644 (file)
@@ -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;
 
index 75af12231d1d9cbffd31f204562d3c4099b85ee6..08cc52b374a9a06df6ec563cdaed3b6fcf90e18e 100644 (file)
@@ -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;