瀏覽代碼

serial: core: Document and assert lock requirements for irq helpers

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>
Peter Hurley 11 年之前
父節點
當前提交
4d90bb147e
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      drivers/tty/serial/serial_core.c

+ 8 - 0
drivers/tty/serial/serial_core.c

@@ -2743,6 +2743,8 @@ EXPORT_SYMBOL(uart_match_port);
  *	uart_handle_dcd_change - handle a change of carrier detect state
  *	uart_handle_dcd_change - handle a change of carrier detect state
  *	@uport: uart_port structure for the open port
  *	@uport: uart_port structure for the open port
  *	@status: new carrier detect status, nonzero if active
  *	@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)
 void uart_handle_dcd_change(struct uart_port *uport, unsigned int status)
 {
 {
@@ -2750,6 +2752,8 @@ void uart_handle_dcd_change(struct uart_port *uport, unsigned int status)
 	struct tty_struct *tty = port->tty;
 	struct tty_struct *tty = port->tty;
 	struct tty_ldisc *ld;
 	struct tty_ldisc *ld;
 
 
+	lockdep_assert_held_once(&uport->lock);
+
 	if (tty) {
 	if (tty) {
 		ld = tty_ldisc_ref(tty);
 		ld = tty_ldisc_ref(tty);
 		if (ld) {
 		if (ld) {
@@ -2774,12 +2778,16 @@ EXPORT_SYMBOL_GPL(uart_handle_dcd_change);
  *	uart_handle_cts_change - handle a change of clear-to-send state
  *	uart_handle_cts_change - handle a change of clear-to-send state
  *	@uport: uart_port structure for the open port
  *	@uport: uart_port structure for the open port
  *	@status: new clear to send status, nonzero if active
  *	@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)
 void uart_handle_cts_change(struct uart_port *uport, unsigned int status)
 {
 {
 	struct tty_port *port = &uport->state->port;
 	struct tty_port *port = &uport->state->port;
 	struct tty_struct *tty = port->tty;
 	struct tty_struct *tty = port->tty;
 
 
+	lockdep_assert_held_once(&uport->lock);
+
 	uport->icount.cts++;
 	uport->icount.cts++;
 
 
 	if (tty_port_cts_enabled(port)) {
 	if (tty_port_cts_enabled(port)) {