Skip to content

Commit

Permalink
mxser: clean up timeout handling in mxser_wait_until_sent()
Browse files Browse the repository at this point in the history
timeout cannot be zero at the point of use. So no need to check for
zero. Also precompute the expiration time (into expire) and use it. This
makes the code more clear.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-14-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jiri Slaby authored and Greg Kroah-Hartman committed Nov 25, 2021
1 parent fe74bc6 commit 49b798a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/tty/mxser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,15 +1420,14 @@ static bool mxser_tx_empty(struct mxser_port *info)
static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
{
struct mxser_port *info = tty->driver_data;
unsigned long orig_jiffies, char_time;
unsigned long expire, char_time;

if (info->type == PORT_UNKNOWN)
return;

if (info->xmit_fifo_size == 0)
return; /* Just in case.... */

orig_jiffies = jiffies;
/*
* Set the check interval to be 1/5 of the estimated time to
* send a single character, and make it at least 1. The check
Expand Down Expand Up @@ -1458,11 +1457,13 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
if (!timeout || timeout > 2 * info->timeout)
timeout = 2 * info->timeout;

expire = jiffies + timeout;

while (mxser_tx_empty(info)) {
msleep_interruptible(char_time);
if (signal_pending(current))
break;
if (timeout && time_after(jiffies, orig_jiffies + timeout))
if (time_after(jiffies, expire))
break;
}
}
Expand Down

0 comments on commit 49b798a

Please sign in to comment.