nuttx/drivers/serial
Lingao Meng 3a0fb4b9bf drivers/serial: bound uart_tcdrain xmit-buffer wait by caller timeout
uart_tcdrain() takes a caller-supplied timeout (e.g. 10s from the
TCDRN ioctl path), but the timeout was only applied to the final
TX-FIFO polling loop.  The earlier xmit-buffer drain loop called
nxsem_wait(&dev->xmitsem) with no timeout, so any condition that
prevents the lower half from posting xmitsem (e.g. a stuck DMA
completion path, a wedged hardware-flow-control stall) would block
tcdrain() indefinitely, regardless of the timeout the caller asked
for.  The pre-existing comment ("NOTE: There is no timeout on the
following loop. ... the caller should call tcflush() first") openly
acknowledged this hang.

Move the start timestamp before both phases and replace the bare
nxsem_wait() with nxsem_tickwait() using the remaining time, so the
total time spent in tcdrain() honors the caller's timeout regardless
of which phase stalls.  When the remaining time is already exhausted,
short-circuit to -ETIMEDOUT without calling into the scheduler.  The
existing exit path (drop critical section, skip the FIFO polling
loop, unlock the xmit mutex, leave the cancellation point) handles
the new -ETIMEDOUT propagation correctly without further changes.

Also fold the "Set up for the timeout" comment into the kludge
REVISIT comment, since the timestamp is no longer set up at that
point.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-06-02 19:50:55 +08:00
..
CMakeLists.txt serial/xlnx_ps: add common Xilinx UART Peripheral System (XUARTPS) support 2026-02-27 08:14:03 -03:00
Kconfig serial/xlnx_ps: add help chapter for XUARTPS 2026-02-27 08:14:03 -03:00
Kconfig-16550 drivers/serial/16550: add polling mode support for serial drivers 2026-02-27 08:14:03 -03:00
Kconfig-cmsdk drivers/serial:support arm cmsdk drivers 2024-04-26 18:42:35 -03:00
Kconfig-lpuart
Kconfig-pci drivers/serial: simplify 16550_PCI_UARTx_CLOCK config 2025-01-03 08:52:43 +08:00
Kconfig-pl011 drivers/serial/uart_pl011.c : add the interface about clock and reset control for reducing power consumption. 2024-06-03 21:18:44 +08:00
Kconfig-sci
Kconfig-uart
Kconfig-usart drivers/serial/serial: prevent race conditions on 8-bit architectures 2025-06-19 10:01:24 -03:00
Kconfig-xlnxps drivers/serial/xlnxps: add polling mode support for serial drivers 2026-02-27 08:14:03 -03:00
Make.defs serial/xlnx_ps: add common Xilinx UART Peripheral System (XUARTPS) support 2026-02-27 08:14:03 -03:00
ptmx.c drivers/serial: fix the issue of the refs count for filep being zeroed out by utilizing dup2 2025-06-26 09:31:14 -03:00
pty.c drivers/serial/pty: fix memory leak when pty_destroy 2026-01-06 15:08:23 -03:00
pty.h drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
serial.c drivers/serial: bound uart_tcdrain xmit-buffer wait by caller timeout 2026-06-02 19:50:55 +08:00
serial_cmsdk.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
serial_dma.c style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
serial_gdbstub.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
serial_io.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
uart_16550.c drivers/serial/16550: fix AM62x console bring-up 2026-05-28 22:21:38 +08:00
uart_bth4.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
uart_bth5.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
uart_hostfs.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
uart_pci_16550.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
uart_pl011.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
uart_ram.c serial/uart_ram: update lower buffer offset if previous send completes 2025-01-23 18:14:48 +08:00
uart_rpmsg.c serial/uart_rpmsg: Remove redundant CONFIG_RPMSG_UART_CONSOLE macro check 2026-03-03 11:55:34 -05:00
uart_rpmsg_raw.c serial/uart_rpmsg: Remove redundant CONFIG_RPMSG_UART_CONSOLE macro check 2026-03-03 11:55:34 -05:00
uart_xlnx_ps.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00