2014-11-05 17:40:21

by Peter Hurley

[permalink] [raw]
Subject: [PATCH -next 0/3] 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(-)

--
2.1.3


2014-11-05 17:40:26

by Peter Hurley

[permalink] [raw]
Subject: [PATCH -next 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().

Signed-off-by: Peter Hurley <[email protected]>
---
drivers/tty/tty_port.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 1b93357..3b641d1 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -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",
--
2.1.3

2014-11-05 17:40:49

by Peter Hurley

[permalink] [raw]
Subject: [PATCH -next 3/3] tty: Flush tty buffers after hardware shutdown

The 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.

Signed-off-by: Peter Hurley <[email protected]>
---
drivers/tty/tty_port.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 3b641d1..4d9abaa 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -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);
--
2.1.3

2014-11-05 17:41:39

by Peter Hurley

[permalink] [raw]
Subject: [PATCH -next 2/3] tty: Convert tty->closing to int

tty->closing is a bitfield member; prevent corruption from non-atomic
update by assigning a unique memory location.

Signed-off-by: Peter Hurley <[email protected]>
---
include/linux/tty.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index c52a689..7d66ae5 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -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 */
--
2.1.3