From: Peter Hurley <peter@hurleysoftware.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.cz>,
One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Peter Hurley <peter@hurleysoftware.com>
Subject: [PATCH 15/26] serial: core: Privatize modem status enable flags
Date: Tue, 2 Sep 2014 17:39:24 -0400 [thread overview]
Message-ID: <1409693975-1028-16-git-send-email-peter@hurleysoftware.com> (raw)
In-Reply-To: <1409693975-1028-1-git-send-email-peter@hurleysoftware.com>
The serial core uses the tty port flags, ASYNC_CTS_FLOW and
ASYNC_CD_CHECK, to track whether CTS and DCD changes should be
ignored or handled. However, the tty port flags are not safe for
atomic bit operations and no lock provides serialized updates.
Introduce the struct uart_port status field to track CTS and DCD
enable states, and serialize access with uart port lock. Substitute
uart_cts_enabled() helper for tty_port_cts_enabled().
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
drivers/tty/serial/mxs-auart.c | 2 +-
drivers/tty/serial/serial_core.c | 29 +++++++++++++++++------------
include/linux/serial_core.h | 12 ++++++++++++
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index b5c3292..10c2933 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -408,7 +408,7 @@ static void mxs_auart_set_mctrl(struct uart_port *u, unsigned mctrl)
ctrl &= ~(AUART_CTRL2_RTSEN | AUART_CTRL2_RTS);
if (mctrl & TIOCM_RTS) {
- if (tty_port_cts_enabled(&u->state->port))
+ if (uart_cts_enabled(u))
ctrl |= AUART_CTRL2_RTSEN;
else
ctrl |= AUART_CTRL2_RTS;
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index b50050d..288dc2e 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -58,6 +58,11 @@ static void uart_change_pm(struct uart_state *state,
static void uart_port_shutdown(struct tty_port *port);
+static int uart_dcd_enabled(struct uart_port *uport)
+{
+ return uport->status & UPSTAT_DCD_ENABLE;
+}
+
/*
* This routine is used by the interrupt handler to schedule processing in
* the software interrupt portion of the driver.
@@ -129,7 +134,6 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
int init_hw)
{
struct uart_port *uport = state->uart_port;
- struct tty_port *port = &state->port;
unsigned long page;
int retval = 0;
@@ -175,12 +179,12 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
}
- if (tty_port_cts_enabled(port)) {
- spin_lock_irq(&uport->lock);
+ spin_lock_irq(&uport->lock);
+ if (uart_cts_enabled(uport)) {
if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
tty->hw_stopped = 1;
- spin_unlock_irq(&uport->lock);
}
+ spin_unlock_irq(&uport->lock);
}
/*
@@ -431,7 +435,6 @@ EXPORT_SYMBOL(uart_get_divisor);
static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
struct ktermios *old_termios)
{
- struct tty_port *port = &state->port;
struct uart_port *uport = state->uart_port;
struct ktermios *termios;
@@ -446,17 +449,19 @@ static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
uport->ops->set_termios(uport, termios, old_termios);
/*
- * Set flags based on termios cflag
+ * Set modem status enables based on termios cflag
*/
+ spin_lock_irq(&uport->lock);
if (termios->c_cflag & CRTSCTS)
- set_bit(ASYNCB_CTS_FLOW, &port->flags);
+ uport->status |= UPSTAT_CTS_ENABLE;
else
- clear_bit(ASYNCB_CTS_FLOW, &port->flags);
+ uport->status &= ~UPSTAT_CTS_ENABLE;
if (termios->c_cflag & CLOCAL)
- clear_bit(ASYNCB_CHECK_CD, &port->flags);
+ uport->status &= ~UPSTAT_DCD_ENABLE;
else
- set_bit(ASYNCB_CHECK_CD, &port->flags);
+ uport->status |= UPSTAT_DCD_ENABLE;
+ spin_unlock_irq(&uport->lock);
}
static inline int __uart_put_char(struct uart_port *port,
@@ -2753,7 +2758,7 @@ void uart_handle_dcd_change(struct uart_port *uport, unsigned int status)
uport->icount.dcd++;
- if (port->flags & ASYNC_CHECK_CD) {
+ if (uart_dcd_enabled(uport)) {
if (status)
wake_up_interruptible(&port->open_wait);
else if (tty)
@@ -2778,7 +2783,7 @@ void uart_handle_cts_change(struct uart_port *uport, unsigned int status)
uport->icount.cts++;
- if (tty_port_cts_enabled(port)) {
+ if (uart_cts_enabled(uport)) {
if (tty->hw_stopped) {
if (status) {
tty->hw_stopped = 0;
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 4a43292..bc70048 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -112,6 +112,7 @@ struct uart_icount {
};
typedef unsigned int __bitwise__ upf_t;
+typedef unsigned int __bitwise__ upstat_t;
struct uart_port {
spinlock_t lock; /* port lock */
@@ -188,6 +189,12 @@ struct uart_port {
#define UPF_CHANGE_MASK ((__force upf_t) (0x17fff))
#define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY))
+ /* status must be updated while holding port lock */
+ upstat_t status;
+
+#define UPSTAT_CTS_ENABLE ((__force upstat_t) (1 << 0))
+#define UPSTAT_DCD_ENABLE ((__force upstat_t) (1 << 1))
+
unsigned int mctrl; /* current modem ctrl settings */
unsigned int timeout; /* character-based timeout */
unsigned int type; /* port type */
@@ -351,6 +358,11 @@ static inline int uart_tx_stopped(struct uart_port *port)
return 0;
}
+static inline bool uart_cts_enabled(struct uart_port *uport)
+{
+ return uport->status & UPSTAT_CTS_ENABLE;
+}
+
/*
* The following are helper functions for the low level drivers.
*/
--
2.1.0
next prev parent reply other threads:[~2014-09-02 21:39 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-02 21:39 [PATCH 00/26] tty/serial flow control fixes Peter Hurley
2014-09-02 21:39 ` [PATCH 01/26] Revert "serial: uart: add hw flow control support configuration" Peter Hurley
2014-09-02 21:50 ` Murali Karicheri
2014-09-02 21:58 ` Peter Hurley
2014-09-02 22:17 ` Murali Karicheri
2014-09-02 21:39 ` [PATCH 02/26] serial: Style fix Peter Hurley
2014-09-02 21:39 ` [PATCH 03/26] serial: imx: Fix x_char handling and tx flow control Peter Hurley
2014-09-02 21:39 ` [PATCH 04/26] serial: core: Fix x_char race Peter Hurley
2014-09-02 21:39 ` [PATCH 05/26] serial: core: Remove unsafe x_char optimization Peter Hurley
2014-09-02 21:39 ` [PATCH 06/26] serial: Fix send_xchar() handlers Peter Hurley
2014-09-02 21:39 ` [PATCH 07/26] serial: mpc52xx: Use default serial core x_char handler Peter Hurley
2014-09-02 21:39 ` [PATCH 08/26] serial: sunsab: Don't enable tx if tx stopped Peter Hurley
2014-09-02 21:39 ` [PATCH 09/26] serial: blackfin: Fix missing gpio.h Peter Hurley
2014-09-02 21:39 ` [PATCH 10/26] serial: core: Document lock requirement for UPF_* flags updates Peter Hurley
2014-09-02 21:39 ` [PATCH 11/26] serial: 8250: Document serial8250_modem_status() locking Peter Hurley
2014-09-02 21:39 ` [PATCH 12/26] serial: core: Unwrap tertiary assignment in uart_handle_dcd_change() Peter Hurley
2014-09-02 21:39 ` [PATCH 13/26] locking: Add non-fatal spin lock assert Peter Hurley
2014-09-03 9:27 ` Peter Zijlstra
2014-09-03 11:20 ` Peter Hurley
2014-09-03 14:40 ` Peter Zijlstra
2014-09-03 14:50 ` Peter Hurley
2014-09-03 15:07 ` Peter Zijlstra
2014-09-04 5:14 ` Ingo Molnar
2014-09-10 11:02 ` Peter Hurley
2014-09-10 13:08 ` Peter Zijlstra
2014-09-10 14:45 ` Peter Hurley
2014-09-10 18:34 ` Greg Kroah-Hartman
2014-09-02 21:39 ` [PATCH 14/26] serial: core: Document and assert lock requirements for irq helpers Peter Hurley
2014-09-02 21:39 ` Peter Hurley [this message]
2014-09-02 21:39 ` [PATCH 16/26] isdn: i4l: Remove ASYNC_CTS_FLOW Peter Hurley
2014-09-02 21:39 ` [PATCH 17/26] serial: core: Privatize tty->hw_stopped Peter Hurley
2014-09-09 0:29 ` Peter Hurley
2014-09-02 21:39 ` [PATCH 18/26] usb: serial: Remove unused tty->hw_stopped Peter Hurley
2014-09-02 21:39 ` [PATCH 19/26] serial: bfin-uart: Fix auto CTS Peter Hurley
2014-09-02 21:39 ` [PATCH 20/26] serial: core: Use spin_lock_irq() in uart_set_termios() Peter Hurley
2014-09-02 21:39 ` [PATCH 21/26] tty: Convert tty_struct bitfield to bools Peter Hurley
2014-09-03 10:58 ` One Thousand Gnomes
2014-09-03 12:14 ` Peter Hurley
2014-09-03 12:19 ` One Thousand Gnomes
2014-09-03 15:10 ` Peter Hurley
2014-09-03 17:56 ` Greg Kroah-Hartman
2014-09-04 16:08 ` Peter Hurley
2014-09-02 21:39 ` [PATCH 22/26] tty: Serialize tty flow control changes with flow_lock Peter Hurley
2014-09-02 21:39 ` [PATCH 23/26] tty: Move packet mode flow control notifications to pty driver Peter Hurley
2014-09-02 21:39 ` [PATCH 24/26] tty: Serialize tcflow() with other tty flow control changes Peter Hurley
2014-09-02 21:39 ` [PATCH 25/26] tty: Move and rename send_prio_char() as tty_send_xchar() Peter Hurley
2014-09-02 21:39 ` [PATCH 26/26] tty: Hold termios_rwsem for tcflow(TCIxxx) Peter Hurley
2014-09-08 23:24 ` [PATCH 00/26] tty/serial flow control fixes Greg Kroah-Hartman
2014-09-08 23:33 ` Peter Hurley
2014-09-08 23:43 ` Greg Kroah-Hartman
2014-09-08 23:46 ` Peter Hurley
2014-09-09 0:01 ` Greg Kroah-Hartman
2014-09-10 19:06 ` [PATCH v2 00/14] " Peter Hurley
2014-09-10 19:06 ` [PATCH v2 01/14] serial: core: Document and assert lock requirements for irq helpers Peter Hurley
2014-09-10 19:06 ` [PATCH v2 02/14] serial: core: Privatize modem status enable flags Peter Hurley
2014-09-10 19:06 ` [PATCH v2 03/14] isdn: i4l: Remove ASYNC_CTS_FLOW Peter Hurley
2014-09-10 19:06 ` [PATCH v2 04/14] serial: core: Privatize tty->hw_stopped Peter Hurley
2014-09-10 19:06 ` [PATCH v2 05/14] usb: serial: Remove unused tty->hw_stopped Peter Hurley
2014-09-23 15:33 ` Johan Hovold
2014-09-10 19:06 ` [PATCH v2 06/14] serial: bfin-uart: Fix auto CTS Peter Hurley
2014-09-10 19:06 ` [PATCH v2 07/14] serial: core: Use spin_lock_irq() in uart_set_termios() Peter Hurley
2014-09-10 19:06 ` [PATCH v2 08/14] tty: Convert tty_struct bitfield to ints Peter Hurley
2014-09-10 19:06 ` [PATCH v2 09/14] tty: Serialize tty flow control changes with flow_lock Peter Hurley
2014-09-10 19:06 ` [PATCH v2 10/14] tty: Move packet mode flow control notifications to pty driver Peter Hurley
2014-09-10 19:06 ` [PATCH v2 11/14] tty: Serialize tcflow() with other tty flow control changes Peter Hurley
2014-09-10 19:06 ` [PATCH v2 12/14] tty: Move and rename send_prio_char() as tty_send_xchar() Peter Hurley
2014-09-10 19:06 ` [PATCH v2 13/14] tty: Hold termios_rwsem for tcflow(TCIxxx) Peter Hurley
2014-09-10 19:06 ` [PATCH v2 14/14] tty: Workaround Alpha non-atomic byte storage in tty_struct Peter Hurley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409693975-1028-16-git-send-email-peter@hurleysoftware.com \
--to=peter@hurleysoftware.com \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).