Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: imx-audmix: check return value of devm_kasprintf()

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>

authored by

Claudiu Beznea and committed by
Mark Brown
2f76e1d6 997905d5

+9
+9
sound/soc/fsl/imx-audmix.c
··· 227 227 228 228 dai_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%s", 229 229 fe_name_pref, args.np->full_name + 1); 230 + if (!dai_name) 231 + return -ENOMEM; 230 232 231 233 dev_info(pdev->dev.parent, "DAI FE name:%s\n", dai_name); 232 234 ··· 237 235 capture_dai_name = 238 236 devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s %s", 239 237 dai_name, "CPU-Capture"); 238 + if (!capture_dai_name) 239 + return -ENOMEM; 240 240 } 241 241 242 242 /* ··· 270 266 "AUDMIX-Playback-%d", i); 271 267 be_cp = devm_kasprintf(&pdev->dev, GFP_KERNEL, 272 268 "AUDMIX-Capture-%d", i); 269 + if (!be_name || !be_pb || !be_cp) 270 + return -ENOMEM; 273 271 274 272 priv->dai[num_dai + i].cpus = &dlc[1]; 275 273 priv->dai[num_dai + i].codecs = &asoc_dummy_dlc; ··· 294 288 priv->dapm_routes[i].source = 295 289 devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s %s", 296 290 dai_name, "CPU-Playback"); 291 + if (!priv->dapm_routes[i].source) 292 + return -ENOMEM; 293 + 297 294 priv->dapm_routes[i].sink = be_pb; 298 295 priv->dapm_routes[num_dai + i].source = be_pb; 299 296 priv->dapm_routes[num_dai + i].sink = be_cp;