lkml.org 
[lkml]   [2024]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version
On Thu, Apr 11, 2024 at 8:39 AM Nathan Chancellor <nathan@kernel.org> wrote:
> On Wed, Apr 10, 2024 at 04:26:29PM -0700, John Stultz wrote:
> > Building with clang, I see the following warning:
> >
> > In file included from posix_timers.c:17:
> > ./../kselftest.h:398:6: warning: variable 'major' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
> > if (uname(&info) || sscanf(info.release, "%u.%u.", &major, &minor) != 2)
> > ^~~~~~~~~~~~
> > ./../kselftest.h:401:9: note: uninitialized use occurs here
> > return major > min_major || (major == min_major && minor >= min_minor);
> > ^~~~~
> >
> > This is a bit of a red-herring as if the uname() call did fail,
> > we would hit ksft_exit_fail_msg() which should exit.
>
> Correct, although we have not really conveyed that to the compiler,
> right? exit() is noreturn, which means all functions that call exit()
> unconditionally are also noreturn, such as ksft_exit_fail_msg(). LLVM
> will figure this out once it performs inlining and such but that happens
> after clang's static analysis phase that this warning occurs in. I think
> a better solution would be to add __noreturn to the functions in
> tools/testing/selftests/kselftest.h that call exit(), so that the
> compiler is aware of this through all pipeline phases, maybe something
> like this? It resolves the wawrning for me.

No objection from me if this is the better approach.

Would you send that patch out?

thanks
-john

\
 
 \ /
  Last update: 2024-05-27 16:36    [W:0.068 / U:0.364 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site