[PATCH v2 4/4] serial: max310x: end the RTS envelope when a flush leaves nothing to send

From: Tapio Reijonen

Date: Tue Nov 17 2026 - 01:14:30 EST


With software-timed RTS, max310x_handle_tx() ends the envelope only at
its entry check, when it finds the transmit fifo empty. If
uart_flush_buffer() empties the fifo after that check, while the
function reads TXFIFOLVL, the loop ends without writing to the chip and
the function returns. Nothing was written, so no TX-empty interrupt
follows. tx_state stays at MAX310X_TX_SEND and RTS stays asserted until
the next write or until the port is closed, and an RS-485 transceiver
blocks the bus for that time.

A tcflush(TCOFLUSH) timed to the end of the delay before send
reproduces it: 68 of 975 flushes left the port in the send state, seen
by a following byte that left without the delay.

Call max310x_delayed_stop_tx() when the loop has pushed nothing. It
returns when data is still queued or the chip FIFO still drains, and
arms the after-send hold otherwise. With the change, 9509 such flushes
left no port in the send state.

Fixes: 33632215e1bb ("serial: max310x: drive RTS in software when hardware delays are too short")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/patchset/20261116-max310x-tx-fixes-v1-0-61c01f180911%40vaisala.com
Signed-off-by: Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>
---
drivers/tty/serial/max310x.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index d92bf241558862cd83073c1d12ec9f0aaf88f090..4d8b7d79f2c9450a1e8c6d382710cbe526196ae1 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -923,6 +923,7 @@ static void max310x_handle_tx(struct uart_port *port)
{
struct max310x_one *one = to_max310x_port(port);
struct tty_port *tport = &port->state->port;
+ bool pushed = false;

if (unlikely(port->x_char)) {
max310x_port_write(port, MAX310X_THR_REG, port->x_char);
@@ -976,6 +977,7 @@ static void max310x_handle_tx(struct uart_port *port)
break;

max310x_batch_write(port, one->tx_buf, to_send);
+ pushed = true;

/*
* uart_flush_buffer() reset the fifo during the transfer:
@@ -989,6 +991,14 @@ static void max310x_handle_tx(struct uart_port *port)
uart_port_unlock_irqrestore(port, flags);
}

+ /*
+ * Nothing went to the chip. If a flush has emptied the fifo since
+ * the check above, no TX-empty interrupt follows to end the
+ * envelope.
+ */
+ if (!pushed)
+ max310x_delayed_stop_tx(port);
+
if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
uart_write_wakeup(port);
}

--
2.47.3