Skip to content

Commit

Permalink
serial: core: Document and assert lock requirements for irq helpers
Browse files Browse the repository at this point in the history
The serial core provides two helper functions, uart_handle_dcd_change()
and uart_handle_cts_change(), for UART drivers to use at interrupt
time. The serial core expects the UART driver to hold the uart port lock
when calling these helpers to prevent state corruption.

If lockdep enabled, trigger a warning if the uart port lock is not held
when calling these helper functions.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
peterhurley authored and gregkh committed Sep 24, 2014
1 parent 9a37110 commit 4d90bb1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/tty/serial/serial_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2743,13 +2743,17 @@ EXPORT_SYMBOL(uart_match_port);
* uart_handle_dcd_change - handle a change of carrier detect state
* @uport: uart_port structure for the open port
* @status: new carrier detect status, nonzero if active
*
* Caller must hold uport->lock
*/
void uart_handle_dcd_change(struct uart_port *uport, unsigned int status)
{
struct tty_port *port = &uport->state->port;
struct tty_struct *tty = port->tty;
struct tty_ldisc *ld;

lockdep_assert_held_once(&uport->lock);

if (tty) {
ld = tty_ldisc_ref(tty);
if (ld) {
Expand All @@ -2774,12 +2778,16 @@ EXPORT_SYMBOL_GPL(uart_handle_dcd_change);
* uart_handle_cts_change - handle a change of clear-to-send state
* @uport: uart_port structure for the open port
* @status: new clear to send status, nonzero if active
*
* Caller must hold uport->lock
*/
void uart_handle_cts_change(struct uart_port *uport, unsigned int status)
{
struct tty_port *port = &uport->state->port;
struct tty_struct *tty = port->tty;

lockdep_assert_held_once(&uport->lock);

uport->icount.cts++;

if (tty_port_cts_enabled(port)) {
Expand Down

0 comments on commit 4d90bb1

Please sign in to comment.