more tty closing fixes
cover more tty closing fixes
Hi Greg,
These 3 patches are stragglers from the old tty closing series. I'm still working on eliminating ASYNC_CLOSING and the improvements to opening in O_NONBLOCK mode.
Regards,
Peter Hurley (3):
tty: Move tty hung up check from port->lock critical section
tty: Convert tty->closing to int
tty: Flush tty buffers after hardware shutdown
drivers/tty/tty_port.c | 7 +++---- include/linux/tty.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.3
PATCH 1/3 tty: Move tty hung up check from port->lock critical section
The port->lock does not protect the filp->f_op field; move the tty_hung_up_p() test outside the port->lock critical section in tty_port_close_start().
--- drivers/tty/tty_port.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/tty/tty_port.c +2 -4
@@ -473,12 +473,10 @@ int tty_port_close_start(struct tty_port *port, {unsigned long flags; -spin_lock_irqsave (&port->lock, flags); -if (tty_hung_up_p (filp)) { -spin_unlock_irqrestore (&port->lock, flags); +if (tty_hung_up_p (filp))return 0 ; - } +spin_lock_irqsave (&port->lock, flags);if (tty->count ==1 && port->count !=1 ) { printk(KERN_WARNING "tty_port_close_start: tty->count = 1 port count = %d.\n",
Signature · 1 line
2.1.3
PATCH 2/3 tty: Convert tty->closing to int
In reply to Peter Hurleytty->closing is a bitfield member; prevent corruption from non-atomic update by assigning a unique memory location.
--- include/linux/tty.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/tty.h +1 -1
@@ -284,7 +284,7 @@ struct tty_struct {#define N_TTY_BUF_SIZE 4096 - unsigned char closing:1; +int closing;unsigned char *write_buf;int write_cnt;/* If the tty has a pending do_SAK, queue it here - akpm */
Signature · 1 line
2.1.3
PATCH 3/3 tty: Flush tty buffers after hardware shutdown
In reply to Peter HurleyThe line discipline buffer and the tty buffers must be flushed again after hardware shutdown; otherwise, a brief window exists between the ldisc flush in tty_port_close_start() and the subsequent tty_port_shutdown(), during which more data could be received into the tty buffers. A racing open might then be able to receive data from the previous session.
--- drivers/tty/tty_port.c | 1 + 1 file changed, 1 insertion(+)
drivers/tty/tty_port.c +1 -0
@@ -520,6 +520,7 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) {unsigned long flags; +tty_ldisc_flush (tty); tty->closing =0 ;spin_lock_irqsave (&port->lock, flags);
Signature · 1 line
2.1.3