diff options
| author | Tony Lindgren <tony@atomide.com> | 2012-02-20 10:11:08 -0800 |
|---|---|---|
| committer | Tony Lindgren <tony@atomide.com> | 2012-02-20 10:11:08 -0800 |
| commit | 856c5403462419eff9a7891efeee7bddc2a08af6 (patch) | |
| tree | 2f4bb681e10ec1f895600fa0a4b0b177dadf6fb4 /lib | |
| parent | b0ee4e394009f02a1d1b166091a19e8b842b4ea4 (diff) | |
| parent | d517110243130965e2803cc2373d434bdaf6dafb (diff) | |
| download | cachepc-linux-856c5403462419eff9a7891efeee7bddc2a08af6.tar.gz cachepc-linux-856c5403462419eff9a7891efeee7bddc2a08af6.zip | |
Merge branch 'fixes-mmc' into fixes
Diffstat (limited to 'lib')
| -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 7a94c8f14e29..b1dd3e7d88cb 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; |
