Skip to contentSkip to conversation

tty: serial: fsl_lpuart: Fix Tx DMA edge case

PATCH In review Aaron Brice 3 participants 3 messages Oct 6, 2016 – Oct 10, 2016 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: serial: fsl_lpuart: Fix Tx DMA edge case

In the case where head == 0 on the circular buffer, there should be one DMA buffer, not two. The second zero-length buffer would break the lpuart driver, transfer would never complete.

---
 drivers/tty/serial/fsl_lpuart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +1 -2
index de9d510..76103f2 100644
@@ -328,7 +328,7 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
 
 	sport->dma_tx_bytes = uart_circ_chars_pending(xmit);
 
-	if (xmit->tail < xmit->head) {
+	if (xmit->tail < xmit->head || xmit->head == 0) {
 		sport->dma_tx_nents = 1;
 		sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes);
 	} else {
@@ -359,7 +359,6 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
 	sport->dma_tx_in_progress = true;
 	sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
 	dma_async_issue_pending(sport->dma_tx_chan);
-
 }
 
 static void lpuart_dma_tx_complete(void *arg)
Signature · 1 line
2.7.4
Acked-by Tested-by on v1 1/1
#1 lore raw
Quoted 3 lines · Aaron Brice

In the case where head == 0 on the circular buffer, there should be one DMA buffer, not two. The second zero-length buffer would break the lpuart driver, transfer would never complete.

That looks right, and seems to work fine here:

@Greg, would be good if this would still make it into 4.9.

--
Stefan

Quoted 27 lines
---
 drivers/tty/serial/fsl_lpuart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +1 -2
index de9d510..76103f2 100644
@@ -328,7 +328,7 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
 
 	sport->dma_tx_bytes = uart_circ_chars_pending(xmit);
 
-	if (xmit->tail < xmit->head) {
+	if (xmit->tail < xmit->head || xmit->head == 0) {
 		sport->dma_tx_nents = 1;
 		sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes);
 	} else {
@@ -359,7 +359,6 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
 	sport->dma_tx_in_progress = true;
 	sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
 	dma_async_issue_pending(sport->dma_tx_chan);
-
 }
 
 static void lpuart_dma_tx_complete(void *arg)
Tested-by on v1 1/1
#2 lore raw
In reply to Aaron Brice
Quoted 3 lines · Aaron Brice

In the case where head == 0 on the circular buffer, there should be one DMA buffer, not two. The second zero-length buffer would break the lpuart driver, transfer would never complete.

Quoted 27 lines
---
  drivers/tty/serial/fsl_lpuart.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +1 -2
index de9d510..76103f2 100644
@@ -328,7 +328,7 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
 
  	sport->dma_tx_bytes = uart_circ_chars_pending(xmit);
 
-	if (xmit->tail < xmit->head) {
+	if (xmit->tail < xmit->head || xmit->head == 0) {
  		sport->dma_tx_nents = 1;
  		sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes);
  	} else {
@@ -359,7 +359,6 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
  	sport->dma_tx_in_progress = true;
  	sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
  	dma_async_issue_pending(sport->dma_tx_chan);
-
  }
 
  static void lpuart_dma_tx_complete(void *arg)