kunit: debugfs: Handle errors from alloc_string_stream()
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Mon, 30 Oct 2023 10:47:32 +0000 (10:47 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 18 Dec 2023 20:21:15 +0000 (13:21 -0700)
commit1557e89d3af51a4f1bd6870b3117bed651de5dbf
tree640b51659b5b26092c1b90fcbce4e99e69103e13
parent34dfd5bb2e5507e69d9b6d6c90f546600c7a4977
kunit: debugfs: Handle errors from alloc_string_stream()

In kunit_debugfs_create_suite() give up and skip creating the debugfs
file if any of the alloc_string_stream() calls return an error or NULL.
Only put a value in the log pointer of kunit_suite and kunit_test if it
is a valid pointer to a log.

This prevents the potential invalid dereference reported by smatch:

 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()

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: 05e2006ce493 ("kunit: Use string_stream for test log")
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/debugfs.c