On Mon, Jan 26, 2026 at 07:20:57PM +0300, Dmitry Antipov wrote:
> In '_parse_integer_limit()', replace native integer arithmetic with
> 'check_mul_overflow()' and 'check_add_overflow()' to check whether
> an intermediate result goes out of range, and denote such a case
> with ULLONG_MAX, thus making the function more similar to standard
> C library's 'strtoull()'. Adjust comment to kernel-doc style as well.
...
> - if (unlikely(res & (~0ull << 60))) {
> - if (res > div_u64(ULLONG_MAX - val, base))
Interestingly, but the original check was made to improve performance. We don't
need to worry about overflow unless we close to it. It also has a hint to the
compiler to take branch as a slow path.
> + if (res != ULLONG_MAX) {
> + /*
> + * tmp = res * base;
> + * if (overflow)
> + * res = ULLONG_MAX;
> + * else {
> + * res = tmp + val;
> + * if (overflow)
> + * res = ULLONG_MAX;
> + * }
> + */
This looks like a left over. Use plain English to explain what's going on
here. But I think this should be only done for the last a couple of iterations
only.
> + if (check_mul_overflow(res, base, &tmp) ||
> + check_add_overflow(tmp, val, &res)) {
> + res = ULLONG_MAX;
> rv |= KSTRTOX_OVERFLOW;
> + }
> }
> - res = res * base + val;
> rv++;
> s++;
> }
--
With Best Regards,
Andy Shevchenko