linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 08/24] n_hdlc: invert conditions in n_hdlc_tty_close and n_hdlc_tty_poll
Date: Wed, 19 Feb 2020 09:41:02 +0100	[thread overview]
Message-ID: <20200219084118.26491-8-jslaby@suse.cz> (raw)
In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz>

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: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_hdlc.c | 72 +++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 34 deletions(-)

diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 07ba42badd7a..e40561caa450 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -258,24 +258,25 @@ static void n_hdlc_tty_close(struct tty_struct *tty)
 {
 	struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
 
-	if (n_hdlc != NULL) {
-		if (n_hdlc->magic != HDLC_MAGIC) {
-			printk (KERN_WARNING"n_hdlc: trying to close unopened tty!\n");
-			return;
-		}
+	if (!n_hdlc)
+		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)
-		clear_bit(TTY_NO_WRITE_SPLIT,&tty->flags);
+	clear_bit(TTY_NO_WRITE_SPLIT,&tty->flags);
 #endif
-		tty->disc_data = NULL;
-		if (tty == n_hdlc->backup_tty)
-			n_hdlc->backup_tty = NULL;
-		if (tty != n_hdlc->tty)
-			return;
-		if (n_hdlc->backup_tty) {
-			n_hdlc->tty = n_hdlc->backup_tty;
-		} else {
-			n_hdlc_release (n_hdlc);
-		}
+	tty->disc_data = NULL;
+	if (tty == n_hdlc->backup_tty)
+		n_hdlc->backup_tty = NULL;
+	if (tty != n_hdlc->tty)
+		return;
+	if (n_hdlc->backup_tty) {
+		n_hdlc->tty = n_hdlc->backup_tty;
+	} else {
+		n_hdlc_release (n_hdlc);
 	}
 }	/* end of n_hdlc_tty_close() */
 
@@ -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);
 	__poll_t mask = 0;
 
-	if (n_hdlc && n_hdlc->magic == HDLC_MAGIC && tty == n_hdlc->tty) {
-		/* queue current process into any wait queue that */
-		/* may awaken in the future (read and write) */
-
-		poll_wait(filp, &tty->read_wait, wait);
-		poll_wait(filp, &tty->write_wait, wait);
-
-		/* set bits for operations that won't block */
-		if (!list_empty(&n_hdlc->rx_buf_list.list))
-			mask |= EPOLLIN | EPOLLRDNORM;	/* readable */
-		if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
-			mask |= EPOLLHUP;
-		if (tty_hung_up_p(filp))
-			mask |= EPOLLHUP;
-		if (!tty_is_writelocked(tty) &&
-				!list_empty(&n_hdlc->tx_free_buf_list.list))
-			mask |= EPOLLOUT | EPOLLWRNORM;	/* writable */
-	}
+	if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || tty != n_hdlc->tty)
+		return 0;
+
+	/*
+	 * queue the current process into any wait queue that may awaken in the
+	 * future (read and write)
+	 */
+	poll_wait(filp, &tty->read_wait, wait);
+	poll_wait(filp, &tty->write_wait, wait);
+
+	/* set bits for operations that won't block */
+	if (!list_empty(&n_hdlc->rx_buf_list.list))
+		mask |= EPOLLIN | EPOLLRDNORM;	/* readable */
+	if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
+		mask |= EPOLLHUP;
+	if (tty_hung_up_p(filp))
+		mask |= EPOLLHUP;
+	if (!tty_is_writelocked(tty) &&
+			!list_empty(&n_hdlc->tx_free_buf_list.list))
+		mask |= EPOLLOUT | EPOLLWRNORM;	/* writable */
+
 	return mask;
 }	/* end of n_hdlc_tty_poll() */
 
-- 
2.25.0


  parent reply	other threads:[~2020-02-19  8:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19  8:40 [PATCH 01/24] n_hdlc: remove tracing debug prints Jiri Slaby
2020-02-19  8:40 ` [PATCH 02/24] n_hdlc: remove unused macros Jiri Slaby
2020-02-19  8:40 ` [PATCH 03/24] n_hdlc: convert debuglevel use to pr_debug Jiri Slaby
2020-02-19 12:20   ` Joe Perches
2020-02-20 12:45     ` Greg KH
2020-02-21  8:16     ` Jiri Slaby
2020-02-19  8:40 ` [PATCH 04/24] n_hdlc: put init/exit strings directly to prints Jiri Slaby
2020-02-19  8:40 ` [PATCH 05/24] n_hdlc: cleanup messages during registration Jiri Slaby
2020-02-19  8:41 ` [PATCH 06/24] n_hdlc: use clamp() for maxframe Jiri Slaby
2020-02-19  8:41 ` [PATCH 07/24] n_hdlc: simplify freeing of buffer list Jiri Slaby
2020-02-19  8:41 ` Jiri Slaby [this message]
2020-02-19  8:41 ` [PATCH 09/24] n_hdlc: remove unused flags Jiri Slaby
2020-02-19  8:41 ` [PATCH 10/24] n_hdlc: remove unused backup_tty Jiri Slaby
2020-02-19  8:41 ` [PATCH 11/24] n_hdlc: expand tty2n_hdlc macro Jiri Slaby
2020-02-19  8:41 ` [PATCH 12/24] n_hdlc: inline n_hdlc_release Jiri Slaby
2020-02-19  8:41 ` [PATCH 13/24] n_hdlc: remove cached tty Jiri Slaby
2020-02-19  8:41 ` [PATCH 14/24] n_hdlc: remove checking of n_hdlc Jiri Slaby
2020-02-19  8:41 ` [PATCH 15/24] n_hdlc: add helper for buffers allocation Jiri Slaby
2020-02-19  8:41 ` [PATCH 16/24] n_hdlc: move tty_ldisc_ops to the bottom Jiri Slaby
2020-02-19  8:41 ` [PATCH 17/24] n_hdlc: switch tbusy and woke_up to bools Jiri Slaby
2020-02-19  8:41 ` [PATCH 18/24] n_hdlc: remove unneeded ifdef Jiri Slaby
2020-02-19  8:41 ` [PATCH 19/24] n_hdlc: use __func__ and pr_ print helpers Jiri Slaby
2020-02-19  8:41 ` [PATCH 20/24] n_hdlc: remove useless whitespace at line wraps Jiri Slaby
2020-02-19  8:41 ` [PATCH 21/24] n_hdlc: remove spaces between function name and ( Jiri Slaby
2020-02-19  8:41 ` [PATCH 22/24] n_hdlc: add missing spaces after commas Jiri Slaby
2020-02-19  8:41 ` [PATCH 23/24] n_hdlc: fix whitespace around binary operators Jiri Slaby
2020-02-19  8:41 ` [PATCH 24/24] n_hdlc: wrap a comment properly Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200219084118.26491-8-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).