]> git.ipfire.org Git - thirdparty/linux.git/commit
fortify: Use C arithmetic not FIELD_xxx() in FORTIFY_REASON defines
authorDavid Laight <david.laight.linux@gmail.com>
Sun, 14 Dec 2025 12:58:57 +0000 (12:58 +0000)
committerKees Cook <kees@kernel.org>
Thu, 15 Jan 2026 03:49:52 +0000 (19:49 -0800)
commit995ddc58d791bb85b1b044d295e1fe4fad48ba72
tree591bc1c238cad1a2a3b354202946c2e28c2d4744
parentcc34c669abe0c198daec20de5185c8187f4b240d
fortify: Use C arithmetic not FIELD_xxx() in FORTIFY_REASON defines

FIELD_GET() and FIELD_PREP() are mainly useful for hardware register
accesses, but here they are being used for some very simple oprations.

This wouldn't matter much, but they contain a lot of compile-time
checks (that really aren't needed here) that bloat the expansion
of FIELD_GET(GENMASK(7, 1), func) to over 18KB.
Even with the 'bloat reduced' FIELD_GET/PREP they are still hundreds of
characters.

Replace FIELD_GET(BIT(0), r) with ((r) & 1), FIELD_GET(GENMASK(7, 1), r) with
(r) >> 1), and (FIELD_PREP(BIT(0), write) | FIELD_PREP(GENMASK(7, 1), func))
with ((func) << 1 | (write)).

The generated code is the same, but it makes the .c file less obfuctaced,
the .i file much easier to read, and should marginally decrease compilation
time.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Link: https://patch.msgid.link/20251214125857.3308-1-david.laight.linux@gmail.com
Signed-off-by: Kees Cook <kees@kernel.org>
include/linux/fortify-string.h