Skip to content

Commit 5c37936

Browse files
keesakpm00
authored andcommitted
lib: stackinit: hide never-taken branch from compiler
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>
1 parent 3203b3a commit 5c37936

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/stackinit_kunit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static noinline void test_ ## name (struct kunit *test) \
212212
static noinline DO_NOTHING_TYPE_ ## which(var_type) \
213213
do_nothing_ ## name(var_type *ptr) \
214214
{ \
215+
OPTIMIZER_HIDE_VAR(ptr); \
215216
/* Will always be true, but compiler doesn't know. */ \
216217
if ((unsigned long)ptr > 0x2) \
217218
return DO_NOTHING_RETURN_ ## which(ptr); \

0 commit comments

Comments
 (0)