Skip to contentSkip to conversation

tty: serial: fsl_lpuart: count tty buffer overruns

PATCH In review Sherry Sun 2 participants 2 messages Jan 11, 2022 – Jan 13, 2022 TTY layer and serial drivers

lore
Share & tools
lore

Sherry Sun

author
#0 lore raw

PATCH v3 1/1 tty: serial: fsl_lpuart: count tty buffer overruns

Added support for counting the tty buffer overruns in fsl_lpuart driver like other uart drivers.

---
changes in V3

1. Remove the initialization for copied as it is not necessary.

---
 drivers/tty/serial/fsl_lpuart.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/tty/serial/fsl_lpuart.c +13 -7
index ce3e26144689..7d90c5a530ee 100644
@@ -931,7 +931,8 @@ static void lpuart_rxint(struct lpuart_port *sport)
 			sport->port.sysrq = 0;
 		}
 
-		tty_insert_flip_char(port, rx, flg);
+		if (tty_insert_flip_char(port, rx, flg) == 0)
+			sport->port.icount.buf_overrun++;
 	}
 
 out:
@@ -1024,7 +1025,8 @@ static void lpuart32_rxint(struct lpuart_port *sport)
 				flg = TTY_OVERRUN;
 		}
 
-		tty_insert_flip_char(port, rx, flg);
+		if (tty_insert_flip_char(port, rx, flg) == 0)
+			sport->port.icount.buf_overrun++;
 	}
 
 out:
@@ -1116,7 +1118,7 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
 	struct dma_chan *chan = sport->dma_rx_chan;
 	struct circ_buf *ring = &sport->rx_ring;
 	unsigned long flags;
-	int count = 0;
+	int count = 0, copied;
 
 	if (lpuart_is_32(sport)) {
 		unsigned long sr = lpuart32_read(&sport->port, UARTSTAT);
@@ -1218,20 +1220,24 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
 	if (ring->head < ring->tail) {
 		count = sport->rx_sgl.length - ring->tail;
 
-		tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		copied = tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		if (copied != count)
+			sport->port.icount.buf_overrun++;
 		ring->tail = 0;
-		sport->port.icount.rx += count;
+		sport->port.icount.rx += copied;
 	}
 
 	/* Finally we read data from tail to head */
 	if (ring->tail < ring->head) {
 		count = ring->head - ring->tail;
-		tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		copied = tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		if (copied != count)
+			sport->port.icount.buf_overrun++;
 		/* Wrap ring->head if needed */
 		if (ring->head >= sport->rx_sgl.length)
 			ring->head = 0;
 		ring->tail = ring->head;
-		sport->port.icount.rx += count;
+		sport->port.icount.rx += copied;
 	}
 
 exit:
Signature · 1 line
2.17.1
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Sherry Sun

Added support for counting the tty buffer overruns in fsl_lpuart driver like other uart drivers.

Quoted 70 lines

---
changes in V3

1. Remove the initialization for copied as it is not necessary.

---
  drivers/tty/serial/fsl_lpuart.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
drivers/tty/serial/fsl_lpuart.c +13 -7
index ce3e26144689..7d90c5a530ee 100644
@@ -931,7 +931,8 @@ static void lpuart_rxint(struct lpuart_port *sport)
  			sport->port.sysrq = 0;
  		}
 
-		tty_insert_flip_char(port, rx, flg);
+		if (tty_insert_flip_char(port, rx, flg) == 0)
+			sport->port.icount.buf_overrun++;
  	}
 
  out:
@@ -1024,7 +1025,8 @@ static void lpuart32_rxint(struct lpuart_port *sport)
  				flg = TTY_OVERRUN;
  		}
 
-		tty_insert_flip_char(port, rx, flg);
+		if (tty_insert_flip_char(port, rx, flg) == 0)
+			sport->port.icount.buf_overrun++;
  	}
 
  out:
@@ -1116,7 +1118,7 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
  	struct dma_chan *chan = sport->dma_rx_chan;
  	struct circ_buf *ring = &sport->rx_ring;
  	unsigned long flags;
-	int count = 0;
+	int count = 0, copied;
 
  	if (lpuart_is_32(sport)) {
  		unsigned long sr = lpuart32_read(&sport->port, UARTSTAT);
@@ -1218,20 +1220,24 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
  	if (ring->head < ring->tail) {
  		count = sport->rx_sgl.length - ring->tail;
 
-		tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		copied = tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		if (copied != count)
+			sport->port.icount.buf_overrun++;
  		ring->tail = 0;
-		sport->port.icount.rx += count;
+		sport->port.icount.rx += copied;
  	}
 
  	/* Finally we read data from tail to head */
  	if (ring->tail < ring->head) {
  		count = ring->head - ring->tail;
-		tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		copied = tty_insert_flip_string(port, ring->buf + ring->tail, count);
+		if (copied != count)
+			sport->port.icount.buf_overrun++;
  		/* Wrap ring->head if needed */
  		if (ring->head >= sport->rx_sgl.length)
  			ring->head = 0;
  		ring->tail = ring->head;
-		sport->port.icount.rx += count;
+		sport->port.icount.rx += copied;
  	}
 
  exit:
Signature · 2 lines
js
suse labs