diff options
author | Colin Cross <ccross@android.com> | 2012-02-21 12:45:05 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2012-02-21 12:45:05 -0800 |
commit | fbd94b86e411e6ea0b4fa56682120b32af5c16c2 (patch) | |
tree | 59f59602de610bddfad66e294cb42ee1d1f29d31 /lib | |
parent | 293f64abe6006f6ff1cc6f672e27729ff7b74ead (diff) | |
parent | b01543dfe67bb1d191998e90d20534dc354de059 (diff) |
Merge commit 'v3.3-rc4' into android-3.3
Conflicts:
drivers/mmc/core/sdio.c
drivers/staging/android/Kconfig
drivers/staging/android/lowmemorykiller.c
Change-Id: I39ef9b27bb9febaee811b200ccac0ed5d51147f3
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 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; |