kunit: Return void from kunit_run_all_tests()
PATCH 1/1 kunit: Return void from kunit_run_all_tests()
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")
--- include/kunit/test.h | 5 ++--- lib/kunit/executor.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
include/kunit/test.h +2 -3
@@ -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) */
lib/kunit/executor.c +2 -3
@@ -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,
Signature · 1 line
Thomas Weißschuh <[email protected]>
Le 01/09/2026 à 17:50, Thomas Weißschuh a écrit :
Quoted 8 lines
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 <[email protected]>---
Nice catch, thanks.
Cheers,
-- David
Quoted 61 lines
include/kunit/test.h | 5 ++--- lib/kunit/executor.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)include/kunit/test.h +2
-3@@ -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) */ lib/kunit/executor.c +2
-4@@ -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-b2f71f7e980cBest regards,
--
Thomas Weißschuh <[email protected]>
PATCH 1/1 kunit: Initialize filter error before disabled cleanup
In reply to Thomas Weißschuhkunit_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.
--- lib/kunit/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/executor.c +1 -1
@@ -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
Signature · 1 line
2.53.0
Re: [PATCH next] kunit: Initialize filter error before disabled cleanup
Quoted 12 lines · Karl Mehltretter
kunit_run_all_tests()jumps tofree_outwhen KUnit execution is disabled. If a boot filter is configured,free_outtests err even thoughkunit_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=yandCONFIG_KMSAN=y, KMSAN reports an uninitialized-value use inkunit_run_all_tests()and identifies local variable err as its origin.
Quoted 5 lines
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 <[email protected]>
Thanks!
The code using the variable was not yet there when I wrote the patch. Also this logic could really use some cleanup...
Quoted 3 lines
--- lib/kunit/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
(...)
Re: [PATCH next] kunit: Initialize filter error before disabled cleanup
In reply to Karl MehltretterQuoted 12 lines · Karl Mehltretter
kunit_run_all_tests()jumps tofree_outwhen KUnit execution is disabled. If a boot filter is configured,free_outtests err even thoughkunit_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=yandCONFIG_KMSAN=y, KMSAN reports an uninitialized-value use inkunit_run_all_tests()and identifies local variable err as its origin.
Quoted 5 lines
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 <[email protected]>
Friendly ping on this fix. It has Thomas's Reviewed-by tag.
I don't see this fix in the KUnit tree or folded into the original change.
Thanks,
Karl