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

index cac064a6034935a723621c2b8d3dc15c0254697d..757e7868e322a4f2fa1df1c0731a2c2a2427ee39 100644 (file)
@@ -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;
 
index cc2918ee2cf5ce1613d7d814d2572f42fc1da6aa..f8335a04595a76c5f113bb31ffc93c91547fad9b 100644 (file)
@@ -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;