Re: [PATCH v3] cgroup: Preserve sign for fractional input
From: Tejun Heo
Date: Tue Dec 01 2026 - 02:31:55 EST
Hello, Zhiqi.
On Tue, Dec 01, 2026 at 10:22:11AM +0800, Zhiqi Zhang wrote:
> + whole = 0;
> + p = input;
> + if (!isdigit(*p))
> return -EINVAL;
>
> - p = input + wlen;
> + while (isdigit(*p)) {
> + int digit = *p++ - '0';
> +
> + if (check_mul_overflow(whole, 10, &whole) ||
> + check_add_overflow(whole, digit, &whole))
> + return -ERANGE;
> + }
Can you keep sscanf() for the whole part and just switch it to %llu after
reading the sign? That would accept whitespace between the sign and the
digits but that's fine.
> + max_abs = negative ? (u64)S64_MAX + 1 : S64_MAX;
> + if (abs_v > max_abs)
> + return -ERANGE;
> +
> + if (negative)
> + *v = abs_v == max_abs ? S64_MIN : -(s64)abs_v;
> + else
> + *v = abs_v;
Maybe just range check against S64_MAX and negate if negative? No need to
handle S64_MIN.
Thanks.
--
tejun