linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daeseok Youn <daeseok.youn@gmail.com>
To: lidza.louina@gmail.com
Cc: markh@compro.net, gregkh@linuxfoundation.org,
	driverdev-devel@linuxdriverproject.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] staging: dgnc: refactor the dgnc_maxcps_room() to improve
Date: Fri, 19 Aug 2016 10:05:19 +0900	[thread overview]
Message-ID: <20160819010519.GA8031@SEL-JYOUN-D1> (raw)

The whole code in dgnc_maxcps_room() function surrounds with
one if-statement for checking channel's maxcps and buffer size.
I tried to separate the logic for this function from if-condition.

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
---
 drivers/staging/dgnc/dgnc_tty.c | 46 +++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 31b18e6..cb31b83 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -1494,30 +1494,32 @@ static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
  */
 static int dgnc_maxcps_room(struct channel_t *ch, int bytes_available)
 {
-	if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
-		int cps_limit = 0;
-		unsigned long current_time = jiffies;
-		unsigned long buffer_time = current_time +
-			(HZ * ch->ch_digi.digi_bufsize) /
-			ch->ch_digi.digi_maxcps;
-
-		if (ch->ch_cpstime < current_time) {
-			/* buffer is empty */
-			ch->ch_cpstime = current_time;	/* reset ch_cpstime */
-			cps_limit = ch->ch_digi.digi_bufsize;
-		} else if (ch->ch_cpstime < buffer_time) {
-			/* still room in the buffer */
-			cps_limit = ((buffer_time - ch->ch_cpstime) *
-					ch->ch_digi.digi_maxcps) / HZ;
-		} else {
-			/* no room in the buffer */
-			cps_limit = 0;
-		}
-
-		bytes_available = min(cps_limit, bytes_available);
+	int cps_limit;
+	unsigned long current_time;
+	unsigned long buffer_time;
+
+	if (ch->ch_digi.digi_maxcps <= 0 ||
+	    ch->ch_digi.digi_bufsize <= 0)
+		return bytes_available;
+
+	current_time = jiffies;
+	buffer_time = current_time + (HZ * ch->ch_digi.digi_bufsize) /
+		      ch->ch_digi.digi_maxcps;
+
+	if (ch->ch_cpstime < current_time) {
+		/* buffer is empty */
+		ch->ch_cpstime = current_time;	/* reset ch_cpstime */
+		cps_limit = ch->ch_digi.digi_bufsize;
+	} else if (ch->ch_cpstime < buffer_time) {
+		/* still room in the buffer */
+		cps_limit = ((buffer_time - ch->ch_cpstime) *
+				ch->ch_digi.digi_maxcps) / HZ;
+	} else {
+		/* no room in the buffer */
+		cps_limit = 0;
 	}
 
-	return bytes_available;
+	return min(cps_limit, bytes_available);
 }
 
 /*
-- 
1.9.1

             reply	other threads:[~2016-08-19  1:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19  1:05 Daeseok Youn [this message]
2016-08-21 15:56 ` [PATCH 2/2] staging: dgnc: refactor the dgnc_maxcps_room() to improve Greg KH

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=20160819010519.GA8031@SEL-JYOUN-D1 \
    --to=daeseok.youn@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lidza.louina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markh@compro.net \
    /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).