diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2016-04-10 04:56:34 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-04-30 19:26:55 +0300 |
commit | 9ed19428a51d53477e2b79be3303fa08f8575749 (patch) | |
tree | 2260eee9aba3a539713c3b04d4081a4bf1acce02 /include/linux/serial_core.h | |
parent | 4047b37122d1be8dd8e8c504f6f596930b660188 (diff) | |
download | linux-9ed19428a51d53477e2b79be3303fa08f8575749.tar.xz |
serial: core: Prevent unsafe uart port access, part 2
For serial core operations not already excluded by holding port->mutex,
use reference counting to protect deferencing the state->uart_port.
Introduce helper functions, uart_port_ref() and uart_port_deref(), to
wrap uart_port access, and helper macros, uart_port_lock() and
uart_port_unlock(), to wrap combination uart_port access with uart
port lock sections.
Port removal in uart_remove_one_port() waits for reference count to
drop to zero before detaching the uart port from struct uart_state.
For functions only reading the tx circular buffer indexes (where the
uart port lock is claimed to prevent concurrent users), a NULL uart
port is simply ignored and the operation completes normally.
For functions change the tx circular buffer indexes (where the uart
port lock is claimed to prevent concurrent users), the operation is
aborted if the uart port is NULL (ie., has been detached).
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/serial_core.h')
-rw-r--r-- | include/linux/serial_core.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index cbfcf38e220d..fd4ad4dce11a 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -281,6 +281,8 @@ struct uart_state { enum uart_pm_state pm_state; struct circ_buf xmit; + atomic_t refcount; + wait_queue_head_t remove_wait; struct uart_port *uart_port; }; |