ASoC: atmel_ssc_dai: Remove wrong spinlock usage
PATCH 1/1 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
--- sound/soc/atmel/atmel_ssc_dai.c | 7 ------- 1 file changed, 7 deletions(-)
sound/soc/atmel/atmel_ssc_dai.c +0 -7
@@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES ] = { { .name ="ssc0" , - .lock =__SPIN_LOCK_UNLOCKED (ssc_info[0 ].lock), .dir_mask =SSC_DIR_MASK_UNUSED , .initialized =0 , }, { .name ="ssc1" , - .lock =__SPIN_LOCK_UNLOCKED (ssc_info[1 ].lock), .dir_mask =SSC_DIR_MASK_UNUSED , .initialized =0 , }, { .name ="ssc2" , - .lock =__SPIN_LOCK_UNLOCKED (ssc_info[2 ].lock), .dir_mask =SSC_DIR_MASK_UNUSED , .initialized =0 , },
@@ -317,13 +314,11 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,snd_soc_dai_set_dma_data (dai, substream, dma_params); -spin_lock_irq (&ssc_p->lock);if (ssc_p->dir_mask & dir_mask) {spin_unlock_irq (&ssc_p->lock);return -EBUSY ; } ssc_p->dir_mask |= dir_mask; -spin_unlock_irq (&ssc_p->lock);return 0 ; }
@@ -355,7 +350,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, dir_mask =1 << dir; -spin_lock_irq (&ssc_p->lock); ssc_p->dir_mask &= ~dir_mask;if (!ssc_p->dir_mask) {if (ssc_p->initialized) {
@@ -369,7 +363,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period =0 ; ssc_p->forced_divider =0 ; } -spin_unlock_irq (&ssc_p->lock);/* Shutdown the SSC clock. */ pr_debug ("atmel_ssc_dai: Stopping clock\n" );
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerQuoted 29 lines · Gregory CLEMENT
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()andatmel_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
Signed-off-by Gregory CLEMENT <[email protected]>--- sound/soc/atmel/atmel_ssc_dai.c | 7 ------- 1 file changed, 7 deletions(-)sound/soc/atmel/atmel_ssc_dai.c +0
-0
sound/soc/atmel/atmel_ssc_dai.c static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = { · line 119
Quoted 4 lines
sound/soc/atmel/atmel_ssc_dai.c +0
-1@@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES ] = { { .name ="ssc0" , - .lock =__SPIN_LOCK_UNLOCKED (ssc_info[0 ].lock),
This member is now unused and can be removed from the struct.
Once fixed, Reviewed-by: Alexandre Belloni <[email protected]>
Quoted 48 lines
sound/soc/atmel/atmel_ssc_dai.c +0
-6.dir_mask = SSC_DIR_MASK_UNUSED, .initialized = 0, }, { .name = "ssc1", - .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock), .dir_mask = SSC_DIR_MASK_UNUSED, .initialized = 0, }, { .name = "ssc2", - .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock), .dir_mask = SSC_DIR_MASK_UNUSED, .initialized = 0, },@@ -317,13 +314,11 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,snd_soc_dai_set_dma_data (dai, substream, dma_params); -spin_lock_irq (&ssc_p->lock);if (ssc_p->dir_mask & dir_mask) {spin_unlock_irq (&ssc_p->lock);return -EBUSY ; } ssc_p->dir_mask |= dir_mask; -spin_unlock_irq (&ssc_p->lock);return 0 ; }@@ -355,7 +350,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, dir_mask =1 << dir; -spin_lock_irq (&ssc_p->lock); ssc_p->dir_mask &= ~dir_mask;if (!ssc_p->dir_mask) {if (ssc_p->initialized) {@@ -369,7 +363,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period =0 ; ssc_p->forced_divider =0 ; } -spin_unlock_irq (&ssc_p->lock);/* Shutdown the SSC clock. */ pr_debug ("atmel_ssc_dai: Stopping clock\n" );Signature · 1 line
2.23.0
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hi Alex,
Quoted 37 lines · Gregory CLEMENT
Quoted 29 lines
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()andatmel_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
Signed-off-by Gregory CLEMENT <[email protected]>--- sound/soc/atmel/atmel_ssc_dai.c | 7 ------- 1 file changed, 7 deletions(-)sound/soc/atmel/atmel_ssc_dai.c +0
-0sound/soc/atmel/atmel_ssc_dai.c static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = { · line 119
Quoted 4 lines
sound/soc/atmel/atmel_ssc_dai.c +0
-1@@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES ] = { { .name ="ssc0" , - .lock =__SPIN_LOCK_UNLOCKED (ssc_info[0 ].lock),This member is now unused and can be removed from the struct.
Quoted 2 lines
Once fixed, Reviewed-by: Alexandre Belloni
<[email protected]>
Indeed I wanted to do this but finally forgot.
I am sending a v2.
Thanks,
Gregory
Quoted 54 lines
Quoted 49 lines
sound/soc/atmel/atmel_ssc_dai.c +0
-6.dir_mask = SSC_DIR_MASK_UNUSED, .initialized = 0, }, { .name = "ssc1", - .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock), .dir_mask = SSC_DIR_MASK_UNUSED, .initialized = 0, }, { .name = "ssc2", - .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock), .dir_mask = SSC_DIR_MASK_UNUSED, .initialized = 0, },@@ -317,13 +314,11 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,snd_soc_dai_set_dma_data (dai, substream, dma_params); -spin_lock_irq (&ssc_p->lock);if (ssc_p->dir_mask & dir_mask) {spin_unlock_irq (&ssc_p->lock);return -EBUSY ; } ssc_p->dir_mask |= dir_mask; -spin_unlock_irq (&ssc_p->lock);return 0 ; }@@ -355,7 +350,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, dir_mask =1 << dir; -spin_lock_irq (&ssc_p->lock); ssc_p->dir_mask &= ~dir_mask;if (!ssc_p->dir_mask) {if (ssc_p->initialized) {@@ -369,7 +363,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period =0 ; ssc_p->forced_divider =0 ; } -spin_unlock_irq (&ssc_p->lock);/* Shutdown the SSC clock. */ pr_debug ("atmel_ssc_dai: Stopping clock\n" );Signature · 1 line
2.23.0Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Signature · 3 lines
Gregory Clement, Bootlin Embedded Linux and Kernel engineering http://bootlin.com