[PATCH v2 0/4] serial: max310x: transmit path fixes

From: Tapio Reijonen

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


Four fixes for the MAX310x transmit path, found while stress testing
the software-timed RS-485 delays that are new in v7.4.

Patch 1 fixes a race between the transmit work and a flush. The work
advances the fifo after the SPI transfer without the port lock; since
the kfifo conversion in v6.10 a uart_flush_buffer() during the transfer
leaves the read index ahead of the write index, and the fifo reports
about 4 billion bytes queued. tcdrain() then never returns and stale
data is sent until the port is closed. It carries Cc stable, but does
not apply to v7.3 and older as it is: the context is the v7.4 driver.
6.12.y and later need an adapted version.

Patches 2 and 3 fix commit 33632215e1bb ("serial: max310x: drive RTS in
software when hardware delays are too short"), which is in v7.4-rc1.
With patch 2, data written while an envelope is closing no longer
leaves after RTS has been released. With patch 3, a late TX-empty
interrupt of the previous envelope no longer pushes the head of the
next write out before RTS is up. Both lose data silently on an RS-485
bus, so it would be good to have them in v7.4.

Patch 4 is new in v2 and fixes the same commit. A flush that empties
the fifo while the transmit work reads the chip FIFO level left the
envelope open, with RTS asserted until the next write. The sashiko
review of v1 pointed at it.

Tested on a MAX14830 behind a single-core i.MX6SX, on v7.4-rc3:

- flush during transmission on all four ports, five minutes: the fifo
length stays within 4096;
- 20 unbinds with a tcdrain() blocked on a slow port: no task is left
sleeping;
- RS-485 loopback with data verification on three ports, 57600 baud,
25-byte writes every 20 ms, 20 ms before-send delay, ten minutes:
no byte lost or misframed. The numbers without patches 2 and 3 are
in their commit messages;
- baud rate changes at random moments under traffic, each one moving
the port between chip-timed and driver-timed RTS: 7672 changes in
ten minutes, no stall, every byte sent;
- TIOCSERGETLSR and tcdrain() polled after every write, 12500 writes:
the port is never reported idle with data unsent;
- xmit_fifo_size raised to 256 with TIOCSSERIAL: 570000 bytes per
port, all sent, nothing in the log;
- output stopped with TCOOFF, data queued, baud rate changed: nothing
is sent while stopped, everything after TCOON;
- TIOCSRS485 repeated every few milliseconds while a second block is
written at the end of the first, with and without CPU load, 50
minutes on v7.4-rc2 and v7.4-rc3: 30900 block pairs verified through
the loopback, none lost;
- tcflush(TCOFLUSH) timed to the end of the delay before send, 9509
flushes: a byte written afterwards always gets the delay. Without
patch 4, 68 of 975 flushes left RTS asserted.

The envelope timing was checked on a logic analyser with an earlier
version of patches 1 to 3, on v7.3-rc7.

Known and not changed here; all of it is in the driver without this
series:

- an x_char is written without regard to the RTS envelope;
- a reconfigure while stopped output has data queued asserts RTS for
about one character time;
- by the code, a TIOCSRS485 applied at the very end of an envelope can
arm the after-send hold while a new write is being pushed, and RTS
then drops under that write. Patch 2 closes this window for the
transmit work, not for the work item that applies the ioctl. The
TIOCSRS485 test above did not provoke it.

sashiko also describes a flush between the adoption of a queued block
and its restart when a reconfigure is applied. A TCFLSH cannot get
there: uart_ioctl() takes port->mutex first, which the reconfigure
holds. In a function trace of 1500 tries the flush never ran while
the reconfigure was being applied. Other callers of
uart_flush_buffer() are not covered by this argument.

Tool use: Claude Code (Anthropic) was used throughout. It drafted the
code and the commit messages, wrote the test scripts and the hardware
test plans, and analysed the function traces. An LLM review of an
earlier version found two faults, in patches 1 and 3; both were
reproduced on hardware and are fixed in what is posted here. I decided
the approach of each fix, reviewed every change against the code, and
ran the hardware tests. The code and the messages are mine to defend.

Signed-off-by: Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>
---
Changes in v2:
- New patch 4: end the RTS envelope when a flush leaves nothing to
send (found by the sashiko review of v1, reproduced on hardware)
- Patches 1 to 3 unchanged
- Link to v1: https://lore.kernel.org/r/20261116-max310x-tx-fixes-v1-0-61c01f180911@xxxxxxxxxxx

---
Tapio Reijonen (4):
serial: max310x: do not advance the TX fifo past a flush
serial: max310x: re-check the TX queue before the after-send hold
serial: max310x: hold TX data until the software RTS send phase
serial: max310x: end the RTS envelope when a flush leaves nothing to send

drivers/tty/serial/max310x.c | 132 ++++++++++++++++++++++++++++++++++---------
1 file changed, 106 insertions(+), 26 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261112-max310x-tx-fixes-eba3803195ae

Best regards,
--
Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>