ASoC: Fix Blackfin I2S _pointer() implementation return in bounds values
PATCH 1/1 ASoC: Fix Blackfin I2S _pointer() implementation return in bounds values
The Blackfin DMA controller can report one frame beyond the end of the buffer in the wraparound case but ALSA requires that the pointer always be in the buffer. Do the wraparound to handle this. A similar bug is likely to apply to the other Blackfin PCM drivers but the code is less obvious to inspection and I don't have a user to test.
--- sound/soc/blackfin/bf5xx-i2s-pcm.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
sound/soc/blackfin/bf5xx-i2s-pcm.c +12 -2
@@ -138,11 +138,21 @@ static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream)pr_debug ("%s enter\n" , __func__);if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { diff =sport_curr_offset_tx (sport); - frames =bytes_to_frames (substream->runtime, diff); }else { diff =sport_curr_offset_rx (sport); - frames =bytes_to_frames (substream->runtime, diff); } + +/* +* TX at least can report one frame beyond the end of the +* buffer if we hit the wraparound case - clamp to within the +* buffer as the ALSA APIs require. +*/ +if (diff ==snd_pcm_lib_buffer_bytes (substream)) + diff =0 ; + } + + frames =bytes_to_frames (substream->runtime, diff); +return frames; }
Signature · 1 line
1.7.5.4
sound/soc/blackfin/bf5xx-i2s-pcm.c static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream) · line 152
Quoted 4 lines · Mark Brown
[...]
sound/soc/blackfin/bf5xx-i2s-pcm.c +3
-0+if (diff ==snd_pcm_lib_buffer_bytes (substream)) + diff =0 ; + }
stray closing bracket
sound/soc/blackfin/bf5xx-i2s-pcm.c static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream) · line 156
Quoted 3 lines
sound/soc/blackfin/bf5xx-i2s-pcm.c +2
-0+ frames =bytes_to_frames (substream->runtime, diff); +return frames;
Could be 'return bytes_to_frames(substream->runtime, diff);' directly
Quoted 7 lines · Lars-Peter Clausen
sound/soc/blackfin/bf5xx-i2s-pcm.c static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream) · line 152
Quoted 4 lines · Mark Brown
[...]
sound/soc/blackfin/bf5xx-i2s-pcm.c +3
-0+if (diff ==snd_pcm_lib_buffer_bytes (substream)) + diff =0 ; + }stray closing bracket
Hrm, so there is. Fixed locally, I guess there's no point in reposting just for that.
Quoted 5 lines
sound/soc/blackfin/bf5xx-i2s-pcm.c static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream) · line 156
Quoted 3 lines
sound/soc/blackfin/bf5xx-i2s-pcm.c +2
-0+ frames =bytes_to_frames (substream->runtime, diff); +return frames;Could be 'return
bytes_to_frames(substream->runtime, diff);' directly
Does no harm either way, though. I don't always find doing the return directly quite so parsable, but I think here I wrote it this way because it makes the diff a bit more obvious.
Quoted 8 lines · Mark Brown
The Blackfin DMA controller can report one frame beyond the end of the buffer in the wraparound case but ALSA requires that the pointer always be in the buffer. Do the wraparound to handle this. A similar bug is likely to apply to the other Blackfin PCM drivers but the code is less obvious to inspection and I don't have a user to test.
Signed-off-by Mark Brown <[email protected]>---