Skip to content

Commit c37bc68

Browse files
jhovoldgregkh
authored andcommitted
TTY: fix tty_wait_until_sent maximum timeout
Currently tty_wait_until_sent may take up to twice as long as the requested timeout while waiting for driver and hardware buffers to drain. Fix this by taking the remaining number of jiffies after waiting for driver buffers to drain into account so that the timeout actually becomes a maximum timeout as it is documented to be. Note that this specifically implies tighter timings when closing a port as a consequence of actually honouring the port closing-wait setting for drivers relying on tty_wait_until_sent_from_close (e.g. via tty_port_close_start). Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 79fbf4a commit c37bc68

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/tty/tty_ioctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
218218
if (!timeout)
219219
timeout = MAX_SCHEDULE_TIMEOUT;
220220

221-
if (wait_event_interruptible_timeout(tty->write_wait,
222-
!tty_chars_in_buffer(tty), timeout) < 0) {
221+
timeout = wait_event_interruptible_timeout(tty->write_wait,
222+
!tty_chars_in_buffer(tty), timeout);
223+
if (timeout <= 0)
223224
return;
224-
}
225225

226226
if (timeout == MAX_SCHEDULE_TIMEOUT)
227227
timeout = 0;

0 commit comments

Comments
 (0)