Skip to content

Commit

Permalink
ASoC: dapm: Lock during userspace access
Browse files Browse the repository at this point in the history
[ Upstream commit d90d066 ]

commit e50b1e0 upstream.

The DAPM lock must be held when accessing the DAPM graph status through
sysfs or debugfs, otherwise concurrent changes to the graph can result in
undefined behaviour.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
larsclausen authored and sashalevin committed Aug 22, 2015
1 parent ddc4232 commit 30f6445
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sound/soc/soc-dapm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
size_t count, loff_t *ppos)
{
struct snd_soc_dapm_widget *w = file->private_data;
struct snd_soc_card *card = w->dapm->card;
char *buf;
int in, out;
ssize_t ret;
Expand All @@ -1863,6 +1864,8 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
if (!buf)
return -ENOMEM;

mutex_lock(&card->dapm_mutex);

in = is_connected_input_ep(w, NULL);
dapm_clear_walk_input(w->dapm, &w->sources);
out = is_connected_output_ep(w, NULL);
Expand Down Expand Up @@ -1905,6 +1908,8 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
p->sink->name);
}

mutex_unlock(&card->dapm_mutex);

ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);

kfree(buf);
Expand Down Expand Up @@ -2165,11 +2170,15 @@ static ssize_t dapm_widget_show(struct device *dev,
struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
int i, count = 0;

mutex_lock(&rtd->card->dapm_mutex);

for (i = 0; i < rtd->num_codecs; i++) {
struct snd_soc_codec *codec = rtd->codec_dais[i]->codec;
count += dapm_widget_show_codec(codec, buf + count);
}

mutex_unlock(&rtd->card->dapm_mutex);

return count;
}

Expand Down

0 comments on commit 30f6445

Please sign in to comment.