summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-03-20 16:26:15 +0100
committerTakashi Iwai <tiwai@suse.de>2009-03-20 16:26:15 +0100
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)
hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
delta = new_hw_ptr - hw_ptr_interrupt;
if (hw_ptr_interrupt >= runtime->boundary) {
- hw_ptr_interrupt %= runtime->boundary;
- if (!hw_base) /* hw_base was already lapped; recalc delta */
+ hw_ptr_interrupt -= runtime->boundary;
+ if (hw_base < runtime->boundary / 2)
+ /* hw_base was already lapped; recalc delta */
delta = new_hw_ptr - hw_ptr_interrupt;
}
if (delta < 0) {
@@ -241,7 +242,7 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
delta = 0;
} else {
hw_base += runtime->buffer_size;
- if (hw_base == runtime->boundary)
+ if (hw_base >= runtime->boundary)
hw_base = 0;
new_hw_ptr = hw_base + pos;
}
@@ -296,7 +297,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
return 0;
}
hw_base += runtime->buffer_size;
- if (hw_base == runtime->boundary)
+ if (hw_base >= runtime->boundary)
hw_base = 0;
new_hw_ptr = hw_base + pos;
}