aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorGregory CLEMENT <gregory.clement@bootlin.com>2019-09-18 06:03:44 -0400
committerMark Brown <broonie@kernel.org>2019-09-18 06:12:24 -0400
commit0dce49efc70536a8c3b4bb5354a71b727ba31b80 (patch)
tree5ad1e15f8f6188b90de37bb6f0ab025ad07b106b /sound
parenta0a4bf57a977ed37bcbdfc8027a44485fe086a3d (diff)
ASoC: atmel_ssc_dai: Remove wrong spinlock usage
A potential bug was reported in the email "[BUG] atmel_ssc_dai: a possible sleep-in-atomic bug in atmel_ssc_shutdown"[1] Indeed in the function atmel_ssc_shutdown() free_irq() was called in a critical section protected by spinlock. However this spinlock is only used in atmel_ssc_shutdown() and atmel_ssc_startup() functions. After further analysis, it occurred that the call to these function are already protected by mutex used on the calling functions. Then we can remove the spinlock which will fix this bug as a side effect. Thanks to this patch the following message disappears: "BUG: sleeping function called from invalid context at kernel/locking/mutex.c:909" [1]: https://www.spinics.net/lists/alsa-devel/msg71286.html Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com> Link: https://lore.kernel.org/r/20190918100344.23629-1-gregory.clement@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c12
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.h1
2 files changed, 2 insertions, 11 deletions
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index 48e9eef34c0f..ca603397651c 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
116static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = { 116static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = {
117 { 117 {
118 .name = "ssc0", 118 .name = "ssc0",
119 .lock = __SPIN_LOCK_UNLOCKED(ssc_info[0].lock),
120 .dir_mask = SSC_DIR_MASK_UNUSED, 119 .dir_mask = SSC_DIR_MASK_UNUSED,
121 .initialized = 0, 120 .initialized = 0,
122 }, 121 },
123 { 122 {
124 .name = "ssc1", 123 .name = "ssc1",
125 .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock),
126 .dir_mask = SSC_DIR_MASK_UNUSED, 124 .dir_mask = SSC_DIR_MASK_UNUSED,
127 .initialized = 0, 125 .initialized = 0,
128 }, 126 },
129 { 127 {
130 .name = "ssc2", 128 .name = "ssc2",
131 .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock),
132 .dir_mask = SSC_DIR_MASK_UNUSED, 129 .dir_mask = SSC_DIR_MASK_UNUSED,
133 .initialized = 0, 130 .initialized = 0,
134 }, 131 },
@@ -317,13 +314,10 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
317 314
318 snd_soc_dai_set_dma_data(dai, substream, dma_params); 315 snd_soc_dai_set_dma_data(dai, substream, dma_params);
319 316
320 spin_lock_irq(&ssc_p->lock); 317 if (ssc_p->dir_mask & dir_mask)
321 if (ssc_p->dir_mask & dir_mask) {
322 spin_unlock_irq(&ssc_p->lock);
323 return -EBUSY; 318 return -EBUSY;
324 } 319
325 ssc_p->dir_mask |= dir_mask; 320 ssc_p->dir_mask |= dir_mask;
326 spin_unlock_irq(&ssc_p->lock);
327 321
328 return 0; 322 return 0;
329} 323}
@@ -355,7 +349,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
355 349
356 dir_mask = 1 << dir; 350 dir_mask = 1 << dir;
357 351
358 spin_lock_irq(&ssc_p->lock);
359 ssc_p->dir_mask &= ~dir_mask; 352 ssc_p->dir_mask &= ~dir_mask;
360 if (!ssc_p->dir_mask) { 353 if (!ssc_p->dir_mask) {
361 if (ssc_p->initialized) { 354 if (ssc_p->initialized) {
@@ -369,7 +362,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
369 ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0; 362 ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
370 ssc_p->forced_divider = 0; 363 ssc_p->forced_divider = 0;
371 } 364 }
372 spin_unlock_irq(&ssc_p->lock);
373 365
374 /* Shutdown the SSC clock. */ 366 /* Shutdown the SSC clock. */
375 pr_debug("atmel_ssc_dai: Stopping clock\n"); 367 pr_debug("atmel_ssc_dai: Stopping clock\n");
diff --git a/sound/soc/atmel/atmel_ssc_dai.h b/sound/soc/atmel/atmel_ssc_dai.h
index ae764cb541c7..3470b966e449 100644
--- a/sound/soc/atmel/atmel_ssc_dai.h
+++ b/sound/soc/atmel/atmel_ssc_dai.h
@@ -93,7 +93,6 @@ struct atmel_ssc_state {
93struct atmel_ssc_info { 93struct atmel_ssc_info {
94 char *name; 94 char *name;
95 struct ssc_device *ssc; 95 struct ssc_device *ssc;
96 spinlock_t lock; /* lock for dir_mask */
97 unsigned short dir_mask; /* 0=unused, 1=playback, 2=capture */ 96 unsigned short dir_mask; /* 0=unused, 1=playback, 2=capture */
98 unsigned short initialized; /* true if SSC has been initialized */ 97 unsigned short initialized; /* true if SSC has been initialized */
99 unsigned short daifmt; 98 unsigned short daifmt;