aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2014-06-16 09:17:03 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-10 19:06:48 -0400
commitddc7b758a6765bd7f853b829104bb7a486a304ad (patch)
tree6266ec321bc78553ebd5fd960271a7bd88f883bd
parent9c9928bded9b4e35326d608b636ac65ff16f0404 (diff)
tty: Move tty->closing from port lock critical section
tty->closing informs the line discipline that the hardware will be shutting down imminently, and to disable further input other than soft flow control (but to still allow additional output). However, the tty lock is the necessary lock for preventing concurrent changes to tty->closing. As shown by the call-tree audit [1] of functions that modify tty->closing, the tty lock is already held for those functions. [1] Call-tree audit of functions that modify tty->closing * does not include call tree to tty_port_close(), tty_port_close_start(), or tty_port_close_end() which is already documented in 'tty: Document locking for tty_port_close{,start,end}' that shows callers to those 3 functions hold the tty lock tty_release() tty->ops->close() --+ | __tty_hangup() | tty->ops->close() --+ | mp_close():drivers/staging/sb105x/sb_pci_mp.c dngc_tty_close():drivers/staging/dgnc/dgnc_tty.c dgap_tty_close():drivers/staging/dgap/dgap_tty.c dgrp_tty_close():drivers/staging/dgrp/dgrp_tty.c rp_close():drivers/tty/rocket.c hvsi_close():drivers/tty/hvc/hvsi.c rs_close():drivers/tty/serial/68328serial.c rs_close():drivers/tty/serial/crisv10.c uart_close():drivers/tty/serial/serial_core.c isdn_tty_close():drivers/isdn/i4l/isdn_tty.c tty3215_close():drivers/s390/char/con3215.c tty_open() tty_ldisc_setup() ----+ | __tty_hangup() | tty_ldisc_hangup() ---+ | tty_set_ldisc() --------+ tty_ldisc_restore() --+ | +- tty_ldisc_open() ld->ops->open() --+ | +- n_tty_open() Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/serial/serial_core.c2
-rw-r--r--drivers/tty/tty_port.c6
2 files changed, 5 insertions, 3 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 127ac6c8fd40..3e08df52d68d 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1368,8 +1368,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1368 tty_ldisc_flush(tty); 1368 tty_ldisc_flush(tty);
1369 1369
1370 tty_port_tty_set(port, NULL); 1370 tty_port_tty_set(port, NULL);
1371 spin_lock_irqsave(&port->lock, flags);
1372 tty->closing = 0; 1371 tty->closing = 0;
1372 spin_lock_irqsave(&port->lock, flags);
1373 1373
1374 if (port->blocked_open) { 1374 if (port->blocked_open) {
1375 spin_unlock_irqrestore(&port->lock, flags); 1375 spin_unlock_irqrestore(&port->lock, flags);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 7309594e1c12..9209d6331b8e 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -497,9 +497,10 @@ int tty_port_close_start(struct tty_port *port,
497 return 0; 497 return 0;
498 } 498 }
499 set_bit(ASYNCB_CLOSING, &port->flags); 499 set_bit(ASYNCB_CLOSING, &port->flags);
500 tty->closing = 1;
501 spin_unlock_irqrestore(&port->lock, flags); 500 spin_unlock_irqrestore(&port->lock, flags);
502 501
502 tty->closing = 1;
503
503 if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 504 if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
504 /* Don't block on a stalled port, just pull the chain */ 505 /* Don't block on a stalled port, just pull the chain */
505 if (tty->flow_stopped) 506 if (tty->flow_stopped)
@@ -522,9 +523,10 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
522{ 523{
523 unsigned long flags; 524 unsigned long flags;
524 525
525 spin_lock_irqsave(&port->lock, flags);
526 tty->closing = 0; 526 tty->closing = 0;
527 527
528 spin_lock_irqsave(&port->lock, flags);
529
528 if (port->blocked_open) { 530 if (port->blocked_open) {
529 spin_unlock_irqrestore(&port->lock, flags); 531 spin_unlock_irqrestore(&port->lock, flags);
530 if (port->close_delay) { 532 if (port->close_delay) {