Commit 1c583063 authored by Clemens Ladisch's avatar Clemens Ladisch Committed by Takashi Iwai

ALSA: cmipci: work around invalid PCM pointer

When the CMI8738 FRAME2 register is read, the chip sometimes (probably
when wrapping around) returns an invalid value that would be outside the
programmed DMA buffer. This leads to an inconsistent PCM pointer that is
likely to result in an underrun.

To work around this, read the register multiple times until we get a
valid value; the error state seems to be very short-lived.
Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
Reported-and-tested-by: default avatarMatija Nalis <mnalis-alsadev@voyager.hr>
Cc: <stable@kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent fc8aa7b1
...@@ -941,13 +941,21 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci ...@@ -941,13 +941,21 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
size_t ptr; size_t ptr;
unsigned int reg; unsigned int reg, rem, tries;
if (!rec->running) if (!rec->running)
return 0; return 0;
#if 1 // this seems better.. #if 1 // this seems better..
reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
ptr = rec->dma_size - (snd_cmipci_read_w(cm, reg) + 1); for (tries = 0; tries < 3; tries++) {
ptr >>= rec->shift; rem = snd_cmipci_read_w(cm, reg);
if (rem < rec->dma_size)
goto ok;
}
printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem);
return SNDRV_PCM_POS_XRUN;
ok:
ptr = (rec->dma_size - (rem + 1)) >> rec->shift;
#else #else
reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1;
ptr = snd_cmipci_read(cm, reg) - rec->offset; ptr = snd_cmipci_read(cm, reg) - rec->offset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment