summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2016-10-11 20:51:32 (GMT)
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-11 22:06:30 (GMT)
commit8cfd56d4790423499d03f09f8584e0c6de494ec7 (patch)
tree214e9634190641a501cab0393580394a3b4f7eb9
parent1204c77f9b6ab8ba8cc6cfe00342f5e64a740cdf (diff)
downloadlinux-8cfd56d4790423499d03f09f8584e0c6de494ec7.tar.xz
lib/kstrtox.c: smaller _parse_integer()
Set "overflow" bit upon encountering it instead of postponing to the end of the conversion. Somehow gcc unwedges itself and generates better code: $ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux _parse_integer 177 139 -38 Inspired by patch from Zhaoxiu Zeng. Link: http://lkml.kernel.org/r/20160826221920.GA1909@p183.telecom.by Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--lib/kstrtox.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index d8a5cf6..b8e2080 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -48,11 +48,9 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
{
unsigned long long res;
unsigned int rv;
- int overflow;
res = 0;
rv = 0;
- overflow = 0;
while (*s) {
unsigned int val;
@@ -71,15 +69,13 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
*/
if (unlikely(res & (~0ull << 60))) {
if (res > div_u64(ULLONG_MAX - val, base))
- overflow = 1;
+ rv |= KSTRTOX_OVERFLOW;
}
res = res * base + val;
rv++;
s++;
}
*p = res;
- if (overflow)
- rv |= KSTRTOX_OVERFLOW;
return rv;
}