[PATCH next] kunit: Initialize filter error before disabled cleanup

Karl Mehltretter posted 1 patch 1 week, 4 days ago
lib/kunit/executor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH next] kunit: Initialize filter error before disabled cleanup
Posted by Karl Mehltretter 1 week, 4 days ago
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
Re: [PATCH next] kunit: Initialize filter error before disabled cleanup
Posted by Thomas Weißschuh 2 hours ago
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(-)

(...)