diff options
author | Kelly Anderson <kelly@silka.with-linux.com> | 2011-04-01 05:58:25 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-04-01 12:01:23 -0400 |
commit | 12ff414e2e4512f59fe191dc18e856e2939a1c79 (patch) | |
tree | 7aa36c6a9f80f749cd36251c8e2c31990cef3270 /sound/core | |
parent | 840126579da56edae8ecc4a0d85198f742982f10 (diff) |
ALSA: pcm: fix infinite loop in snd_pcm_update_hw_ptr0()
When period interrupts are disabled, snd_pcm_update_hw_ptr0() compares
the current time against the time estimated for the current hardware
pointer to detect xruns. The somewhat fuzzy threshold in the while loop
makes it possible that hdelta becomes negative; the comparison being
done with unsigned types then makes the loop go through the entire 263
negative range, and, depending on the value, never reach an unsigned
value that is small enough to stop the loop. Doing this with interrupts
disabled results in the machine locking up.
To prevent this, ensure that the loop condition uses signed types for
both operands so that the comparison is correctly done.
Many thanks to Kelly Anderson for debugging this.
Reported-by: Nix <nix@esperi.org.uk>
Reported-by: "Christopher K." <c.krooss@googlemail.com>
Reported-and-tested-by: Kelly Anderson <kelly@silka.with-linux.com>
Signed-off-by: Kelly Anderson <kelly@silka.with-linux.com>
[cl: remove unneeded casts; use a temp variable]
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Cc: 2.6.38 <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/pcm_lib.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index a82e3756a72d..64449cb8f873 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c | |||
@@ -375,6 +375,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, | |||
375 | } | 375 | } |
376 | 376 | ||
377 | if (runtime->no_period_wakeup) { | 377 | if (runtime->no_period_wakeup) { |
378 | snd_pcm_sframes_t xrun_threshold; | ||
378 | /* | 379 | /* |
379 | * Without regular period interrupts, we have to check | 380 | * Without regular period interrupts, we have to check |
380 | * the elapsed time to detect xruns. | 381 | * the elapsed time to detect xruns. |
@@ -383,7 +384,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, | |||
383 | if (jdelta < runtime->hw_ptr_buffer_jiffies / 2) | 384 | if (jdelta < runtime->hw_ptr_buffer_jiffies / 2) |
384 | goto no_delta_check; | 385 | goto no_delta_check; |
385 | hdelta = jdelta - delta * HZ / runtime->rate; | 386 | hdelta = jdelta - delta * HZ / runtime->rate; |
386 | while (hdelta > runtime->hw_ptr_buffer_jiffies / 2 + 1) { | 387 | xrun_threshold = runtime->hw_ptr_buffer_jiffies / 2 + 1; |
388 | while (hdelta > xrun_threshold) { | ||
387 | delta += runtime->buffer_size; | 389 | delta += runtime->buffer_size; |
388 | hw_base += runtime->buffer_size; | 390 | hw_base += runtime->buffer_size; |
389 | if (hw_base >= runtime->boundary) | 391 | if (hw_base >= runtime->boundary) |