Skip to content

Commit

Permalink
ASoC: Fix use after free
Browse files Browse the repository at this point in the history
Freeing the current list element while iterating over the list will cause a use
after free since the iterator function will still use the current element to
look up the next. Use list_for_each_safe() and remove the element from the list
before freeing it to avoid this.

Fixes: 1438c2f ("ASoC: Add a per component dai list")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Mar 12, 2014
1 parent 1438c2f commit 5c1d5f0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3913,11 +3913,12 @@ static inline char *fmt_multiple_name(struct device *dev,
*/
static void snd_soc_unregister_dais(struct snd_soc_component *component)
{
struct snd_soc_dai *dai;
struct snd_soc_dai *dai, *_dai;

list_for_each_entry(dai, &component->dai_list, list) {
list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
dai->name);
list_del(&dai->list);
kfree(dai->name);
kfree(dai);
}
Expand Down

0 comments on commit 5c1d5f0

Please sign in to comment.