aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-03-20 11:26:15 -0400
committerTakashi Iwai <tiwai@suse.de>2009-03-20 11:26:15 -0400
commit8b22d943c34b616eefbd6d2f8f197a53b1f29fd0 (patch)
tree48f8b24ff0d9f41cfa13c764f42a0a05f493ce82
parentded652f7024bc2d7b6118b561a44187af30841b0 (diff)
ALSA: pcm - Safer boundary checks
Make the boundary checks a bit safer. These caese are rare or theoretically won't happen, but nothing bad to keep the checks safer... Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/core/pcm_lib.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 063c675177a9..fbb2e391591e 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -222,8 +222,9 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
222 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size; 222 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
223 delta = new_hw_ptr - hw_ptr_interrupt; 223 delta = new_hw_ptr - hw_ptr_interrupt;
224 if (hw_ptr_interrupt >= runtime->boundary) { 224 if (hw_ptr_interrupt >= runtime->boundary) {
225 hw_ptr_interrupt %= runtime->boundary; 225 hw_ptr_interrupt -= runtime->boundary;
226 if (!hw_base) /* hw_base was already lapped; recalc delta */ 226 if (hw_base < runtime->boundary / 2)
227 /* hw_base was already lapped; recalc delta */
227 delta = new_hw_ptr - hw_ptr_interrupt; 228 delta = new_hw_ptr - hw_ptr_interrupt;
228 } 229 }
229 if (delta < 0) { 230 if (delta < 0) {
@@ -241,7 +242,7 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
241 delta = 0; 242 delta = 0;
242 } else { 243 } else {
243 hw_base += runtime->buffer_size; 244 hw_base += runtime->buffer_size;
244 if (hw_base == runtime->boundary) 245 if (hw_base >= runtime->boundary)
245 hw_base = 0; 246 hw_base = 0;
246 new_hw_ptr = hw_base + pos; 247 new_hw_ptr = hw_base + pos;
247 } 248 }
@@ -296,7 +297,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
296 return 0; 297 return 0;
297 } 298 }
298 hw_base += runtime->buffer_size; 299 hw_base += runtime->buffer_size;
299 if (hw_base == runtime->boundary) 300 if (hw_base >= runtime->boundary)
300 hw_base = 0; 301 hw_base = 0;
301 new_hw_ptr = hw_base + pos; 302 new_hw_ptr = hw_base + pos;
302 } 303 }