Skip to content

Commit 6ba8ddf

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: topology: Fix error handling in sof_widget_ready()
Fix the error paths in sof_widget_ready() to free all allocated memory and prevent memory leaks. Signed-off-by: Ranjani Sridharan <[email protected]> Reviewed-by: Péter Ujfalusi <[email protected]> Reviewed-by: Bard Liao <[email protected]> Reviewed-by: Pierre-Louis Bossart <[email protected]> Signed-off-by: Peter Ujfalusi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 858a438 commit 6ba8ddf

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

sound/soc/sof/topology.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,14 +1388,15 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
13881388
if (ret < 0) {
13891389
dev_err(scomp->dev, "failed to parse component pin tokens for %s\n",
13901390
w->name);
1391-
return ret;
1391+
goto widget_free;
13921392
}
13931393

13941394
if (swidget->num_sink_pins > SOF_WIDGET_MAX_NUM_PINS ||
13951395
swidget->num_source_pins > SOF_WIDGET_MAX_NUM_PINS) {
13961396
dev_err(scomp->dev, "invalid pins for %s: [sink: %d, src: %d]\n",
13971397
swidget->widget->name, swidget->num_sink_pins, swidget->num_source_pins);
1398-
return -EINVAL;
1398+
ret = -EINVAL;
1399+
goto widget_free;
13991400
}
14001401

14011402
if (swidget->num_sink_pins > 1) {
@@ -1404,7 +1405,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
14041405
if (ret < 0) {
14051406
dev_err(scomp->dev, "failed to parse sink pin binding for %s\n",
14061407
w->name);
1407-
return ret;
1408+
goto widget_free;
14081409
}
14091410
}
14101411

@@ -1414,7 +1415,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
14141415
if (ret < 0) {
14151416
dev_err(scomp->dev, "failed to parse source pin binding for %s\n",
14161417
w->name);
1417-
return ret;
1418+
goto widget_free;
14181419
}
14191420
}
14201421

@@ -1436,9 +1437,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
14361437
case snd_soc_dapm_dai_out:
14371438
dai = kzalloc(sizeof(*dai), GFP_KERNEL);
14381439
if (!dai) {
1439-
kfree(swidget);
1440-
return -ENOMEM;
1441-
1440+
ret = -ENOMEM;
1441+
goto widget_free;
14421442
}
14431443

14441444
ret = sof_widget_parse_tokens(scomp, swidget, tw, token_list, token_list_size);
@@ -1496,8 +1496,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
14961496
tw->shift, swidget->id, tw->name,
14971497
strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
14981498
? tw->sname : "none");
1499-
kfree(swidget);
1500-
return ret;
1499+
goto widget_free;
15011500
}
15021501

15031502
if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE)) {
@@ -1518,10 +1517,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
15181517
if (ret) {
15191518
dev_err(scomp->dev, "widget event binding failed for %s\n",
15201519
swidget->widget->name);
1521-
kfree(swidget->private);
1522-
kfree(swidget->tuples);
1523-
kfree(swidget);
1524-
return ret;
1520+
goto free;
15251521
}
15261522
}
15271523
}
@@ -1532,10 +1528,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
15321528

15331529
spipe = kzalloc(sizeof(*spipe), GFP_KERNEL);
15341530
if (!spipe) {
1535-
kfree(swidget->private);
1536-
kfree(swidget->tuples);
1537-
kfree(swidget);
1538-
return -ENOMEM;
1531+
ret = -ENOMEM;
1532+
goto free;
15391533
}
15401534

15411535
spipe->pipe_widget = swidget;
@@ -1546,6 +1540,12 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
15461540
w->dobj.private = swidget;
15471541
list_add(&swidget->list, &sdev->widget_list);
15481542
return ret;
1543+
free:
1544+
kfree(swidget->private);
1545+
kfree(swidget->tuples);
1546+
widget_free:
1547+
kfree(swidget);
1548+
return ret;
15491549
}
15501550

15511551
static int sof_route_unload(struct snd_soc_component *scomp,

0 commit comments

Comments
 (0)