Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ffb6da9 authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman
Browse files

tty: Simplify tty_release() state checks



The local o_tty variable in tty_release() is now accessed only
when closing the pty master.

Set o_tty to slave pty when closing pty master, otherwise NULL;
use o_tty != NULL as replacement for pty_master.

Reviewed-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 359b9fb5
Loading
Loading
Loading
Loading
+9 −10
Original line number Original line Diff line number Diff line
@@ -1759,8 +1759,8 @@ static int tty_release_checks(struct tty_struct *tty, int idx)
int tty_release(struct inode *inode, struct file *filp)
int tty_release(struct inode *inode, struct file *filp)
{
{
	struct tty_struct *tty = file_tty(filp);
	struct tty_struct *tty = file_tty(filp);
	struct tty_struct *o_tty;
	struct tty_struct *o_tty = NULL;
	int	pty_master, do_sleep, final;
	int	do_sleep, final;
	int	idx;
	int	idx;
	char	buf[64];
	char	buf[64];


@@ -1773,9 +1773,8 @@ int tty_release(struct inode *inode, struct file *filp)
	__tty_fasync(-1, filp, 0);
	__tty_fasync(-1, filp, 0);


	idx = tty->index;
	idx = tty->index;
	pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
	if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
		      tty->driver->subtype == PTY_TYPE_MASTER);
	    tty->driver->subtype == PTY_TYPE_MASTER)
	/* Review: parallel close */
		o_tty = tty->link;
		o_tty = tty->link;


	if (tty_release_checks(tty, idx)) {
	if (tty_release_checks(tty, idx)) {
@@ -1820,7 +1819,7 @@ int tty_release(struct inode *inode, struct file *filp)
				do_sleep++;
				do_sleep++;
			}
			}
		}
		}
		if (pty_master && o_tty->count <= 1) {
		if (o_tty && o_tty->count <= 1) {
			if (waitqueue_active(&o_tty->read_wait)) {
			if (waitqueue_active(&o_tty->read_wait)) {
				wake_up_poll(&o_tty->read_wait, POLLIN);
				wake_up_poll(&o_tty->read_wait, POLLIN);
				do_sleep++;
				do_sleep++;
@@ -1838,7 +1837,7 @@ int tty_release(struct inode *inode, struct file *filp)
		schedule();
		schedule();
	}
	}


	if (pty_master) {
	if (o_tty) {
		if (--o_tty->count < 0) {
		if (--o_tty->count < 0) {
			printk(KERN_WARNING "%s: bad pty slave count (%d) for %s\n",
			printk(KERN_WARNING "%s: bad pty slave count (%d) for %s\n",
				__func__, o_tty->count, tty_name(o_tty, buf));
				__func__, o_tty->count, tty_name(o_tty, buf));
@@ -1872,13 +1871,13 @@ int tty_release(struct inode *inode, struct file *filp)
	if (!tty->count) {
	if (!tty->count) {
		read_lock(&tasklist_lock);
		read_lock(&tasklist_lock);
		session_clear_tty(tty->session);
		session_clear_tty(tty->session);
		if (pty_master)
		if (o_tty)
			session_clear_tty(o_tty->session);
			session_clear_tty(o_tty->session);
		read_unlock(&tasklist_lock);
		read_unlock(&tasklist_lock);
	}
	}


	/* check whether both sides are closing ... */
	/* check whether both sides are closing ... */
	final = !tty->count && !(pty_master && o_tty->count);
	final = !tty->count && !(o_tty && o_tty->count);


	tty_unlock_pair(tty, o_tty);
	tty_unlock_pair(tty, o_tty);
	/* At this point, the tty->count == 0 should ensure a dead tty
	/* At this point, the tty->count == 0 should ensure a dead tty