]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
lib: stackinit: hide never-taken branch from compiler
authorKees Cook <kees@kernel.org>
Sun, 17 Nov 2024 11:38:13 +0000 (03:38 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2025 12:28:41 +0000 (13:28 +0100)
commit2461ffdc772523f7bc2e1e67028c6e559d63a70b
treeb03271abd385bcb008f48f235424c5755c64cc3a
parent002668bfd4162259282965cb6d36b401effd33ff
lib: stackinit: hide never-taken branch from compiler

[ Upstream commit 5c3793604f91123bf49bc792ce697a0bef4c173c ]

The never-taken branch leads to an invalid bounds condition, which is by
design. To avoid the unwanted warning from the compiler, hide the
variable from the optimizer.

../lib/stackinit_kunit.c: In function 'do_nothing_u16_zero':
../lib/stackinit_kunit.c:51:49: error: array subscript 1 is outside array bounds of 'u16[0]' {aka 'short unsigned int[]'} [-Werror=array-bounds=]
   51 | #define DO_NOTHING_RETURN_SCALAR(ptr)           *(ptr)
      |                                                 ^~~~~~
../lib/stackinit_kunit.c:219:24: note: in expansion of macro 'DO_NOTHING_RETURN_SCALAR'
  219 |                 return DO_NOTHING_RETURN_ ## which(ptr + 1);    \
      |                        ^~~~~~~~~~~~~~~~~~

Link: https://lkml.kernel.org/r/20241117113813.work.735-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
lib/test_stackinit.c