]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
overflow: Allow non-type arg to type_max() and type_min()
authorKees Cook <keescook@chromium.org>
Fri, 1 Mar 2024 06:22:26 +0000 (22:22 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Apr 2024 11:07:32 +0000 (13:07 +0200)
commit2618ab102c80619211eb3a995ccbc74543d5aa9a
treef3019960e4b481b44a3af2fa534fdbd56a6fbfab
parent3ba4aceb68f013f36fbfd0a6aab5df439b4198d4
overflow: Allow non-type arg to type_max() and type_min()

[ Upstream commit bd1ebf2467f9c5d157bec7b025e83f8ffdae1318 ]

A common use of type_max() is to find the max for the type of a
variable. Using the pattern type_max(typeof(var)) is needlessly
verbose. Instead, since typeof(type) == type we can just explicitly
call typeof() on the argument to type_max() and type_min(). Add
wrappers for readability.

We can do some replacements right away:

$ git grep '\btype_\(min\|max\)(typeof' | wc -l
11

Link: https://lore.kernel.org/r/20240301062221.work.840-kees@kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/overflow.h