Skip to content

Commit e29122d

Browse files
bardliaoplbossart
authored andcommitted
ASoC: Intel: sof_rt5682: test devm_ and return -ENOMEM
test all devm_ based memory allocation function and return -ENOMEM if it is failed. Signed-off-by: Bard liao <yung-chuan.liao@linux.intel.com>
1 parent 3681eee commit e29122d

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎sound/soc/intel/boards/sof_rt5682.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,15 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
310310

311311
links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
312312
(1 + dmic_num + hdmi_num), GFP_KERNEL);
313+
if (!links)
314+
goto devm_err;
315+
313316
/* SSP */
314317
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
315318
"SSP%d-Codec", ssp_port);
319+
if (!links[id].name)
320+
goto devm_err;
321+
316322
links[id].id = id;
317323
links[id].codecs = rt5682_component;
318324
links[id].num_codecs = ARRAY_SIZE(rt5682_component);
@@ -327,6 +333,8 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
327333
if (is_legacy_cpu) {
328334
links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL,
329335
"ssp%d-port", ssp_port);
336+
if (!links[id].cpu_dai_name)
337+
goto devm_err;
330338
} else {
331339
/*
332340
* Currently, On SKL+ platforms MCLK will be turned off in sof
@@ -340,16 +348,24 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
340348
links[id].ignore_pmdown_time = 1;
341349
links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL,
342350
"SSP%d Pin", ssp_port);
351+
if (!links[id].cpu_dai_name)
352+
goto devm_err;
343353
}
344354
id++;
345355

346356
/* dmic */
347357
for (i = 1; i <= dmic_num; i++) {
348358
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
349359
"dmic%02d", i);
360+
if (!links[id].name)
361+
goto devm_err;
362+
350363
links[id].id = id;
351364
links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL,
352365
"DMIC%02d Pin", i);
366+
if (!links[id].cpu_dai_name)
367+
goto devm_err;
368+
353369
links[id].codecs = dmic_component;
354370
links[id].num_codecs = ARRAY_SIZE(dmic_component);
355371
links[id].platforms = platform_component;
@@ -365,17 +381,28 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
365381
idisp_components = devm_kzalloc(dev,
366382
sizeof(struct snd_soc_dai_link_component) *
367383
hdmi_num, GFP_KERNEL);
384+
if (!idisp_components)
385+
goto devm_err;
368386
}
369387
for (i = 1; i <= hdmi_num; i++) {
370388
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
371389
"iDisp%d", i);
390+
if (!links[id].name)
391+
goto devm_err;
392+
372393
links[id].id = id;
373394
links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL,
374395
"iDisp%d Pin", i);
396+
if (!links[id].cpu_dai_name)
397+
goto devm_err;
398+
375399
idisp_components[i-1].name = "ehdaudio0D2";
376400
idisp_components[i-1].dai_name = devm_kasprintf(dev, GFP_KERNEL,
377401
"intel-hdmi-"
378402
"hifi%d", i);
403+
if (!idisp_components[i-1].dai_name)
404+
goto devm_err;
405+
379406
links[id].codecs = &idisp_components[i-1];
380407
links[id].num_codecs = 1;
381408
links[id].platforms = platform_component;
@@ -387,6 +414,9 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
387414
}
388415

389416
return links;
417+
418+
devm_err:
419+
return NULL;
390420
}
391421

392422
static int sof_audio_probe(struct platform_device *pdev)
@@ -420,6 +450,9 @@ static int sof_audio_probe(struct platform_device *pdev)
420450
dai_links = sof_card_dai_links_create(&pdev->dev, sof_rt5682_quirk &
421451
SOF_RT5682_SSP_MASK,
422452
dmic_num, hdmi_num);
453+
if (!dai_links)
454+
return -ENOMEM;
455+
423456
sof_audio_card_rt5682.dai_link = dai_links;
424457
sof_audio_card_rt5682.num_links = 1 + dmic_num + hdmi_num;
425458

0 commit comments

Comments
 (0)