Commit 6ba8ddf8 authored by Ranjani Sridharan's avatar Ranjani Sridharan Committed by Mark Brown

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: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: default avatarPéter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20230307114815.4909-1-peter.ujfalusi@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 858a438a
...@@ -1388,14 +1388,15 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, ...@@ -1388,14 +1388,15 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "failed to parse component pin tokens for %s\n", dev_err(scomp->dev, "failed to parse component pin tokens for %s\n",
w->name); w->name);
return ret; goto widget_free;
} }
if (swidget->num_sink_pins > SOF_WIDGET_MAX_NUM_PINS || if (swidget->num_sink_pins > SOF_WIDGET_MAX_NUM_PINS ||
swidget->num_source_pins > SOF_WIDGET_MAX_NUM_PINS) { swidget->num_source_pins > SOF_WIDGET_MAX_NUM_PINS) {
dev_err(scomp->dev, "invalid pins for %s: [sink: %d, src: %d]\n", dev_err(scomp->dev, "invalid pins for %s: [sink: %d, src: %d]\n",
swidget->widget->name, swidget->num_sink_pins, swidget->num_source_pins); swidget->widget->name, swidget->num_sink_pins, swidget->num_source_pins);
return -EINVAL; ret = -EINVAL;
goto widget_free;
} }
if (swidget->num_sink_pins > 1) { if (swidget->num_sink_pins > 1) {
...@@ -1404,7 +1405,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, ...@@ -1404,7 +1405,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "failed to parse sink pin binding for %s\n", dev_err(scomp->dev, "failed to parse sink pin binding for %s\n",
w->name); w->name);
return ret; goto widget_free;
} }
} }
...@@ -1414,7 +1415,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, ...@@ -1414,7 +1415,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "failed to parse source pin binding for %s\n", dev_err(scomp->dev, "failed to parse source pin binding for %s\n",
w->name); w->name);
return ret; goto widget_free;
} }
} }
...@@ -1436,9 +1437,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, ...@@ -1436,9 +1437,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
case snd_soc_dapm_dai_out: case snd_soc_dapm_dai_out:
dai = kzalloc(sizeof(*dai), GFP_KERNEL); dai = kzalloc(sizeof(*dai), GFP_KERNEL);
if (!dai) { if (!dai) {
kfree(swidget); ret = -ENOMEM;
return -ENOMEM; goto widget_free;
} }
ret = sof_widget_parse_tokens(scomp, swidget, tw, token_list, token_list_size); 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, ...@@ -1496,8 +1496,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
tw->shift, swidget->id, tw->name, tw->shift, swidget->id, tw->name,
strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0 strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
? tw->sname : "none"); ? tw->sname : "none");
kfree(swidget); goto widget_free;
return ret;
} }
if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE)) { 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, ...@@ -1518,10 +1517,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
if (ret) { if (ret) {
dev_err(scomp->dev, "widget event binding failed for %s\n", dev_err(scomp->dev, "widget event binding failed for %s\n",
swidget->widget->name); swidget->widget->name);
kfree(swidget->private); goto free;
kfree(swidget->tuples);
kfree(swidget);
return ret;
} }
} }
} }
...@@ -1532,10 +1528,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, ...@@ -1532,10 +1528,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
spipe = kzalloc(sizeof(*spipe), GFP_KERNEL); spipe = kzalloc(sizeof(*spipe), GFP_KERNEL);
if (!spipe) { if (!spipe) {
kfree(swidget->private); ret = -ENOMEM;
kfree(swidget->tuples); goto free;
kfree(swidget);
return -ENOMEM;
} }
spipe->pipe_widget = swidget; spipe->pipe_widget = swidget;
...@@ -1546,6 +1540,12 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index, ...@@ -1546,6 +1540,12 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
w->dobj.private = swidget; w->dobj.private = swidget;
list_add(&swidget->list, &sdev->widget_list); list_add(&swidget->list, &sdev->widget_list);
return ret; return ret;
free:
kfree(swidget->private);
kfree(swidget->tuples);
widget_free:
kfree(swidget);
return ret;
} }
static int sof_route_unload(struct snd_soc_component *scomp, static int sof_route_unload(struct snd_soc_component *scomp,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment