ASoC: dapm: Fix race condition in widgets power list creation
PATCH 1/1 ASoC: dapm: Fix race condition in widgets power list creation
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 <[email protected]>
--- include/sound/soc.h | 1 + sound/soc/soc-core.c | 1 + sound/soc/soc-dapm.c | 2 ++ 3 files changed, 4 insertions(+), 0 deletions(-)
include/sound/soc.h +1 -0
@@ -614,6 +614,7 @@ struct snd_soc_card {struct list_head list;struct mutex mutex; +struct mutex dapm_mutex;bool instantiated;
sound/soc/soc-core.c +1 -0
@@ -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);
sound/soc/soc-dapm.c +2 -0
@@ -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.
Signature · 1 line
1.6.3.3