public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning
@ 2024-04-10 23:26 John Stultz
  2024-04-10 23:26 ` [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version John Stultz
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: John Stultz @ 2024-04-10 23:26 UTC (permalink / raw)
  To: LKML
  Cc: John Stultz, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Oleg Nesterov,
	Andrew Morton, Edward Liaw, Carlos Llamas, kernel-team,
	linux-kselftest

After commit 6d029c25b71f ("selftests/timers/posix_timers:
Reimplement check_timer_distribution()") I started seeing the
following warning building with an older gcc:

posix_timers.c:250:2: warning: format not a string literal and no format arguments [-Wformat-security]
  250 |  ksft_print_msg(errmsg);
      |  ^~~~~~~~~~~~~~

Fix this up by changing it to ksft_print_msg("%s", errmsg)

Cc: Shuah Khan <shuah@kernel.org>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Edward Liaw <edliaw@google.com>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: kernel-team@android.com
Cc: linux-kselftest@vger.kernel.org
Fixes: 6d029c25b71f ("selftests/timers/posix_timers: Reimplement check_timer_distribution()")
Signed-off-by: John Stultz <jstultz@google.com>
---
 tools/testing/selftests/timers/posix_timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index d86a0e00711e..348f47176e0a 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -247,7 +247,7 @@ static int check_timer_distribution(void)
 		ksft_test_result_skip("check signal distribution (old kernel)\n");
 	return 0;
 err:
-	ksft_print_msg(errmsg);
+	ksft_print_msg("%s", errmsg);
 	return -1;
 }
 
-- 
2.44.0.478.gd926399ef9-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version
  2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
@ 2024-04-10 23:26 ` John Stultz
  2024-04-11 15:39   ` Nathan Chancellor
  2024-04-10 23:26 ` [PATCH 3/3] selftests: timers: Fix abs() warning in posix_timers test John Stultz
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: John Stultz @ 2024-04-10 23:26 UTC (permalink / raw)
  To: LKML
  Cc: John Stultz, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Oleg Nesterov,
	Andrew Morton, Edward Liaw, Carlos Llamas, kernel-team,
	linux-kselftest

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.

But to make clang happpy, lets initialize the major/minor values
to zero.

Cc: Shuah Khan <shuah@kernel.org>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Edward Liaw <edliaw@google.com>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: kernel-team@android.com
Cc: linux-kselftest@vger.kernel.org
Fixes: 6d029c25b71f ("selftests/timers/posix_timers: Reimplement check_timer_distribution()")
Signed-off-by: John Stultz <jstultz@google.com>
---
 tools/testing/selftests/kselftest.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 973b18e156b2..12e2f3ab8b13 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -392,7 +392,7 @@ static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...)
 static inline int ksft_min_kernel_version(unsigned int min_major,
 					  unsigned int min_minor)
 {
-	unsigned int major, minor;
+	unsigned int major = 0, minor = 0;
 	struct utsname info;
 
 	if (uname(&info) || sscanf(info.release, "%u.%u.", &major, &minor) != 2)
-- 
2.44.0.478.gd926399ef9-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/3] selftests: timers: Fix abs() warning in posix_timers test
  2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
  2024-04-10 23:26 ` [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version John Stultz
@ 2024-04-10 23:26 ` John Stultz
  2024-04-12 12:15   ` [tip: timers/urgent] " tip-bot2 for John Stultz
  2024-04-10 23:28 ` [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning Justin Stitt
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: John Stultz @ 2024-04-10 23:26 UTC (permalink / raw)
  To: LKML
  Cc: John Stultz, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Oleg Nesterov,
	Andrew Morton, Edward Liaw, Carlos Llamas, kernel-team,
	linux-kselftest

Building with clang, I'm seeing:
posix_timers.c:69:6: warning: absolute value function 'abs' given an
argument of type 'long long' but has parameter of type 'int' which may
cause truncation of value [-Wabsolute-value]
        if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
            ^

So switch to using llabs() instead.

Cc: Shuah Khan <shuah@kernel.org>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Edward Liaw <edliaw@google.com>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: kernel-team@android.com
Cc: linux-kselftest@vger.kernel.org
Fixes: 0bc4b0cf1570 ("selftests: add basic posix timers selftests")
Signed-off-by: John Stultz <jstultz@google.com>
---
 tools/testing/selftests/timers/posix_timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 348f47176e0a..c001dd79179d 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -66,7 +66,7 @@ static int check_diff(struct timeval start, struct timeval end)
 	diff = end.tv_usec - start.tv_usec;
 	diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC;
 
-	if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
+	if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
 		printf("Diff too high: %lld..", diff);
 		return -1;
 	}
-- 
2.44.0.478.gd926399ef9-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning
  2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
  2024-04-10 23:26 ` [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version John Stultz
  2024-04-10 23:26 ` [PATCH 3/3] selftests: timers: Fix abs() warning in posix_timers test John Stultz
@ 2024-04-10 23:28 ` Justin Stitt
  2024-04-11  9:38 ` Oleg Nesterov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Justin Stitt @ 2024-04-10 23:28 UTC (permalink / raw)
  To: John Stultz
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Oleg Nesterov, Andrew Morton,
	Edward Liaw, Carlos Llamas, kernel-team, linux-kselftest

On Wed, Apr 10, 2024 at 4:26 PM John Stultz <jstultz@google.com> wrote:
>
> After commit 6d029c25b71f ("selftests/timers/posix_timers:
> Reimplement check_timer_distribution()") I started seeing the
> following warning building with an older gcc:
>
> posix_timers.c:250:2: warning: format not a string literal and no format arguments [-Wformat-security]
>   250 |  ksft_print_msg(errmsg);
>       |  ^~~~~~~~~~~~~~
>
> Fix this up by changing it to ksft_print_msg("%s", errmsg)
>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
> Cc: Frederic Weisbecker <frederic@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Bill Wendling <morbo@google.com>
> Cc: Justin Stitt <justinstitt@google.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Edward Liaw <edliaw@google.com>
> Cc: Carlos Llamas <cmllamas@google.com>
> Cc: kernel-team@android.com
> Cc: linux-kselftest@vger.kernel.org
> Fixes: 6d029c25b71f ("selftests/timers/posix_timers: Reimplement check_timer_distribution()")
> Signed-off-by: John Stultz <jstultz@google.com>

Yep, makes sense.

Acked-by: Justin Stitt <justinstitt@google.com>

> ---
>  tools/testing/selftests/timers/posix_timers.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
> index d86a0e00711e..348f47176e0a 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -247,7 +247,7 @@ static int check_timer_distribution(void)
>                 ksft_test_result_skip("check signal distribution (old kernel)\n");
>         return 0;
>  err:
> -       ksft_print_msg(errmsg);
> +       ksft_print_msg("%s", errmsg);
>         return -1;
>  }
>
> --
> 2.44.0.478.gd926399ef9-goog
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning
  2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
                   ` (2 preceding siblings ...)
  2024-04-10 23:28 ` [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning Justin Stitt
@ 2024-04-11  9:38 ` Oleg Nesterov
  2024-04-11 20:45 ` Shuah Khan
  2024-04-12 12:15 ` [tip: timers/urgent] selftests: timers: Fix posix_timers ksft_print_msg() warning tip-bot2 for John Stultz
  5 siblings, 0 replies; 13+ messages in thread
From: Oleg Nesterov @ 2024-04-11  9:38 UTC (permalink / raw)
  To: John Stultz
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Andrew Morton,
	Edward Liaw, Carlos Llamas, kernel-team, linux-kselftest

On 04/10, John Stultz wrote:
>
> After commit 6d029c25b71f ("selftests/timers/posix_timers:
> Reimplement check_timer_distribution()") I started seeing the
> following warning building with an older gcc:
>
> posix_timers.c:250:2: warning: format not a string literal and no format arguments [-Wformat-security]
>   250 |  ksft_print_msg(errmsg);
>       |  ^~~~~~~~~~~~~~

...

> -	ksft_print_msg(errmsg);
> +	ksft_print_msg("%s", errmsg);
>  	return -1;

Thanks,

Oleg.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version
  2024-04-10 23:26 ` [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version John Stultz
@ 2024-04-11 15:39   ` Nathan Chancellor
  2024-04-11 18:11     ` John Stultz
  0 siblings, 1 reply; 13+ messages in thread
From: Nathan Chancellor @ 2024-04-11 15:39 UTC (permalink / raw)
  To: John Stultz
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Oleg Nesterov, Andrew Morton, Edward Liaw,
	Carlos Llamas, kernel-team, linux-kselftest

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.

diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 050c5fd01840..29364c9f3332 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -83,6 +83,7 @@
 #define KSFT_XPASS 3
 #define KSFT_SKIP  4
 
+#define __noreturn       __attribute__((__noreturn__))
 #define __printf(a, b)   __attribute__((format(printf, a, b)))
 
 /* counters */
@@ -324,13 +325,13 @@ void ksft_test_result_code(int exit_code, const char *test_name,
 		break;						\
 	} } while (0)
 
-static inline int ksft_exit_pass(void)
+static inline __noreturn int ksft_exit_pass(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_PASS);
 }
 
-static inline int ksft_exit_fail(void)
+static inline __noreturn int ksft_exit_fail(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_FAIL);
@@ -357,7 +358,7 @@ static inline int ksft_exit_fail(void)
 		  ksft_cnt.ksft_xfail +	\
 		  ksft_cnt.ksft_xskip)
 
-static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
+static inline __noreturn __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
 {
 	int saved_errno = errno;
 	va_list args;
@@ -372,7 +373,7 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
 	exit(KSFT_FAIL);
 }
 
-static inline void ksft_exit_fail_perror(const char *msg)
+static inline __noreturn void ksft_exit_fail_perror(const char *msg)
 {
 #ifndef NOLIBC
 	ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
@@ -385,19 +386,19 @@ static inline void ksft_exit_fail_perror(const char *msg)
 #endif
 }
 
-static inline int ksft_exit_xfail(void)
+static inline __noreturn int ksft_exit_xfail(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_XFAIL);
 }
 
-static inline int ksft_exit_xpass(void)
+static inline __noreturn int ksft_exit_xpass(void)
 {
 	ksft_print_cnts();
 	exit(KSFT_XPASS);
 }
 
-static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...)
+static inline __noreturn __printf(1, 2) int ksft_exit_skip(const char *msg, ...)
 {
 	int saved_errno = errno;
 	va_list args;

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version
  2024-04-11 15:39   ` Nathan Chancellor
@ 2024-04-11 18:11     ` John Stultz
  2024-04-11 18:47       ` Nathan Chancellor
  0 siblings, 1 reply; 13+ messages in thread
From: John Stultz @ 2024-04-11 18:11 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Oleg Nesterov, Andrew Morton, Edward Liaw,
	Carlos Llamas, kernel-team, linux-kselftest

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version
  2024-04-11 18:11     ` John Stultz
@ 2024-04-11 18:47       ` Nathan Chancellor
  0 siblings, 0 replies; 13+ messages in thread
From: Nathan Chancellor @ 2024-04-11 18:47 UTC (permalink / raw)
  To: John Stultz
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Oleg Nesterov, Andrew Morton, Edward Liaw,
	Carlos Llamas, kernel-team, linux-kselftest

On Thu, Apr 11, 2024 at 11:11:59AM -0700, John Stultz wrote:
> 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?

Done: https://lore.kernel.org/20240411-mark-kselftest-exit-funcs-noreturn-v1-1-b027c948f586@kernel.org/

If you have to respin this series for some reason, feel free to include
that change so that they go together, up to you though.

Cheers,
nathan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning
  2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
                   ` (3 preceding siblings ...)
  2024-04-11  9:38 ` Oleg Nesterov
@ 2024-04-11 20:45 ` Shuah Khan
  2024-04-11 20:53   ` John Stultz
  2024-04-12 12:15 ` [tip: timers/urgent] selftests: timers: Fix posix_timers ksft_print_msg() warning tip-bot2 for John Stultz
  5 siblings, 1 reply; 13+ messages in thread
From: Shuah Khan @ 2024-04-11 20:45 UTC (permalink / raw)
  To: John Stultz, LKML
  Cc: Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Oleg Nesterov,
	Andrew Morton, Edward Liaw, Carlos Llamas, kernel-team,
	linux-kselftest, Shuah Khan

On 4/10/24 17:26, John Stultz wrote:
> After commit 6d029c25b71f ("selftests/timers/posix_timers:

Tried to apply this for linux-kselftest next with Nathan's patch.
I can't find this commit in Linux 6.9-rc3? Is this is timers
tree?

> Reimplement check_timer_distribution()") I started seeing the
> following warning building with an older gcc:
> 
> posix_timers.c:250:2: warning: format not a string literal and no format arguments [-Wformat-security]
>    250 |  ksft_print_msg(errmsg);
>        |  ^~~~~~~~~~~~~~
> 
> Fix this up by changing it to ksft_print_msg("%s", errmsg)
> 
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
> Cc: Frederic Weisbecker <frederic@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Bill Wendling <morbo@google.com>
> Cc: Justin Stitt <justinstitt@google.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Edward Liaw <edliaw@google.com>
> Cc: Carlos Llamas <cmllamas@google.com>
> Cc: kernel-team@android.com
> Cc: linux-kselftest@vger.kernel.org
> Fixes: 6d029c25b71f ("selftests/timers/posix_timers: Reimplement check_timer_distribution()")
> Signed-off-by: John Stultz <jstultz@google.com>
> ---
>   tools/testing/selftests/timers/posix_timers.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
> index d86a0e00711e..348f47176e0a 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -247,7 +247,7 @@ static int check_timer_distribution(void)
>   		ksft_test_result_skip("check signal distribution (old kernel)\n");
>   	return 0;
>   err:
> -	ksft_print_msg(errmsg);
> +	ksft_print_msg("%s", errmsg);
>   	return -1;
>   }
>  

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning
  2024-04-11 20:45 ` Shuah Khan
@ 2024-04-11 20:53   ` John Stultz
  2024-04-11 21:12     ` Shuah Khan
  0 siblings, 1 reply; 13+ messages in thread
From: John Stultz @ 2024-04-11 20:53 UTC (permalink / raw)
  To: Shuah Khan
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Oleg Nesterov,
	Andrew Morton, Edward Liaw, Carlos Llamas, kernel-team,
	linux-kselftest

On Thu, Apr 11, 2024 at 1:45 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>
> On 4/10/24 17:26, John Stultz wrote:
> > After commit 6d029c25b71f ("selftests/timers/posix_timers:
>
> Tried to apply this for linux-kselftest next with Nathan's patch.
> I can't find this commit in Linux 6.9-rc3? Is this is timers
> tree?

Yes, it in tip/timers/urgent.

thanks
-john

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning
  2024-04-11 20:53   ` John Stultz
@ 2024-04-11 21:12     ` Shuah Khan
  0 siblings, 0 replies; 13+ messages in thread
From: Shuah Khan @ 2024-04-11 21:12 UTC (permalink / raw)
  To: John Stultz
  Cc: LKML, Shuah Khan, Anna-Maria Behnsen, Frederic Weisbecker,
	Thomas Gleixner, Stephen Boyd, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Oleg Nesterov,
	Andrew Morton, Edward Liaw, Carlos Llamas, kernel-team,
	linux-kselftest, Shuah Khan

On 4/11/24 14:53, John Stultz wrote:
> On Thu, Apr 11, 2024 at 1:45 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>>
>> On 4/10/24 17:26, John Stultz wrote:
>>> After commit 6d029c25b71f ("selftests/timers/posix_timers:
>>
>> Tried to apply this for linux-kselftest next with Nathan's patch.
>> I can't find this commit in Linux 6.9-rc3? Is this is timers
>> tree?
> 
> Yes, it in tip/timers/urgent.
> 


Thank you. Assuming this is going through tip/timers/urgent

Acked-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tip: timers/urgent] selftests: timers: Fix abs() warning in posix_timers test
  2024-04-10 23:26 ` [PATCH 3/3] selftests: timers: Fix abs() warning in posix_timers test John Stultz
@ 2024-04-12 12:15   ` tip-bot2 for John Stultz
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot2 for John Stultz @ 2024-04-12 12:15 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: John Stultz, Thomas Gleixner, stable, x86, linux-kernel

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     ed366de8ec89d4f960d66c85fc37d9de22f7bf6d
Gitweb:        https://git.kernel.org/tip/ed366de8ec89d4f960d66c85fc37d9de22f7bf6d
Author:        John Stultz <jstultz@google.com>
AuthorDate:    Wed, 10 Apr 2024 16:26:30 -07:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 12 Apr 2024 14:11:15 +02:00

selftests: timers: Fix abs() warning in posix_timers test

Building with clang results in the following warning:

  posix_timers.c:69:6: warning: absolute value function 'abs' given an
      argument of type 'long long' but has parameter of type 'int' which may
      cause truncation of value [-Wabsolute-value]
        if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
            ^
So switch to using llabs() instead.

Fixes: 0bc4b0cf1570 ("selftests: add basic posix timers selftests")
Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240410232637.4135564-3-jstultz@google.com

---
 tools/testing/selftests/timers/posix_timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 348f471..c001dd7 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -66,7 +66,7 @@ static int check_diff(struct timeval start, struct timeval end)
 	diff = end.tv_usec - start.tv_usec;
 	diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC;
 
-	if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
+	if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
 		printf("Diff too high: %lld..", diff);
 		return -1;
 	}

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip: timers/urgent] selftests: timers: Fix posix_timers ksft_print_msg() warning
  2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
                   ` (4 preceding siblings ...)
  2024-04-11 20:45 ` Shuah Khan
@ 2024-04-12 12:15 ` tip-bot2 for John Stultz
  5 siblings, 0 replies; 13+ messages in thread
From: tip-bot2 for John Stultz @ 2024-04-12 12:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: John Stultz, Thomas Gleixner, Justin Stitt, Shuah Khan, stable,
	x86, linux-kernel

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     e4a6bceac98eba3c00e874892736b34ea5fdaca3
Gitweb:        https://git.kernel.org/tip/e4a6bceac98eba3c00e874892736b34ea5fdaca3
Author:        John Stultz <jstultz@google.com>
AuthorDate:    Wed, 10 Apr 2024 16:26:28 -07:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 12 Apr 2024 14:11:15 +02:00

selftests: timers: Fix posix_timers ksft_print_msg() warning

After commit 6d029c25b71f ("selftests/timers/posix_timers: Reimplement
check_timer_distribution()") the following warning occurs when building
with an older gcc:

posix_timers.c:250:2: warning: format not a string literal and no format arguments [-Wformat-security]
  250 |  ksft_print_msg(errmsg);
      |  ^~~~~~~~~~~~~~

Fix this up by changing it to ksft_print_msg("%s", errmsg)

Fixes: 6d029c25b71f ("selftests/timers/posix_timers: Reimplement check_timer_distribution()")
Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Justin Stitt <justinstitt@google.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240410232637.4135564-1-jstultz@google.com
---
 tools/testing/selftests/timers/posix_timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index d86a0e0..348f471 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -247,7 +247,7 @@ static int check_timer_distribution(void)
 		ksft_test_result_skip("check signal distribution (old kernel)\n");
 	return 0;
 err:
-	ksft_print_msg(errmsg);
+	ksft_print_msg("%s", errmsg);
 	return -1;
 }
 

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-04-12 12:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-10 23:26 [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning John Stultz
2024-04-10 23:26 ` [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version John Stultz
2024-04-11 15:39   ` Nathan Chancellor
2024-04-11 18:11     ` John Stultz
2024-04-11 18:47       ` Nathan Chancellor
2024-04-10 23:26 ` [PATCH 3/3] selftests: timers: Fix abs() warning in posix_timers test John Stultz
2024-04-12 12:15   ` [tip: timers/urgent] " tip-bot2 for John Stultz
2024-04-10 23:28 ` [PATCH 1/3] selftests: timers: Fix posix_timers ksft_print_msg warning Justin Stitt
2024-04-11  9:38 ` Oleg Nesterov
2024-04-11 20:45 ` Shuah Khan
2024-04-11 20:53   ` John Stultz
2024-04-11 21:12     ` Shuah Khan
2024-04-12 12:15 ` [tip: timers/urgent] selftests: timers: Fix posix_timers ksft_print_msg() warning tip-bot2 for John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox