| 1 |
From: Takashi Iwai <tiwai@suse.de>
|
| 2 |
Date: Fri, 20 Mar 2009 15:26:15 +0000 (+0100)
|
| 3 |
Subject: ALSA: pcm - Safer boundary checks
|
| 4 |
X-Git-Url: http://git.alsa-project.org/?p=alsa-kernel.git;a=commitdiff_plain;h=d9b59892fb7108f6ee33a4fcdc257587b68f2ed6
|
| 5 |
|
| 6 |
ALSA: pcm - Safer boundary checks
|
| 7 |
|
| 8 |
Make the boundary checks a bit safer.
|
| 9 |
These caese are rare or theoretically won't happen, but nothing
|
| 10 |
bad to keep the checks safer...
|
| 11 |
|
| 12 |
Signed-off-by: Takashi Iwai <tiwai@suse.de>
|
| 13 |
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
|
| 14 |
---
|
| 15 |
|
| 16 |
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
|
| 17 |
index 063c675..fbb2e39 100644
|
| 18 |
--- a/sound/core/pcm_lib.c
|
| 19 |
+++ b/sound/core/pcm_lib.c
|
| 20 |
@@ -222,8 +222,9 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
|
| 21 |
hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
|
| 22 |
delta = new_hw_ptr - hw_ptr_interrupt;
|
| 23 |
if (hw_ptr_interrupt >= runtime->boundary) {
|
| 24 |
- hw_ptr_interrupt %= runtime->boundary;
|
| 25 |
- if (!hw_base) /* hw_base was already lapped; recalc delta */
|
| 26 |
+ hw_ptr_interrupt -= runtime->boundary;
|
| 27 |
+ if (hw_base < runtime->boundary / 2)
|
| 28 |
+ /* hw_base was already lapped; recalc delta */
|
| 29 |
delta = new_hw_ptr - hw_ptr_interrupt;
|
| 30 |
}
|
| 31 |
if (delta < 0) {
|
| 32 |
@@ -241,7 +242,7 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
|
| 33 |
delta = 0;
|
| 34 |
} else {
|
| 35 |
hw_base += runtime->buffer_size;
|
| 36 |
- if (hw_base == runtime->boundary)
|
| 37 |
+ if (hw_base >= runtime->boundary)
|
| 38 |
hw_base = 0;
|
| 39 |
new_hw_ptr = hw_base + pos;
|
| 40 |
}
|
| 41 |
@@ -296,7 +297,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
|
| 42 |
return 0;
|
| 43 |
}
|
| 44 |
hw_base += runtime->buffer_size;
|
| 45 |
- if (hw_base == runtime->boundary)
|
| 46 |
+ if (hw_base >= runtime->boundary)
|
| 47 |
hw_base = 0;
|
| 48 |
new_hw_ptr = hw_base + pos;
|
| 49 |
}
|