diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2016-10-11 16:51:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-11 18:06:30 -0400 |
commit | 8cfd56d4790423499d03f09f8584e0c6de494ec7 (patch) | |
tree | 214e9634190641a501cab0393580394a3b4f7eb9 /lib/kstrtox.c | |
parent | 1204c77f9b6ab8ba8cc6cfe00342f5e64a740cdf (diff) |
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>
Diffstat (limited to 'lib/kstrtox.c')
-rw-r--r-- | lib/kstrtox.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/lib/kstrtox.c b/lib/kstrtox.c index d8a5cf66c316..b8e2080c1a47 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 | |||
48 | { | 48 | { |
49 | unsigned long long res; | 49 | unsigned long long res; |
50 | unsigned int rv; | 50 | unsigned int rv; |
51 | int overflow; | ||
52 | 51 | ||
53 | res = 0; | 52 | res = 0; |
54 | rv = 0; | 53 | rv = 0; |
55 | overflow = 0; | ||
56 | while (*s) { | 54 | while (*s) { |
57 | unsigned int val; | 55 | unsigned int val; |
58 | 56 | ||
@@ -71,15 +69,13 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long | |||
71 | */ | 69 | */ |
72 | if (unlikely(res & (~0ull << 60))) { | 70 | if (unlikely(res & (~0ull << 60))) { |
73 | if (res > div_u64(ULLONG_MAX - val, base)) | 71 | if (res > div_u64(ULLONG_MAX - val, base)) |
74 | overflow = 1; | 72 | rv |= KSTRTOX_OVERFLOW; |
75 | } | 73 | } |
76 | res = res * base + val; | 74 | res = res * base + val; |
77 | rv++; | 75 | rv++; |
78 | s++; | 76 | s++; |
79 | } | 77 | } |
80 | *p = res; | 78 | *p = res; |
81 | if (overflow) | ||
82 | rv |= KSTRTOX_OVERFLOW; | ||
83 | return rv; | 79 | return rv; |
84 | } | 80 | } |
85 | 81 | ||