Commit 957dacae authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

TTY: fix DTR not being dropped on hang up

Move HUPCL handling to port shutdown so that DTR is dropped also on hang
up (tty_port_close is a noop for hung-up ports).

Also do not try to drop DTR for uninitialised ports where it has never
been raised (e.g. after a failed open).

Note that this is also the current behaviour of serial-core.

Nine drivers currently call tty_port_close_start directly (rather than
through tty_port_close) and seven of them lower DTR as part of their
close (if the port has been initialised). Fixup the remaining two
drivers so that it continues to be lowered also on normal (non-HUP)
close. [ Note that most of those other seven drivers did not expect DTR
to have been dropped by tty_port_close_start in the first place. ]
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e584a02c
...@@ -1084,6 +1084,10 @@ static void mxser_close(struct tty_struct *tty, struct file *filp) ...@@ -1084,6 +1084,10 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
mutex_lock(&port->mutex); mutex_lock(&port->mutex);
mxser_close_port(port); mxser_close_port(port);
mxser_flush_buffer(tty); mxser_flush_buffer(tty);
if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
if (C_HUPCL(tty))
tty_port_lower_dtr_rts(port);
}
mxser_shutdown_port(port); mxser_shutdown_port(port);
clear_bit(ASYNCB_INITIALIZED, &port->flags); clear_bit(ASYNCB_INITIALIZED, &port->flags);
mutex_unlock(&port->mutex); mutex_unlock(&port->mutex);
......
...@@ -2964,6 +2964,10 @@ static void gsmtty_close(struct tty_struct *tty, struct file *filp) ...@@ -2964,6 +2964,10 @@ static void gsmtty_close(struct tty_struct *tty, struct file *filp)
if (tty_port_close_start(&dlci->port, tty, filp) == 0) if (tty_port_close_start(&dlci->port, tty, filp) == 0)
goto out; goto out;
gsm_dlci_begin_close(dlci); gsm_dlci_begin_close(dlci);
if (test_bit(ASYNCB_INITIALIZED, &dlci->port.flags)) {
if (C_HUPCL(tty))
tty_port_lower_dtr_rts(&dlci->port);
}
tty_port_close_end(&dlci->port, tty); tty_port_close_end(&dlci->port, tty);
tty_port_tty_set(&dlci->port, NULL); tty_port_tty_set(&dlci->port, NULL);
out: out:
......
...@@ -196,13 +196,20 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) ...@@ -196,13 +196,20 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
} }
EXPORT_SYMBOL(tty_port_tty_set); EXPORT_SYMBOL(tty_port_tty_set);
static void tty_port_shutdown(struct tty_port *port) static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
{ {
mutex_lock(&port->mutex); mutex_lock(&port->mutex);
if (port->console) if (port->console)
goto out; goto out;
if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) { if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) {
/*
* Drop DTR/RTS if HUPCL is set. This causes any attached
* modem to hang up the line.
*/
if (tty && C_HUPCL(tty))
tty_port_lower_dtr_rts(port);
if (port->ops->shutdown) if (port->ops->shutdown)
port->ops->shutdown(port); port->ops->shutdown(port);
} }
...@@ -220,18 +227,19 @@ static void tty_port_shutdown(struct tty_port *port) ...@@ -220,18 +227,19 @@ static void tty_port_shutdown(struct tty_port *port)
void tty_port_hangup(struct tty_port *port) void tty_port_hangup(struct tty_port *port)
{ {
struct tty_struct *tty;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
port->count = 0; port->count = 0;
port->flags &= ~ASYNC_NORMAL_ACTIVE; port->flags &= ~ASYNC_NORMAL_ACTIVE;
if (port->tty) { tty = port->tty;
set_bit(TTY_IO_ERROR, &port->tty->flags); if (tty)
tty_kref_put(port->tty); set_bit(TTY_IO_ERROR, &tty->flags);
}
port->tty = NULL; port->tty = NULL;
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
tty_port_shutdown(port); tty_port_shutdown(port, tty);
tty_kref_put(tty);
wake_up_interruptible(&port->open_wait); wake_up_interruptible(&port->open_wait);
wake_up_interruptible(&port->delta_msr_wait); wake_up_interruptible(&port->delta_msr_wait);
} }
...@@ -485,11 +493,6 @@ int tty_port_close_start(struct tty_port *port, ...@@ -485,11 +493,6 @@ int tty_port_close_start(struct tty_port *port,
/* Flush the ldisc buffering */ /* Flush the ldisc buffering */
tty_ldisc_flush(tty); tty_ldisc_flush(tty);
/* Drop DTR/RTS if HUPCL is set. This causes any attached modem to
hang up the line */
if (tty->termios.c_cflag & HUPCL)
tty_port_lower_dtr_rts(port);
/* Don't call port->drop for the last reference. Callers will want /* Don't call port->drop for the last reference. Callers will want
to drop the last active reference in ->shutdown() or the tty to drop the last active reference in ->shutdown() or the tty
shutdown path */ shutdown path */
...@@ -524,7 +527,7 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty, ...@@ -524,7 +527,7 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty,
{ {
if (tty_port_close_start(port, tty, filp) == 0) if (tty_port_close_start(port, tty, filp) == 0)
return; return;
tty_port_shutdown(port); tty_port_shutdown(port, tty);
set_bit(TTY_IO_ERROR, &tty->flags); set_bit(TTY_IO_ERROR, &tty->flags);
tty_port_close_end(port, tty); tty_port_close_end(port, tty);
tty_port_tty_set(port, NULL); tty_port_tty_set(port, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment