tty: serial: msm: Don't read off end of tx fifo

Message ID 1464914908-19059-1-git-send-email-bjorn.andersson@linaro.org
State Accepted
Commit 30acf549ca1e81859a67590ab9ecfce3d1050a0b
Headers show

Commit Message

Bjorn Andersson June 3, 2016, 12:48 a.m.
For dm uarts in pio mode tx data is transferred to the fifo register 4
bytes at a time, but care is not taken when these 4 bytes spans the end
of the xmit buffer so the loop might read up to 3 bytes past the buffer
and then skip the actual data at the beginning of the buffer.

Fix this by, analogous to the DMA case, make sure the chunk doesn't
wrap the xmit buffer.

Fixes: 3a878c430fd6 ("tty: serial: msm: Add TX DMA support")
Cc: Andy Gross <andy.gross@linaro.org>
Cc: Ivan Ivanov <iivanov.xz@gmail.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: stable@vger.kernel.org
Reported-by: Frank Rowand <frowand.list@gmail.com>
Reported-by: Nicolas Dechesne <nicolas.dechesne@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

---
 drivers/tty/serial/msm_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Andy Gross June 5, 2016, 6:44 p.m. | #1
On Thu, Jun 02, 2016 at 05:48:28PM -0700, Bjorn Andersson wrote:
> For dm uarts in pio mode tx data is transferred to the fifo register 4

> bytes at a time, but care is not taken when these 4 bytes spans the end

> of the xmit buffer so the loop might read up to 3 bytes past the buffer

> and then skip the actual data at the beginning of the buffer.

> 

> Fix this by, analogous to the DMA case, make sure the chunk doesn't

> wrap the xmit buffer.

> 

> Fixes: 3a878c430fd6 ("tty: serial: msm: Add TX DMA support")

> Cc: Andy Gross <andy.gross@linaro.org>

> Cc: Ivan Ivanov <iivanov.xz@gmail.com>

> Cc: Stephen Boyd <sboyd@codeaurora.org>

> Cc: stable@vger.kernel.org

> Reported-by: Frank Rowand <frowand.list@gmail.com>

> Reported-by: Nicolas Dechesne <nicolas.dechesne@linaro.org>

> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>


Acked-by: Andy Gross <andy.gross@linaro.org>

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index b7d80bd57db9..7d62610d9de5 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -726,7 +726,7 @@  static void msm_handle_tx(struct uart_port *port)
 		return;
 	}
 
-	pio_count = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE);
+	pio_count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
 	dma_count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
 
 	dma_min = 1;	/* Always DMA */