]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kunit: debugfs: Fix unchecked dereference in debugfs_print_results()
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Mon, 30 Oct 2023 10:47:58 +0000 (10:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 22:52:34 +0000 (14:52 -0800)
[ Upstream commit 34dfd5bb2e5507e69d9b6d6c90f546600c7a4977 ]

Move the call to kunit_suite_has_succeeded() after the check that
the kunit_suite pointer is valid.

This was found by smatch:

 lib/kunit/debugfs.c:66 debugfs_print_results() warn: variable
 dereferenced before check 'suite' (see line 63)

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: 38289a26e1b8 ("kunit: fix debugfs code to use enum kunit_status, not bool")
Reviewed-by: Rae Moar <rmoar@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
lib/kunit/debugfs.c

index 1048ef1b8d6ec09f28e48b27ea699e2742de3827..4c4b84db8f4a4a33d885cd12a896fab6f85bfe9e 100644 (file)
@@ -52,12 +52,14 @@ static void debugfs_print_result(struct seq_file *seq,
 static int debugfs_print_results(struct seq_file *seq, void *v)
 {
        struct kunit_suite *suite = (struct kunit_suite *)seq->private;
-       enum kunit_status success = kunit_suite_has_succeeded(suite);
+       enum kunit_status success;
        struct kunit_case *test_case;
 
        if (!suite || !suite->log)
                return 0;
 
+       success = kunit_suite_has_succeeded(suite);
+
        seq_printf(seq, "%s", suite->log);
 
        kunit_suite_for_each_test_case(suite, test_case)