summaryrefslogtreecommitdiff
path: root/drivers/tty/mxser.c
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2021-11-18 08:31:17 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-11-25 18:33:22 +0100
commit239ef19ef040698ccbabf25582b40c43554542fd (patch)
tree9089b85181bc5880aa410e95dff23ea16f3499de /drivers/tty/mxser.c
parentc7ec012f6c563a84fc5c3052d490292a129413b7 (diff)
mxser: extract TX empty check from mxser_wait_until_sent()
And move it to new mxser_tx_empty(), because: 1) it simplifies the code (esp. the locking), and 2) serial_core needs such a hook anyway, so have it ready. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20211118073125.12283-12-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/mxser.c')
-rw-r--r--drivers/tty/mxser.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 6ab8899ada9c..fb26670b5a0b 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -1402,6 +1402,18 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
}
}
+static bool mxser_tx_empty(struct mxser_port *info)
+{
+ unsigned long flags;
+ u8 lsr;
+
+ spin_lock_irqsave(&info->slock, flags);
+ lsr = inb(info->ioaddr + UART_LSR);
+ spin_unlock_irqrestore(&info->slock, flags);
+
+ return !(lsr & UART_LSR_TEMT);
+}
+
/*
* mxser_wait_until_sent() --- wait until the transmitter is empty
*/
@@ -1409,8 +1421,6 @@ 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 flags;
- int lsr;
if (info->type == PORT_UNKNOWN)
return;
@@ -1445,17 +1455,13 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
if (!timeout || timeout > 2 * info->timeout)
timeout = 2 * info->timeout;
- spin_lock_irqsave(&info->slock, flags);
- while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
- spin_unlock_irqrestore(&info->slock, flags);
+ while (mxser_tx_empty(info)) {
schedule_timeout_interruptible(char_time);
- spin_lock_irqsave(&info->slock, flags);
if (signal_pending(current))
break;
if (timeout && time_after(jiffies, orig_jiffies + timeout))
break;
}
- spin_unlock_irqrestore(&info->slock, flags);
set_current_state(TASK_RUNNING);
}