Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1290507
| From | Peter Hurley <peter@hurleysoftware.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 4/8] serial: core: Take port mutex for send_xchar() tty method |
| Date | 2015-12-13 01:40 +0100 |
| Message-ID | <qF2RH-14v-15@gated-at.bofh.it> (permalink) |
| References | <qF2RH-14v-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Prepare for separate methods of preventing unsafe uart port access
when sending xchar; claim port mutex for the tty ops method (which
might sleep) and rcu for the throttle/unthrottle uses.
The implied limitation is that uart drivers which support
AUTOXOFF flow control cannot define a send_xchar() method that sleeps.
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
drivers/tty/serial/serial_core.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 4430518..806eba81 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -610,23 +610,31 @@ static void uart_flush_buffer(struct tty_struct *tty)
* This function is used to send a high-priority XON/XOFF character to
* the device
*/
-static void uart_send_xchar(struct tty_struct *tty, char ch)
+static void __uart_send_xchar(struct uart_port *uport, char ch)
{
- struct uart_state *state = tty->driver_data;
- struct uart_port *port = state->uart_port;
unsigned long flags;
- if (port->ops->send_xchar)
- port->ops->send_xchar(port, ch);
+ if (uport->ops->send_xchar)
+ uport->ops->send_xchar(uport, ch);
else {
- spin_lock_irqsave(&port->lock, flags);
- port->x_char = ch;
+ spin_lock_irqsave(&uport->lock, flags);
+ uport->x_char = ch;
if (ch)
- port->ops->start_tx(port);
- spin_unlock_irqrestore(&port->lock, flags);
+ uport->ops->start_tx(port);
+ spin_unlock_irqrestore(&uport->lock, flags);
}
}
+static void uart_send_xchar(struct tty_struct *tty, char ch)
+{
+ struct uart_state *state = tty->driver_data;
+ struct uart_port *uport = state->uart_port;
+
+ mutex_lock(&state->port.mutex);
+ __uart_send_xchar(uport, ch);
+ mutex_unlock(&state->port.mutex);
+}
+
static void uart_throttle(struct tty_struct *tty)
{
struct uart_state *state = tty->driver_data;
@@ -644,7 +652,7 @@ static void uart_throttle(struct tty_struct *tty)
}
if (mask & UPSTAT_AUTOXOFF)
- uart_send_xchar(tty, STOP_CHAR(tty));
+ __uart_send_xchar(port, STOP_CHAR(tty));
if (mask & UPSTAT_AUTORTS)
uart_clear_mctrl(port, TIOCM_RTS);
@@ -667,7 +675,7 @@ static void uart_unthrottle(struct tty_struct *tty)
}
if (mask & UPSTAT_AUTOXOFF)
- uart_send_xchar(tty, START_CHAR(tty));
+ __uart_send_xchar(port, START_CHAR(tty));
if (mask & UPSTAT_AUTORTS)
uart_set_mctrl(port, TIOCM_RTS);
--
2.6.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/8] Fix unsafe uart port access Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 4/8] serial: core: Take port mutex for send_xchar() tty method Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 3/8] serial: core: Use tty->index for port # in debug messages Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 1/8] serial: core: Fold __uart_put_char() into caller Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 5/8] serial: core: Expand port mutex section in uart_poll_init() Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 6/8] serial: core: Prevent unsafe uart port access, part 1 Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 2/8] serial: core: Fold do_uart_get_info() into caller Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100 [PATCH 7/8] serial: core: Prevent unsafe uart port access, part 2 Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 01:40 +0100
csiph-web