]> git.baikalelectronics.ru Git - kernel.git/commit
serial: core: fix tcdrain() with CTS enabled
authorTomasz Moń <tomasz.mon@camlingroup.com>
Mon, 28 Feb 2022 05:49:11 +0000 (06:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Apr 2022 14:25:06 +0000 (16:25 +0200)
commit61e650410f2c82aed59ba94d87326f425cb6683e
tree1f981cd957b2f84f26c138637687d1ea41b83e4c
parentfa07399fc3d1cf6f9eadade8ba345dd170a67a79
serial: core: fix tcdrain() with CTS enabled

Do not set timeout to twice the approximate amount of time to send the
entire FIFO if CTS is enabled. If the caller requested no timeout, e.g.
when userspace program called tcdrain(), then wait without any timeout.

Premature return from tcdrain() was observed on imx based system which
has 32 character long transmitter FIFO with hardware CTS handling.

Simple userspace application that reproduces problem has to:
  * Open tty device, enable hardware flow control (CRTSCTS)
  * Write data, e.g. 26 bytes
  * Call tcdrain() to wait for the transmitter
  * Close tty device

The other side of serial connection has to:
  * Receive some data, e.g. 10 bytes
  * Set RTS output (CTS input from sender perspective) inactive for
    at least twice the port timeout
  * Try to receive remaining data

Without this patch, userspace application will finish without any error
while the other side of connection will never receive remaining data.

Signed-off-by: Tomasz Moń <tomasz.mon@camlingroup.com>
Link: https://lore.kernel.org/r/20220228054911.1420221-1-tomasz.mon@camlingroup.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/serial_core.c