diff options
| author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-19 20:02:01 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-19 20:02:01 -0400 |
| commit | 10ce3cc919f50c2043b41ca968b43c26a3672600 (patch) | |
| tree | ea409366a5208aced495bc0516a08b81fd43222e /lib/kstrtox.c | |
| parent | 24e3e5ae1e4c2a3a32f5b1f96b4e3fd721806acd (diff) | |
| parent | 5c6a7a62c130afef3d61c1dee153012231ff5cd9 (diff) | |
Merge branch 'next' into for-linus
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 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) | |||
| 44 | * | 44 | * |
| 45 | * Don't you dare use this function. | 45 | * Don't you dare use this function. |
| 46 | */ | 46 | */ |
| 47 | unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res) | 47 | unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p) |
| 48 | { | 48 | { |
| 49 | unsigned long long res; | ||
| 49 | unsigned int rv; | 50 | unsigned int rv; |
| 50 | int overflow; | 51 | int overflow; |
| 51 | 52 | ||
| 52 | *res = 0; | 53 | res = 0; |
| 53 | rv = 0; | 54 | rv = 0; |
| 54 | overflow = 0; | 55 | overflow = 0; |
| 55 | while (*s) { | 56 | while (*s) { |
| @@ -64,12 +65,19 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long | |||
| 64 | 65 | ||
| 65 | if (val >= base) | 66 | if (val >= base) |
| 66 | break; | 67 | break; |
| 67 | if (*res > div_u64(ULLONG_MAX - val, base)) | 68 | /* |
| 68 | overflow = 1; | 69 | * Check for overflow only if we are within range of |
| 69 | *res = *res * base + val; | 70 | * it in the max base we support (16) |
| 71 | */ | ||
| 72 | if (unlikely(res & (~0ull << 60))) { | ||
| 73 | if (res > div_u64(ULLONG_MAX - val, base)) | ||
| 74 | overflow = 1; | ||
| 75 | } | ||
| 76 | res = res * base + val; | ||
| 70 | rv++; | 77 | rv++; |
| 71 | s++; | 78 | s++; |
| 72 | } | 79 | } |
| 80 | *p = res; | ||
| 73 | if (overflow) | 81 | if (overflow) |
| 74 | rv |= KSTRTOX_OVERFLOW; | 82 | rv |= KSTRTOX_OVERFLOW; |
| 75 | return rv; | 83 | return rv; |
