From: Misael Lopez Cruz <misael.lopez@ti.com>
To: alsa-devel@alsa-project.org
Cc: Misael Lopez Cruz <misael.lopez@ti.com>,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
Liam Girdwood <lrg@slimlogic.co.uk>
Subject: [PATCH] ASoC: dapm: Fix race condition in widgets power list creation
Date: Mon, 17 Jan 2011 20:36:36 -0600 [thread overview]
Message-ID: <1295318196-18136-1-git-send-email-misael.lopez@ti.com> (raw)
Multiple calls to dapm_power_widgets() can create a race condition
causing power list to be corrupted. Those scenarios can occur in
multistream usecases, stream start/stop along with simultaneous
update power calls (mixer, mux, dapm_sync, stream_event).
A new 'dapm_mutex' is added to soc_card, which is held while power
list is created.
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
---
include/sound/soc.h | 1 +
sound/soc/soc-core.c | 1 +
sound/soc/soc-dapm.c | 2 ++
3 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 7e65b01..3dfc608 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -614,6 +614,7 @@ struct snd_soc_card {
struct list_head list;
struct mutex mutex;
+ struct mutex dapm_mutex;
bool instantiated;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 1dc4b11..583a821 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3124,6 +3124,7 @@ static int snd_soc_register_card(struct snd_soc_card *card)
INIT_LIST_HEAD(&card->list);
card->instantiated = 0;
mutex_init(&card->mutex);
+ mutex_init(&card->dapm_mutex);
mutex_lock(&client_mutex);
list_add(&card->list, &card_list);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 3d310af..faee456 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -940,6 +940,7 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
/* Check which widgets we need to power and store them in
* lists indicating if they should be powered up or down.
*/
+ mutex_lock(&card->dapm_mutex);
list_for_each_entry(w, &dapm->widgets, list) {
switch (w->id) {
case snd_soc_dapm_pre:
@@ -974,6 +975,7 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
break;
}
}
+ mutex_unlock(&card->dapm_mutex);
/* If there are no DAPM widgets then try to figure out power from the
* event type.
--
1.6.3.3
next reply other threads:[~2011-01-18 2:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-18 2:36 Misael Lopez Cruz [this message]
[not found] <1295318127-17968-1-git-send-email-misael.lopez@ti.com>
2011-01-18 10:39 ` [PATCH] ASoC: dapm: Fix race condition in widgets power list creation Mark Brown
[not found] ` <4D357B09.70505@nokia.com>
2011-01-18 11:39 ` Mark Brown
2011-01-18 12:08 ` Peter Ujfalusi
2011-01-18 12:26 ` Mark Brown
2011-01-18 12:47 ` Peter Ujfalusi
2011-01-18 13:21 ` Jarkko Nikula
2011-01-18 13:23 ` Mark Brown
2011-01-18 12:34 ` Peter Ujfalusi
2011-01-18 13:22 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295318196-18136-1-git-send-email-misael.lopez@ti.com \
--to=misael.lopez@ti.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=lrg@slimlogic.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.