diff mbox

[04/17,v2] ASoC: dapm: Add unlocked version of snd_soc_dapm_sync

Message ID 1392736948-26623-5-git-send-email-ckeepax@opensource.wolfsonmicro.com (mailing list archive)
State Accepted
Commit 3eb29dfb3d3bd4b600370007b96c3c675fb97aa7
Delegated to: Mark Brown
Headers show

Commit Message

Charles Keepax Feb. 18, 2014, 3:22 p.m. UTC
We will often call sync after several functions that require the DAPM
mutex to be held. Rather than release and immediately relock the mutex
provide an unlocked function for this situation.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
 include/sound/soc-dapm.h |    1 +
 sound/soc/soc-dapm.c     |   27 ++++++++++++++++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

Comments

Lars-Peter Clausen Feb. 18, 2014, 4:14 p.m. UTC | #1
On 02/18/2014 04:22 PM, Charles Keepax wrote:
> We will often call sync after several functions that require the DAPM
> mutex to be held. Rather than release and immediately relock the mutex
> provide an unlocked function for this situation.
>
> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

We should add lockdep_assert() to the unlocked versions to catch broken 
users, but that can be done in a follow-up patch.
Mark Brown Feb. 19, 2014, 3:28 a.m. UTC | #2
On Tue, Feb 18, 2014 at 05:14:27PM +0100, Lars-Peter Clausen wrote:

> We should add lockdep_assert() to the unlocked versions to catch
> broken users, but that can be done in a follow-up patch.

Yes, and not just in these ones either - we've got the other existing
APIs that should have annotations added as well.
Mark Brown Feb. 20, 2014, 10:24 a.m. UTC | #3
On Tue, Feb 18, 2014 at 03:22:15PM +0000, Charles Keepax wrote:
> We will often call sync after several functions that require the DAPM
> mutex to be held. Rather than release and immediately relock the mutex
> provide an unlocked function for this situation.

Applied, thanks.
diff mbox

Patch

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 6e89ef6..3b99176 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -461,6 +461,7 @@  int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
 				const char *pin);
 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
+int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm);
 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
 				  const char *pin);
 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 1a3fe85..cf8ba48 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2342,18 +2342,18 @@  static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
 }
 
 /**
- * snd_soc_dapm_sync - scan and power dapm paths
+ * snd_soc_dapm_sync_unlocked - scan and power dapm paths
  * @dapm: DAPM context
  *
  * Walks all dapm audio paths and powers widgets according to their
  * stream or path usage.
  *
+ * Requires external locking.
+ *
  * Returns 0 for success.
  */
-int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
+int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm)
 {
-	int ret;
-
 	/*
 	 * Suppress early reports (eg, jacks syncing their state) to avoid
 	 * silly DAPM runs during card startup.
@@ -2361,8 +2361,25 @@  int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
 	if (!dapm->card || !dapm->card->instantiated)
 		return 0;
 
+	return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked);
+
+/**
+ * snd_soc_dapm_sync - scan and power dapm paths
+ * @dapm: DAPM context
+ *
+ * Walks all dapm audio paths and powers widgets according to their
+ * stream or path usage.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
+{
+	int ret;
+
 	mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
-	ret = dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP);
+	ret = snd_soc_dapm_sync_unlocked(dapm);
 	mutex_unlock(&dapm->card->dapm_mutex);
 	return ret;
 }