From: Tejun Heo <tj@kernel.org>
To: "Kumar, Kaushlendra" <kaushlendra.kumar@intel.com>
Cc: "hannes@cmpxchg.org" <hannes@cmpxchg.org>,
"mkoutny@suse.com" <mkoutny@suse.com>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>
Subject: Re: [PATCH] cgroup: ensure stable pid sorting in cmppid()
Date: Fri, 20 Feb 2026 20:55:44 -1000 [thread overview]
Message-ID: <aZlW8InMu6s2_RYc@slm.duckdns.org> (raw)
In-Reply-To: <LV3PR11MB8768B0A29D442DD409E6D8BEF569A@LV3PR11MB8768.namprd11.prod.outlook.com>
On Sat, Feb 21, 2026 at 05:45:03AM +0000, Kumar, Kaushlendra wrote:
> > Can you give examples of such an overflow? What values
> > would cause that?
>
> pid_t is a signed 32-bit integer. Consider:
>
> a = 2147483647 (INT_MAX, 0x7FFFFFFF)
> b = -1
>
> a - b = 2147483647 - (-1) = 2147483648
>
> This overflows signed int32, wrapping to a big negative value.
>
> In practice, pid_t values in Linux are positive
and limited to PID_MAX_LIMIT (4mil).
> , so this overflow cannot happen with real PIDs
> today. However, the subtraction pattern is a known
> antipattern for comparison functions, and using the
> three-way idiom is the safer.(less, greater and equal)
It's a bigger anti pattern to complicate code for non-existent problems.
Thanks.
--
tejun
prev parent reply other threads:[~2026-02-21 6:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-21 3:49 [PATCH] cgroup: ensure stable pid sorting in cmppid() Kaushlendra Kumar
2026-02-21 5:00 ` Tejun Heo
2026-02-21 5:45 ` Kumar, Kaushlendra
2026-02-21 6:55 ` 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=aZlW8InMu6s2_RYc@slm.duckdns.org \
--to=tj@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kaushlendra.kumar@intel.com \
--cc=mkoutny@suse.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.