提交 874e1f6f 编写于 作者: T Takashi Iwai

ALSA: vx: Fix possible transfer overflow

The pseudo DMA transfer codes in VX222 and VX-pocket driver have a
slight bug where they check the buffer boundary wrongly, and may
overflow.  Also, the zero sample count might be handled badly for the
playback (although it shouldn't happen in theory).  This patch
addresses these issues.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=141541Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 ab949d51
...@@ -1048,8 +1048,10 @@ static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream ...@@ -1048,8 +1048,10 @@ static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream
/* ok, let's accelerate! */ /* ok, let's accelerate! */
int align = pipe->align * 3; int align = pipe->align * 3;
space = (count / align) * align; space = (count / align) * align;
vx_pseudo_dma_read(chip, runtime, pipe, space); if (space > 0) {
count -= space; vx_pseudo_dma_read(chip, runtime, pipe, space);
count -= space;
}
} }
/* read the rest of bytes */ /* read the rest of bytes */
while (count > 0) { while (count > 0) {
......
...@@ -269,12 +269,12 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -269,12 +269,12 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
/* Transfer using pseudo-dma. /* Transfer using pseudo-dma.
*/ */
if (offset + count > pipe->buffer_bytes) { if (offset + count >= pipe->buffer_bytes) {
int length = pipe->buffer_bytes - offset; int length = pipe->buffer_bytes - offset;
count -= length; count -= length;
length >>= 2; /* in 32bit words */ length >>= 2; /* in 32bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (length-- > 0) { for (; length > 0; length--) {
outl(cpu_to_le32(*addr), port); outl(cpu_to_le32(*addr), port);
addr++; addr++;
} }
...@@ -284,7 +284,7 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -284,7 +284,7 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
pipe->hw_ptr += count; pipe->hw_ptr += count;
count >>= 2; /* in 32bit words */ count >>= 2; /* in 32bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (count-- > 0) { for (; count > 0; count--) {
outl(cpu_to_le32(*addr), port); outl(cpu_to_le32(*addr), port);
addr++; addr++;
} }
...@@ -307,12 +307,12 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -307,12 +307,12 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
vx2_setup_pseudo_dma(chip, 0); vx2_setup_pseudo_dma(chip, 0);
/* Transfer using pseudo-dma. /* Transfer using pseudo-dma.
*/ */
if (offset + count > pipe->buffer_bytes) { if (offset + count >= pipe->buffer_bytes) {
int length = pipe->buffer_bytes - offset; int length = pipe->buffer_bytes - offset;
count -= length; count -= length;
length >>= 2; /* in 32bit words */ length >>= 2; /* in 32bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (length-- > 0) for (; length > 0; length--)
*addr++ = le32_to_cpu(inl(port)); *addr++ = le32_to_cpu(inl(port));
addr = (u32 *)runtime->dma_area; addr = (u32 *)runtime->dma_area;
pipe->hw_ptr = 0; pipe->hw_ptr = 0;
...@@ -320,7 +320,7 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -320,7 +320,7 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
pipe->hw_ptr += count; pipe->hw_ptr += count;
count >>= 2; /* in 32bit words */ count >>= 2; /* in 32bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (count-- > 0) for (; count > 0; count--)
*addr++ = le32_to_cpu(inl(port)); *addr++ = le32_to_cpu(inl(port));
vx2_release_pseudo_dma(chip); vx2_release_pseudo_dma(chip);
......
...@@ -369,12 +369,12 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -369,12 +369,12 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
unsigned short *addr = (unsigned short *)(runtime->dma_area + offset); unsigned short *addr = (unsigned short *)(runtime->dma_area + offset);
vx_setup_pseudo_dma(chip, 1); vx_setup_pseudo_dma(chip, 1);
if (offset + count > pipe->buffer_bytes) { if (offset + count >= pipe->buffer_bytes) {
int length = pipe->buffer_bytes - offset; int length = pipe->buffer_bytes - offset;
count -= length; count -= length;
length >>= 1; /* in 16bit words */ length >>= 1; /* in 16bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (length-- > 0) { for (; length > 0; length--) {
outw(cpu_to_le16(*addr), port); outw(cpu_to_le16(*addr), port);
addr++; addr++;
} }
...@@ -384,7 +384,7 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -384,7 +384,7 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
pipe->hw_ptr += count; pipe->hw_ptr += count;
count >>= 1; /* in 16bit words */ count >>= 1; /* in 16bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (count-- > 0) { for (; count > 0; count--) {
outw(cpu_to_le16(*addr), port); outw(cpu_to_le16(*addr), port);
addr++; addr++;
} }
...@@ -411,12 +411,12 @@ static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -411,12 +411,12 @@ static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
if (snd_BUG_ON(count % 2)) if (snd_BUG_ON(count % 2))
return; return;
vx_setup_pseudo_dma(chip, 0); vx_setup_pseudo_dma(chip, 0);
if (offset + count > pipe->buffer_bytes) { if (offset + count >= pipe->buffer_bytes) {
int length = pipe->buffer_bytes - offset; int length = pipe->buffer_bytes - offset;
count -= length; count -= length;
length >>= 1; /* in 16bit words */ length >>= 1; /* in 16bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (length-- > 0) for (; length > 0; length--)
*addr++ = le16_to_cpu(inw(port)); *addr++ = le16_to_cpu(inw(port));
addr = (unsigned short *)runtime->dma_area; addr = (unsigned short *)runtime->dma_area;
pipe->hw_ptr = 0; pipe->hw_ptr = 0;
...@@ -424,7 +424,7 @@ static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, ...@@ -424,7 +424,7 @@ static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
pipe->hw_ptr += count; pipe->hw_ptr += count;
count >>= 1; /* in 16bit words */ count >>= 1; /* in 16bit words */
/* Transfer using pseudo-dma. */ /* Transfer using pseudo-dma. */
while (count-- > 1) for (; count > 1; count--)
*addr++ = le16_to_cpu(inw(port)); *addr++ = le16_to_cpu(inw(port));
/* Disable DMA */ /* Disable DMA */
pchip->regDIALOG &= ~VXP_DLG_DMAREAD_SEL_MASK; pchip->regDIALOG &= ~VXP_DLG_DMAREAD_SEL_MASK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册