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)
committerLeann Ogasawara <leann.ogasawara@canonical.com>
Tue, 5 Apr 2011 16:36:56 +0000 (09:36 -0700)
commit5398cec3d708aff1da329b65bc74a8b89ef7ccaa
tree88d343c36969e871ea678996c6d344283e1baf8a
parent24f4bfca420b951c9f924aaa2c922e96cbad5346
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>
(cherry picked from commit 12ff414e2e4512f59fe191dc18e856e2939a1c79)

Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
sound/core/pcm_lib.c