Commit f7d5bcd
selftests: kselftest: Mark functions that unconditionally call exit() as __noreturn
After commit 6d029c2 ("selftests/timers/posix_timers: Reimplement
check_timer_distribution()"), clang warns:
tools/testing/selftests/timers/../kselftest.h:398:6: warning: variable 'major' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
398 | if (uname(&info) || sscanf(info.release, "%u.%u.", &major, &minor) != 2)
| ^~~~~~~~~~~~
tools/testing/selftests/timers/../kselftest.h:401:9: note: uninitialized use occurs here
401 | return major > min_major || (major == min_major && minor >= min_minor);
| ^~~~~
tools/testing/selftests/timers/../kselftest.h:398:6: note: remove the '||' if its condition is always false
398 | if (uname(&info) || sscanf(info.release, "%u.%u.", &major, &minor) != 2)
| ^~~~~~~~~~~~~~~
tools/testing/selftests/timers/../kselftest.h:395:20: note: initialize the variable 'major' to silence this warning
395 | unsigned int major, minor;
| ^
| = 0
This is a false positive because if uname() fails, ksft_exit_fail_msg()
will be called, which unconditionally calls exit(), a noreturn function.
However, clang does not know that ksft_exit_fail_msg() will call exit() at
the point in the pipeline that the warning is emitted because inlining has
not occurred, so it assumes control flow will resume normally after
ksft_exit_fail_msg() is called.
Make it clear to clang that all of the functions that call exit()
unconditionally in kselftest.h are noreturn transitively by marking them
explicitly with '__attribute__((__noreturn__))', which clears up the
warning above and any future warnings that may appear for the same reason.
Fixes: 6d029c2 ("selftests/timers/posix_timers: Reimplement check_timer_distribution()")
Reported-by: John Stultz <jstultz@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240411-mark-kselftest-exit-funcs-noreturn-v1-1-b027c948f586@kernel.org
Closes: https://lore.kernel.org/all/20240410232637.4135564-2-jstultz@google.com/1 parent e4a6bce commit f7d5bcd
1 file changed
+9
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
300 | 303 | | |
301 | 304 | | |
302 | 305 | | |
303 | | - | |
| 306 | + | |
304 | 307 | | |
305 | 308 | | |
306 | 309 | | |
307 | 310 | | |
308 | 311 | | |
309 | | - | |
| 312 | + | |
310 | 313 | | |
311 | 314 | | |
312 | 315 | | |
| |||
333 | 336 | | |
334 | 337 | | |
335 | 338 | | |
336 | | - | |
| 339 | + | |
337 | 340 | | |
338 | 341 | | |
339 | 342 | | |
| |||
348 | 351 | | |
349 | 352 | | |
350 | 353 | | |
351 | | - | |
| 354 | + | |
352 | 355 | | |
353 | 356 | | |
354 | 357 | | |
355 | 358 | | |
356 | 359 | | |
357 | | - | |
| 360 | + | |
358 | 361 | | |
359 | 362 | | |
360 | 363 | | |
361 | 364 | | |
362 | 365 | | |
363 | | - | |
| 366 | + | |
364 | 367 | | |
365 | 368 | | |
366 | 369 | | |
| |||
0 commit comments