[bug report] kunit: Use string_stream for test log

3 views
Skip to first unread message

Dan Carpenter

unread,
Sep 27, 2023, 8:37:45 AM9/27/23
to r...@opensource.cirrus.com, kuni...@googlegroups.com
Hello Richard Fitzgerald,

The patch 05e2006ce493: "kunit: Use string_stream for test log" from
Aug 28, 2023 (linux-next), leads to the following Smatch static
checker warning:

lib/kunit/debugfs.c:66 debugfs_print_results() warn: variable dereferenced before check 'suite' (see line 63)
lib/kunit/debugfs.c:115 kunit_debugfs_create_suite() error: 'suite->log' dereferencing possible ERR_PTR()
lib/kunit/debugfs.c:119 kunit_debugfs_create_suite() error: 'test_case->log' dereferencing possible ERR_PTR()

lib/kunit/debugfs.c
109 void kunit_debugfs_create_suite(struct kunit_suite *suite)
110 {
111 struct kunit_case *test_case;
112
113 /* Allocate logs before creating debugfs representation. */
114 suite->log = alloc_string_stream(GFP_KERNEL);

This allocation can't really fail in real life, but we always treat them
as if they can. You could add a GFP_NOFAIL if you don't want to check
for errors.

--> 115 string_stream_set_append_newlines(suite->log, true);
116
117 kunit_suite_for_each_test_case(suite, test_case) {
118 test_case->log = alloc_string_stream(GFP_KERNEL);
119 string_stream_set_append_newlines(test_case->log, true);
120 }
121
122 suite->debugfs = debugfs_create_dir(suite->name, debugfs_rootdir);
123
124 debugfs_create_file(KUNIT_DEBUGFS_RESULTS, S_IFREG | 0444,
125 suite->debugfs,
126 suite, &debugfs_results_fops);
127 }

regards,
dan carpenter
Reply all
Reply to author
Forward
0 new messages