Commit abd08af3 authored by Peter Hurley's avatar Peter Hurley Committed by Kleber Sacilotto de Souza

tty: Simplify tty_set_ldisc() exit handling

BugLink: http://bugs.launchpad.net/bugs/1709126

Perform common exit for both successful and error exit handling
in tty_set_ldisc(). Fixes unlikely possibility of failing to restart
input kworker when switching to the same line discipline (noop case).
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 63d8cb3f)
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Acked-by: default avatarMarcelo Cerri <marcelo.cerri@canonical.com>
Acked-by: default avatarBenjamin M Romer <benjamin.romer@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 82993d9c
......@@ -536,34 +536,21 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
tty_lock(tty);
retval = tty_ldisc_lock(tty, 5 * HZ);
if (retval) {
tty_ldisc_put(new_ldisc);
tty_unlock(tty);
return retval;
}
if (retval)
goto err;
/*
* Check the no-op case
*/
/* Check the no-op case */
if (tty->ldisc->ops->num == ldisc)
goto out;
if (tty->ldisc->ops->num == ldisc) {
tty_ldisc_unlock(tty);
tty_ldisc_put(new_ldisc);
tty_unlock(tty);
return 0;
if (test_bit(TTY_HUPPED, &tty->flags)) {
/* We were raced by hangup */
retval = -EIO;
goto out;
}
old_ldisc = tty->ldisc;
if (test_bit(TTY_HUPPED, &tty->flags)) {
/* We were raced by the hangup method. It will have stomped
the ldisc data and closed the ldisc down */
tty_ldisc_unlock(tty);
tty_ldisc_put(new_ldisc);
tty_unlock(tty);
return -EIO;
}
/* Shutdown the old discipline. */
tty_ldisc_close(tty, old_ldisc);
......@@ -589,18 +576,15 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
the old ldisc (if it was restored as part of error cleanup
above). In either case, releasing a single reference from
the old ldisc is correct. */
tty_ldisc_put(old_ldisc);
/*
* Allow ldisc referencing to occur again
*/
new_ldisc = old_ldisc;
out:
tty_ldisc_unlock(tty);
/* Restart the work queue in case no characters kick it off. Safe if
already running */
tty_buffer_restart_work(tty->port);
err:
tty_ldisc_put(new_ldisc); /* drop the extra reference */
tty_unlock(tty);
return retval;
}
......
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