Commit 5f289514 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

n_hdlc: invert conditions in n_hdlc_tty_close and n_hdlc_tty_poll

This makes the functions return immediatelly on invalid state. And we
can push the indent of the later code one level left.

Pass "-w" to "git show" to see we are changing only the conditions (and
whitespace).
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20200219084118.26491-8-jslaby@suse.czSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 30fafd92
...@@ -258,24 +258,25 @@ static void n_hdlc_tty_close(struct tty_struct *tty) ...@@ -258,24 +258,25 @@ static void n_hdlc_tty_close(struct tty_struct *tty)
{ {
struct n_hdlc *n_hdlc = tty2n_hdlc (tty); struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
if (n_hdlc != NULL) { if (!n_hdlc)
if (n_hdlc->magic != HDLC_MAGIC) { return;
printk (KERN_WARNING"n_hdlc: trying to close unopened tty!\n");
return; if (n_hdlc->magic != HDLC_MAGIC) {
} printk(KERN_WARNING "n_hdlc: trying to close unopened tty!\n");
return;
}
#if defined(TTY_NO_WRITE_SPLIT) #if defined(TTY_NO_WRITE_SPLIT)
clear_bit(TTY_NO_WRITE_SPLIT,&tty->flags); clear_bit(TTY_NO_WRITE_SPLIT,&tty->flags);
#endif #endif
tty->disc_data = NULL; tty->disc_data = NULL;
if (tty == n_hdlc->backup_tty) if (tty == n_hdlc->backup_tty)
n_hdlc->backup_tty = NULL; n_hdlc->backup_tty = NULL;
if (tty != n_hdlc->tty) if (tty != n_hdlc->tty)
return; return;
if (n_hdlc->backup_tty) { if (n_hdlc->backup_tty) {
n_hdlc->tty = n_hdlc->backup_tty; n_hdlc->tty = n_hdlc->backup_tty;
} else { } else {
n_hdlc_release (n_hdlc); n_hdlc_release (n_hdlc);
}
} }
} /* end of n_hdlc_tty_close() */ } /* end of n_hdlc_tty_close() */
...@@ -737,24 +738,27 @@ static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, ...@@ -737,24 +738,27 @@ static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp,
struct n_hdlc *n_hdlc = tty2n_hdlc (tty); struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
__poll_t mask = 0; __poll_t mask = 0;
if (n_hdlc && n_hdlc->magic == HDLC_MAGIC && tty == n_hdlc->tty) { if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || tty != n_hdlc->tty)
/* queue current process into any wait queue that */ return 0;
/* may awaken in the future (read and write) */
/*
poll_wait(filp, &tty->read_wait, wait); * queue the current process into any wait queue that may awaken in the
poll_wait(filp, &tty->write_wait, wait); * future (read and write)
*/
/* set bits for operations that won't block */ poll_wait(filp, &tty->read_wait, wait);
if (!list_empty(&n_hdlc->rx_buf_list.list)) poll_wait(filp, &tty->write_wait, wait);
mask |= EPOLLIN | EPOLLRDNORM; /* readable */
if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) /* set bits for operations that won't block */
mask |= EPOLLHUP; if (!list_empty(&n_hdlc->rx_buf_list.list))
if (tty_hung_up_p(filp)) mask |= EPOLLIN | EPOLLRDNORM; /* readable */
mask |= EPOLLHUP; if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
if (!tty_is_writelocked(tty) && mask |= EPOLLHUP;
!list_empty(&n_hdlc->tx_free_buf_list.list)) if (tty_hung_up_p(filp))
mask |= EPOLLOUT | EPOLLWRNORM; /* writable */ mask |= EPOLLHUP;
} if (!tty_is_writelocked(tty) &&
!list_empty(&n_hdlc->tx_free_buf_list.list))
mask |= EPOLLOUT | EPOLLWRNORM; /* writable */
return mask; return mask;
} /* end of n_hdlc_tty_poll() */ } /* end of n_hdlc_tty_poll() */
......
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