]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ALSA: pcm: fix infinite loop in snd_pcm_update_hw_ptr0()
authorKelly Anderson <kelly@silka.with-linux.com>
Fri, 1 Apr 2011 09:58:25 +0000 (11:58 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 1 Apr 2011 16:01:23 +0000 (18:01 +0200)
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>
sound/core/pcm_lib.c

index a82e3756a72d8b95d49834e3ab61d08c6bf4d1d1..64449cb8f873774a91eb836973c1ab0a1ad2d9b8 100644 (file)
@@ -375,6 +375,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
        }
 
        if (runtime->no_period_wakeup) {
+               snd_pcm_sframes_t xrun_threshold;
                /*
                 * Without regular period interrupts, we have to check
                 * the elapsed time to detect xruns.
@@ -383,7 +384,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
                if (jdelta < runtime->hw_ptr_buffer_jiffies / 2)
                        goto no_delta_check;
                hdelta = jdelta - delta * HZ / runtime->rate;
-               while (hdelta > runtime->hw_ptr_buffer_jiffies / 2 + 1) {
+               xrun_threshold = runtime->hw_ptr_buffer_jiffies / 2 + 1;
+               while (hdelta > xrun_threshold) {
                        delta += runtime->buffer_size;
                        hw_base += runtime->buffer_size;
                        if (hw_base >= runtime->boundary)