diff options
author | Takashi Iwai <tiwai@suse.de> | 2011-03-18 02:31:53 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-03-18 02:31:53 -0400 |
commit | 98d21df431ad55281e1abf780f8d51e3391900b2 (patch) | |
tree | 19d365c9407ce581098596ec913a9cdb9ff7dd8a /sound/drivers | |
parent | 5b7c757d1a8878d49f46c826d6081816935664aa (diff) |
ALSA: aloop - Fix possible IRQ lock inversion
loopback_pos_update() can be called in the timer callback, thus the lock
held should be irq-safe. Otherwise you'll get AB/BA deadlock together
with substream->self_group.lock.
Reported-and-tested-by: Knut Petersen <Knut_Petersen@t-online.de>
Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/drivers')
-rw-r--r-- | sound/drivers/aloop.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index 12b44b0b6777..a0da7755fcea 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c | |||
@@ -482,8 +482,9 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable) | |||
482 | cable->streams[SNDRV_PCM_STREAM_CAPTURE]; | 482 | cable->streams[SNDRV_PCM_STREAM_CAPTURE]; |
483 | unsigned long delta_play = 0, delta_capt = 0; | 483 | unsigned long delta_play = 0, delta_capt = 0; |
484 | unsigned int running; | 484 | unsigned int running; |
485 | unsigned long flags; | ||
485 | 486 | ||
486 | spin_lock(&cable->lock); | 487 | spin_lock_irqsave(&cable->lock, flags); |
487 | running = cable->running ^ cable->pause; | 488 | running = cable->running ^ cable->pause; |
488 | if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) { | 489 | if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) { |
489 | delta_play = jiffies - dpcm_play->last_jiffies; | 490 | delta_play = jiffies - dpcm_play->last_jiffies; |
@@ -495,10 +496,8 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable) | |||
495 | dpcm_capt->last_jiffies += delta_capt; | 496 | dpcm_capt->last_jiffies += delta_capt; |
496 | } | 497 | } |
497 | 498 | ||
498 | if (delta_play == 0 && delta_capt == 0) { | 499 | if (delta_play == 0 && delta_capt == 0) |
499 | spin_unlock(&cable->lock); | 500 | goto unlock; |
500 | return running; | ||
501 | } | ||
502 | 501 | ||
503 | if (delta_play > delta_capt) { | 502 | if (delta_play > delta_capt) { |
504 | loopback_bytepos_update(dpcm_play, delta_play - delta_capt, | 503 | loopback_bytepos_update(dpcm_play, delta_play - delta_capt, |
@@ -510,14 +509,14 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable) | |||
510 | delta_capt = delta_play; | 509 | delta_capt = delta_play; |
511 | } | 510 | } |
512 | 511 | ||
513 | if (delta_play == 0 && delta_capt == 0) { | 512 | if (delta_play == 0 && delta_capt == 0) |
514 | spin_unlock(&cable->lock); | 513 | goto unlock; |
515 | return running; | 514 | |
516 | } | ||
517 | /* note delta_capt == delta_play at this moment */ | 515 | /* note delta_capt == delta_play at this moment */ |
518 | loopback_bytepos_update(dpcm_capt, delta_capt, BYTEPOS_UPDATE_COPY); | 516 | loopback_bytepos_update(dpcm_capt, delta_capt, BYTEPOS_UPDATE_COPY); |
519 | loopback_bytepos_update(dpcm_play, delta_play, BYTEPOS_UPDATE_POSONLY); | 517 | loopback_bytepos_update(dpcm_play, delta_play, BYTEPOS_UPDATE_POSONLY); |
520 | spin_unlock(&cable->lock); | 518 | unlock: |
519 | spin_unlock_irqrestore(&cable->lock, flags); | ||
521 | return running; | 520 | return running; |
522 | } | 521 | } |
523 | 522 | ||