ASoC: imx-audmix: check return value of devm_kasprintf()
authorClaudiu Beznea <claudiu.beznea@microchip.com>
Wed, 14 Jun 2023 12:15:09 +0000 (15:15 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:21:33 +0000 (16:21 +0200)
[ Upstream commit 2f76e1d6ca524a888d29aafe29f2ad2003857971 ]

devm_kasprintf() returns a pointer to dynamically allocated memory.
Pointer could be NULL in case allocation fails. Check pointer validity.
Identified with coccinelle (kmerr.cocci script).

Fixes: b86ef5367761 ("ASoC: fsl: Add Audio Mixer machine driver")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20230614121509.443926-1-claudiu.beznea@microchip.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/fsl/imx-audmix.c

index 1292a84..d8e99b2 100644 (file)
@@ -228,6 +228,8 @@ static int imx_audmix_probe(struct platform_device *pdev)
 
                dai_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%s",
                                          fe_name_pref, args.np->full_name + 1);
+               if (!dai_name)
+                       return -ENOMEM;
 
                dev_info(pdev->dev.parent, "DAI FE name:%s\n", dai_name);
 
@@ -236,6 +238,8 @@ static int imx_audmix_probe(struct platform_device *pdev)
                        capture_dai_name =
                                devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s %s",
                                               dai_name, "CPU-Capture");
+                       if (!capture_dai_name)
+                               return -ENOMEM;
                }
 
                priv->dai[i].cpus = &dlc[0];
@@ -266,6 +270,8 @@ static int imx_audmix_probe(struct platform_device *pdev)
                                       "AUDMIX-Playback-%d", i);
                be_cp = devm_kasprintf(&pdev->dev, GFP_KERNEL,
                                       "AUDMIX-Capture-%d", i);
+               if (!be_name || !be_pb || !be_cp)
+                       return -ENOMEM;
 
                priv->dai[num_dai + i].cpus = &dlc[3];
                priv->dai[num_dai + i].codecs = &dlc[4];
@@ -293,6 +299,9 @@ static int imx_audmix_probe(struct platform_device *pdev)
                priv->dapm_routes[i].source =
                        devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s %s",
                                       dai_name, "CPU-Playback");
+               if (!priv->dapm_routes[i].source)
+                       return -ENOMEM;
+
                priv->dapm_routes[i].sink = be_pb;
                priv->dapm_routes[num_dai + i].source   = be_pb;
                priv->dapm_routes[num_dai + i].sink     = be_cp;