diff options
| author | Grant Likely <grant.likely@secretlab.ca> | 2012-02-28 13:48:58 -0600 |
|---|---|---|
| committer | Grant Likely <grant.likely@secretlab.ca> | 2012-02-28 13:48:58 -0600 |
| commit | b3950d50cfc343b3e7dc5c69c96a61b182fd1e37 (patch) | |
| tree | d54affae2b1e25464493b48aa88cd8d6b4770812 /lib/kstrtox.c | |
| parent | daefd89efc279b142bbb054577c2d706da211723 (diff) | |
| parent | 280ad7fda5f95211857fda38960f2b6fdf6edd3e (diff) | |
| download | olio-linux-3.10-b3950d50cfc343b3e7dc5c69c96a61b182fd1e37.tar.xz olio-linux-3.10-b3950d50cfc343b3e7dc5c69c96a61b182fd1e37.zip | |
Merge branch 'irqdomain/next' into gpio/next
Diffstat (limited to 'lib/kstrtox.c')
| -rw-r--r-- | lib/kstrtox.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/kstrtox.c b/lib/kstrtox.c index 7a94c8f14e2..b1dd3e7d88c 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -44,12 +44,13 @@ const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) * * Don't you dare use this function. */ -unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res) +unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p) { + unsigned long long res; unsigned int rv; int overflow; - *res = 0; + res = 0; rv = 0; overflow = 0; while (*s) { @@ -64,12 +65,19 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long if (val >= base) break; - if (*res > div_u64(ULLONG_MAX - val, base)) - overflow = 1; - *res = *res * base + val; + /* + * Check for overflow only if we are within range of + * it in the max base we support (16) + */ + if (unlikely(res & (~0ull << 60))) { + if (res > div_u64(ULLONG_MAX - val, base)) + overflow = 1; + } + res = res * base + val; rv++; s++; } + *p = res; if (overflow) rv |= KSTRTOX_OVERFLOW; return rv; |