From: Tejun Heo <tj@kernel.org>
To: Zhiqi Zhang <zhiqizhangg@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Michal Koutny <mkoutny@suse.com>, Shuah Khan <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3] cgroup: Preserve sign for fractional input
Date: Mon, 30 Nov 2026 21:31:42 -1000 [thread overview]
Message-ID: <99f0b59fc42085f9485f5dbaaadece9e@kernel.org> (raw)
In-Reply-To: <20261201022211.7609-1-zhiqizhangg@gmail.com>
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
prev parent reply other threads:[~2026-12-01 7:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 6:59 [PATCH] cgroup: Preserve sign for fractional input Zhiqi Zhang
2026-11-27 14:49 ` Tejun Heo
2026-11-29 15:01 ` [PATCH v2] " Zhiqi Zhang
2026-11-29 16:58 ` Tejun Heo
2026-12-01 2:22 ` [PATCH v3] " Zhiqi Zhang
2026-12-01 7:31 ` Tejun Heo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=99f0b59fc42085f9485f5dbaaadece9e@kernel.org \
--to=tj@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=shuah@kernel.org \
--cc=zhiqizhangg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.