]> git.ipfire.org Git - thirdparty/kernel/linux.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)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 18 Dec 2023 20:21:14 +0000 (13:21 -0700)
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>
lib/kunit/debugfs.c

index 270d185737e67f212549eed0d36303ae53e6f939..5bfc18ad5fffdc2c45557ecce4fa08add50935f7 100644 (file)
@@ -60,12 +60,14 @@ static void debugfs_print_result(struct seq_file *seq, struct string_stream *log
 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)
                return 0;
 
+       success = kunit_suite_has_succeeded(suite);
+
        /* Print KTAP header so the debugfs log can be parsed as valid KTAP. */
        seq_puts(seq, "KTAP version 1\n");
        seq_puts(seq, "1..1\n");