[lkml]   [2010]   [Jul]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[024/200] ALSA: pcm: fix delta calculation at boundary wraparound
2.6.34-stable review patch.  If anyone has any objections, please let me know.


From: Clemens Ladisch <>

commit b406e6103baa3da85950f22d3d46d21a8da654c5 upstream.

In the cleanup of the hw_ptr update functions in 2.6.33, the calculation
of the delta value was changed to use the modulo operator to protect
against a negative difference due to the pointer wrapping around at the

However, the ptr variables are unsigned, so a negative difference would
result in the two complement's value which has no relation to the actual
difference relative to the boundary; the result is typically some value
near LONG_MAX-boundary. Furthermore, even if the modulo operation would
be done with signed types, the result of a negative dividend could be

The invalid delta value is then caught by the following checks, but this
means that the pointer update is ignored.

To fix this, use a range check as in the other pointer calculations.

Signed-off-by: Clemens Ladisch <>
Signed-off-by: Takashi Iwai <>
Signed-off-by: Greg Kroah-Hartman <>

sound/core/pcm_lib.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -345,7 +345,9 @@ static int snd_pcm_update_hw_ptr0(struct
new_hw_ptr = hw_base + pos;
- delta = (new_hw_ptr - old_hw_ptr) % runtime->boundary;
+ delta = new_hw_ptr - old_hw_ptr;
+ if (delta < 0)
+ delta += runtime->boundary;
if (xrun_debug(substream, in_interrupt ?
char name[16];

 \ /
  Last update: 2010-07-02 00:05    [W:1.022 / U:3.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site