Skip to content

Commit

Permalink
kunit: debugfs: Fix unchecked dereference in debugfs_print_results()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Fixes: 38289a2 ("kunit: fix debugfs code to use enum kunit_status, not bool")
Reviewed-by: Rae Moar <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
rfvirgil authored and shuahkh committed Dec 18, 2023
1 parent 15bf000 commit 34dfd5b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/kunit/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 34dfd5b

Please sign in to comment.