On Mon, Nov 02, 2026 at 04:14:32PM -0700, James Hilliard wrote: > uart_flush_buffer() resets the transmit FIFO before calling the driver's > flush callback. An asynchronous DMA transfer can still access that storage > after the callback returns, while a new write can immediately reuse it. > > Add uart_xmit_block() and uart_xmit_unblock() so a driver can reserve the > flushed storage until its transfer and completion callbacks have retired. > Serialize the reservation with FIFO producers using the port lock. > > While the storage is reserved, write_room() reports no space and write() > and put_char() accept no data. Defer write-ready notifications until the > reservation is released, preserving one-shot TTY wakeups. Keep the flush's > write-ready notification under the port lock so it cannot race another > reservation. > > Wake tty->write_wait after flushing even when writes remain blocked. > tty_wait_until_sent() waits for the logical FIFO to empty, independently > of whether its storage can be reused. Notify these drain waiters without > invoking the line discipline's write_wakeup() callback, so a reservation > does not prevent a completed logical flush from waking a drain waiter or > consume a one-shot write-ready notification prematurely. > > Suppress ordinary TX starts while the FIFO storage is blocked. Preserve > high-priority flow-control characters, which use separate storage. > Releasing the reservation wakes writers through the existing TTY wakeup > path. This preserves immediate logical flushing while applying write > backpressure until the storage is reusable. > > Track port readiness separately from DMA ownership. Retirement releases the > reservation even during startup or shutdown, while writes and wakeups stay > gated until successful startup or resume. Reopening or restarting a port > wakes deferred writers with either a new or retained FIFO. Restart queued > output when reusing a FIFO after suspension. Keep its write-ready > notification pending until the retained output drains below the normal > wakeup threshold. > > Publish resume readiness under the same port lock as the TX restart, > without clearing any reservation. A concurrent flush can then reserve a > new transfer without resume releasing its storage prematurely. > > Assert the port-lock requirement at uart_write_wakeup(), alongside the > reservation helpers, so callers cannot inspect readiness or release a > one-shot notification concurrently with a reservation change.
... > + /* Retained output must drain before consuming a write-ready > notification. */ > + if (kfifo_len(&state->port.xmit_fifo) < WAKEUP_CHARS) > + uart_write_wakeup(port); I believe I have seen this already a few times. Perhaps a helper with documented idea behind it? -- With Best Regards, Andy Shevchenko
