All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anshul Garg <aksgarg1989@gmail.com>
To: akpm@linux-foundation.org, levex@linux.com,
	felipe.contreras@gmail.com, linux-kernel@vger.kernel.org
Cc: aksgarg1989@gmail.com, anshul.g@samsung.com
Subject: [PATCH] lib/kstrtox.c clean kstrtoll function
Date: Thu, 22 Jan 2015 05:54:10 -0800	[thread overview]
Message-ID: <1421934850-77446-1-git-send-email-aksgarg1989@gmail.com> (raw)
In-Reply-To: <aksgarg1989@gmai.com>

From: Anshul Garg <aksgarg1989@gmail.com>

Instead of having same code for negative and postive
integer, use sign variable for integer parsing.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 lib/kstrtox.c |   24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index ec8da78..744cbb0 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -146,23 +146,19 @@ EXPORT_SYMBOL(kstrtoull);
 int kstrtoll(const char *s, unsigned int base, long long *res)
 {
 	unsigned long long tmp;
-	int rv;
+	int rv, sign = 1;
 
 	if (s[0] == '-') {
-		rv = _kstrtoull(s + 1, base, &tmp);
-		if (rv < 0)
-			return rv;
-		if ((long long)(-tmp) >= 0)
-			return -ERANGE;
-		*res = -tmp;
-	} else {
-		rv = kstrtoull(s, base, &tmp);
-		if (rv < 0)
-			return rv;
-		if ((long long)tmp < 0)
-			return -ERANGE;
-		*res = tmp;
+		sign = -1;
+		s++;
 	}
+
+	rv = kstrtoull(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if ((long long)tmp < 0)
+		return -ERANGE;
+	*res = sign * tmp;
 	return 0;
 }
 EXPORT_SYMBOL(kstrtoll);
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com


       reply	other threads:[~2015-01-22 13:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <aksgarg1989@gmai.com>
2015-01-22 13:54 ` Anshul Garg [this message]
2015-01-22 17:25   ` [PATCH] lib/kstrtox.c clean kstrtoll function Jeff Epler
2015-01-23 13:25     ` Anshul Garg
2015-01-24 19:30       ` Jeff Epler

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=1421934850-77446-1-git-send-email-aksgarg1989@gmail.com \
    --to=aksgarg1989@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshul.g@samsung.com \
    --cc=felipe.contreras@gmail.com \
    --cc=levex@linux.com \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.