Skip to content

Commit

Permalink
ASoC: SOF: topology: Fix error handling in sof_widget_ready()
Browse files Browse the repository at this point in the history
Fix the error paths in sof_widget_ready() to free all allocated memory
and prevent memory leaks.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20230307114815.4909-1-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
ranj063 authored and broonie committed Mar 7, 2023
1 parent 858a438 commit 6ba8ddf
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions sound/soc/sof/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,14 +1388,15 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
if (ret < 0) {
dev_err(scomp->dev, "failed to parse component pin tokens for %s\n",
w->name);
return ret;
goto widget_free;
}

if (swidget->num_sink_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",
swidget->widget->name, swidget->num_sink_pins, swidget->num_source_pins);
return -EINVAL;
ret = -EINVAL;
goto widget_free;
}

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

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

Expand All @@ -1436,9 +1437,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
case snd_soc_dapm_dai_out:
dai = kzalloc(sizeof(*dai), GFP_KERNEL);
if (!dai) {
kfree(swidget);
return -ENOMEM;

ret = -ENOMEM;
goto widget_free;
}

ret = sof_widget_parse_tokens(scomp, swidget, tw, token_list, token_list_size);
Expand Down Expand Up @@ -1496,8 +1496,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
tw->shift, swidget->id, tw->name,
strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0
? tw->sname : "none");
kfree(swidget);
return ret;
goto widget_free;
}

if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE)) {
Expand All @@ -1518,10 +1517,7 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
if (ret) {
dev_err(scomp->dev, "widget event binding failed for %s\n",
swidget->widget->name);
kfree(swidget->private);
kfree(swidget->tuples);
kfree(swidget);
return ret;
goto free;
}
}
}
Expand All @@ -1532,10 +1528,8 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,

spipe = kzalloc(sizeof(*spipe), GFP_KERNEL);
if (!spipe) {
kfree(swidget->private);
kfree(swidget->tuples);
kfree(swidget);
return -ENOMEM;
ret = -ENOMEM;
goto free;
}

spipe->pipe_widget = swidget;
Expand All @@ -1546,6 +1540,12 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
w->dobj.private = swidget;
list_add(&swidget->list, &sdev->widget_list);
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,
Expand Down

0 comments on commit 6ba8ddf

Please sign in to comment.