alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: dapm: Fix race condition in widgets power list creation
@ 2011-01-18  2:36 Misael Lopez Cruz
  0 siblings, 0 replies; 10+ messages in thread
From: Misael Lopez Cruz @ 2011-01-18  2:36 UTC (permalink / raw)
  To: alsa-devel; +Cc: Misael Lopez Cruz, Mark Brown, Liam Girdwood

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-01-18 13:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
2011-01-18  2:36 Misael Lopez Cruz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).