mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kunit: Return void from kunit_run_all_tests()
@ 2026-09-01  9:50 Thomas Weißschuh
  2026-09-02 13:29 ` David Gow
  2026-09-14  2:59 ` [PATCH next] kunit: Initialize filter error before disabled cleanup Karl Mehltretter
  0 siblings, 2 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2026-09-01  9:50 UTC (permalink / raw)
  To: Brendan Higgins, David Gow, Rae Moar
  Cc: linux-kselftest, kunit-dev, linux-kernel, Thomas Weißschuh

No caller tests the return value of this function.

The integer return type is still a remnant from when the function
was executed as initcall. This usage however was removed in
commit 8c0d884986ba ("init: main: add KUnit to kernel init")

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 include/kunit/test.h | 5 ++---
 lib/kunit/executor.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index da5312e0dfa5..31d549578f8e 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -400,11 +400,10 @@ struct kunit_suite_set kunit_merge_suite_sets(struct kunit_suite_set init_suite_
 const void *kunit_array_gen_params(struct kunit *test, const void *prev, char *desc);
 
 #if IS_BUILTIN(CONFIG_KUNIT)
-int kunit_run_all_tests(void);
+void kunit_run_all_tests(void);
 #else
-static inline int kunit_run_all_tests(void)
+static inline void kunit_run_all_tests(void)
 {
-	return 0;
 }
 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
 
diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index b0f8a41d61d3..c798a02470d8 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -371,7 +371,7 @@ static void kunit_handle_shutdown(void)
 
 }
 
-int kunit_run_all_tests(void)
+void kunit_run_all_tests(void)
 {
 	struct kunit_suite_set suite_set = {NULL, NULL};
 	struct kunit_suite_set filtered_suite_set = {NULL, NULL};
@@ -382,7 +382,7 @@ int kunit_run_all_tests(void)
 		__kunit_suites_start, __kunit_suites_end,
 	};
 	size_t init_num_suites = init_suite_set.end - init_suite_set.start;
-	int err = 0;
+	int err;
 
 	if (init_num_suites > 0) {
 		suite_set = kunit_merge_suite_sets(init_suite_set, normal_suite_set);
@@ -432,7 +432,6 @@ int kunit_run_all_tests(void)
 
 out:
 	kunit_handle_shutdown();
-	return err;
 }
 
 #if IS_BUILTIN(CONFIG_KUNIT_TEST)

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260109-kunit-void-b2f71f7e980c

Best regards,
--  
Thomas Weißschuh <thomas.weissschuh@linutronix.de>


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

* Re: [PATCH] kunit: Return void from kunit_run_all_tests()
  2026-09-01  9:50 [PATCH] kunit: Return void from kunit_run_all_tests() Thomas Weißschuh
@ 2026-09-02 13:29 ` David Gow
  2026-09-14  2:59 ` [PATCH next] kunit: Initialize filter error before disabled cleanup Karl Mehltretter
  1 sibling, 0 replies; 4+ messages in thread
From: David Gow @ 2026-09-02 13:29 UTC (permalink / raw)
  To: Thomas Weißschuh, Brendan Higgins, Rae Moar
  Cc: linux-kselftest, kunit-dev, linux-kernel

Le 01/09/2026 à 17:50, Thomas Weißschuh a écrit :
> No caller tests the return value of this function.
> 
> The integer return type is still a remnant from when the function
> was executed as initcall. This usage however was removed in
> commit 8c0d884986ba ("init: main: add KUnit to kernel init")
> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---

Nice catch, thanks.

Reviewed-by: David Gow <david@davidgow.net>

Cheers,
-- David

>   include/kunit/test.h | 5 ++---
>   lib/kunit/executor.c | 5 ++---
>   2 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index da5312e0dfa5..31d549578f8e 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -400,11 +400,10 @@ struct kunit_suite_set kunit_merge_suite_sets(struct kunit_suite_set init_suite_
>   const void *kunit_array_gen_params(struct kunit *test, const void *prev, char *desc);
>   
>   #if IS_BUILTIN(CONFIG_KUNIT)
> -int kunit_run_all_tests(void);
> +void kunit_run_all_tests(void);
>   #else
> -static inline int kunit_run_all_tests(void)
> +static inline void kunit_run_all_tests(void)
>   {
> -	return 0;
>   }
>   #endif /* IS_BUILTIN(CONFIG_KUNIT) */
>   
> diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
> index b0f8a41d61d3..c798a02470d8 100644
> --- a/lib/kunit/executor.c
> +++ b/lib/kunit/executor.c
> @@ -371,7 +371,7 @@ static void kunit_handle_shutdown(void)
>   
>   }
>   
> -int kunit_run_all_tests(void)
> +void kunit_run_all_tests(void)
>   {
>   	struct kunit_suite_set suite_set = {NULL, NULL};
>   	struct kunit_suite_set filtered_suite_set = {NULL, NULL};
> @@ -382,7 +382,7 @@ int kunit_run_all_tests(void)
>   		__kunit_suites_start, __kunit_suites_end,
>   	};
>   	size_t init_num_suites = init_suite_set.end - init_suite_set.start;
> -	int err = 0;
> +	int err;
>   
>   	if (init_num_suites > 0) {
>   		suite_set = kunit_merge_suite_sets(init_suite_set, normal_suite_set);
> @@ -432,7 +432,6 @@ int kunit_run_all_tests(void)
>   
>   out:
>   	kunit_handle_shutdown();
> -	return err;
>   }
>   
>   #if IS_BUILTIN(CONFIG_KUNIT_TEST)
> 
> ---
> base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
> change-id: 20260109-kunit-void-b2f71f7e980c
> 
> Best regards,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 


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

* [PATCH next] kunit: Initialize filter error before disabled cleanup
  2026-09-01  9:50 [PATCH] kunit: Return void from kunit_run_all_tests() Thomas Weißschuh
  2026-09-02 13:29 ` David Gow
@ 2026-09-14  2:59 ` Karl Mehltretter
  2026-09-25  7:43   ` Thomas Weißschuh
  1 sibling, 1 reply; 4+ messages in thread
From: Karl Mehltretter @ 2026-09-14  2:59 UTC (permalink / raw)
  To: Brendan Higgins, David Gow, Rae Moar
  Cc: Karl Mehltretter, Thomas Weißschuh, Shuah Khan,
	linux-kselftest, kunit-dev, linux-kernel

kunit_run_all_tests() jumps to free_out when KUnit execution is disabled.
If a boot filter is configured, free_out tests err even though
kunit_filter_suites() was never called to initialize it.

Clang's -Wconditional-uninitialized diagnoses this path. KMSAN confirms
the runtime use.

With CONFIG_KUNIT_DEFAULT_ENABLED=n,
CONFIG_KUNIT_DEFAULT_FILTER_GLOB="*", CONFIG_INIT_STACK_NONE=y and
CONFIG_KMSAN=y, KMSAN reports an uninitialized-value use in
kunit_run_all_tests() and identifies local variable err as its origin.

Restore the zero initializer. It remains necessary as cleanup state after
kunit_run_all_tests() was changed to return void.

Fixes: e38f53f04824 ("kunit: Return void from kunit_run_all_tests()")
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
 lib/kunit/executor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index c798a02470d8..6e4664ad82ad 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -382,7 +382,7 @@ void kunit_run_all_tests(void)
 		__kunit_suites_start, __kunit_suites_end,
 	};
 	size_t init_num_suites = init_suite_set.end - init_suite_set.start;
-	int err;
+	int err = 0;
 
 	if (init_num_suites > 0) {
 		suite_set = kunit_merge_suite_sets(init_suite_set, normal_suite_set);

base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
-- 
2.53.0

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

* Re: [PATCH next] kunit: Initialize filter error before disabled cleanup
  2026-09-14  2:59 ` [PATCH next] kunit: Initialize filter error before disabled cleanup Karl Mehltretter
@ 2026-09-25  7:43   ` Thomas Weißschuh
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2026-09-25  7:43 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Brendan Higgins, David Gow, Rae Moar, Shuah Khan,
	linux-kselftest, kunit-dev, linux-kernel

On Mon, Sep 14, 2026 at 04:59:33AM +0200, Karl Mehltretter wrote:
> kunit_run_all_tests() jumps to free_out when KUnit execution is disabled.
> If a boot filter is configured, free_out tests err even though
> kunit_filter_suites() was never called to initialize it.
> 
> Clang's -Wconditional-uninitialized diagnoses this path. KMSAN confirms
> the runtime use.
> 
> With CONFIG_KUNIT_DEFAULT_ENABLED=n,
> CONFIG_KUNIT_DEFAULT_FILTER_GLOB="*", CONFIG_INIT_STACK_NONE=y and
> CONFIG_KMSAN=y, KMSAN reports an uninitialized-value use in
> kunit_run_all_tests() and identifies local variable err as its origin.
> 
> Restore the zero initializer. It remains necessary as cleanup state after
> kunit_run_all_tests() was changed to return void.
> 
> Fixes: e38f53f04824 ("kunit: Return void from kunit_run_all_tests()")
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>

Thanks!

Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

The code using the variable was not yet there when I wrote the patch.
Also this logic could really use some cleanup...

> ---
>  lib/kunit/executor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

(...)

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

end of thread, other threads:[~2026-09-25  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-01  9:50 [PATCH] kunit: Return void from kunit_run_all_tests() Thomas Weißschuh
2026-09-02 13:29 ` David Gow
2026-09-14  2:59 ` [PATCH next] kunit: Initialize filter error before disabled cleanup Karl Mehltretter
2026-09-25  7:43   ` Thomas Weißschuh

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

all inboxes | Powered by JetHome®