[PATCH] kunit: debugfs: Handle errors from alloc_string_stream()

2023-09-27 Thread Richard Fitzgerald
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: Richa

Re: [PATCH] kunit: debugfs: Handle errors from alloc_string_stream()

2023-09-28 Thread Richard Fitzgerald
On 27/09/2023 17:50, Richard Fitzgerald wrote: 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

[PATCH v2] kunit: debugfs: Handle errors from alloc_string_stream()

2023-09-28 Thread Richard Fitzgerald
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: Richa

[PATCH] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()

2023-09-28 Thread Richard Fitzgerald
NULL pointers so that client cleanup code can call string_stream_destroy() unconditionally - which could include pointers that have never been set to anything and so are NULL. Signed-off-by: Richard Fitzgerald --- lib/kunit/string-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

[PATCH] kunit: debugfs: Fix unchecked dereference in debugfs_print_results()

2023-09-28 Thread Richard Fitzgerald
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 Report

[PATCH v2 RESEND] kunit: debugfs: Handle errors from alloc_string_stream()

2023-10-30 Thread Richard Fitzgerald
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: Richa

[PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()

2023-10-30 Thread Richard Fitzgerald
NULL pointers so that client cleanup code can call string_stream_destroy() unconditionally - which could include pointers that have never been set to anything and so are NULL. Signed-off-by: Richard Fitzgerald --- lib/kunit/string-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

[PATCH RESEND] kunit: debugfs: Fix unchecked dereference in debugfs_print_results()

2023-10-30 Thread Richard Fitzgerald
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 Report

[PATCH] kunit: test: Avoid cast warning in when adding kfree() as an action

2023-11-06 Thread Richard Fitzgerald
x27;) converts to incompatible function type [-Wcast-function-type-strict] 564 full_log = string_stream_get_string(test->log); > 565 kunit_add_action(test, (kunit_action_t *)kfree, full_log); Signed-off-by: Richard Fitzgerald Reported-by: kernel test robot Closes: h

Re: [PATCH] kunit: test: Avoid cast warning in when adding kfree() as an action

2023-11-06 Thread Richard Fitzgerald
On 6/11/23 17:23, Richard Fitzgerald wrote: In kunit_log_test() pass the kfree_wrapper() function to kunit_add_action() instead of directly passing kfree(). Aargh! Sorry, noticed spurious word in commit title. Will send a V2.

[PATCH v2] kunit: test: Avoid cast warning when adding kfree() as an action

2023-11-06 Thread Richard Fitzgerald
x27;) converts to incompatible function type [-Wcast-function-type-strict] 564 full_log = string_stream_get_string(test->log); > 565 kunit_add_action(test, (kunit_action_t *)kfree, full_log); Signed-off-by: Richard Fitzgerald Reported-by: kernel test robot Closes: h

[PATCH] kunit: string-stream-test: Avoid cast warning when testing gfp_t flags

2023-11-21 Thread Richard Fitzgerald
lue and passing the boolean result of this comparison to KUNIT_EXPECT_TRUE(), as was already done a few lines above in string_stream_managed_init_test(). Signed-off-by: Richard Fitzgerald Fixes: d1a0d699bfc0 ("kunit: string-stream: Add tests for freeing resource-managed string_stream"

Re: [PATCH v2] kunit: run test suites only after module initialization completes

2023-12-06 Thread Richard Fitzgerald
kunit: Fix wild-memory-access bug in kunit_free_suite_set()") Signed-off-by: Marco Pagani Tested-by: Richard Fitzgerald Fixed this crash: https://lore.kernel.org/all/e239b94b-462a-41e5-9a4c-cd1ffd530...@opensource.cirrus.com/ Also tested with sound/pci/hda/cirrus_scodec_test.c

[PATCH] kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL

2023-12-18 Thread Richard Fitzgerald
suite->log must be checked for NULL before passing it to string_stream_clear(). This was done in kunit_init_test() but was missing from kunit_init_suite(). Signed-off-by: Richard Fitzgerald Fixes: 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs") --- lib/kun

[PATCH 1/2] kunit: Allow passing function pointer to kunit_activate_static_stub()

2023-12-18 Thread Richard Fitzgerald
nd in the second case the RHS is already a pointer to the same type. Signed-off-by: Richard Fitzgerald --- include/kunit/static_stub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/kunit/static_stub.h b/include/kunit/static_stub.h index 85315c80b303..bf94032

[PATCH 2/2] kunit: Add example of kunit_activate_static_stub() with pointer-to-function

2023-12-18 Thread Richard Fitzgerald
add_one directly. Signed-off-by: Richard Fitzgerald --- lib/kunit/kunit-example-test.c | 27 +++ 1 file changed, 27 insertions(+) diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index d2f7a3c62c18..9e57f341dc37 100644 --- a/lib/kunit/kunit

Re: [PATCH v3] kunit: run test suites only after module initialization completes

2023-12-20 Thread Richard Fitzgerald
ecked v2: - add include Fixes: 2810c1e99867 ("kunit: Fix wild-memory-access bug in kunit_free_suite_set()") Tested-by: Richard Fitzgerald Reviewed-by: Javier Martinez Canillas Signed-off-by: Marco Pagani --- For V3: Tested-by: Richard Fitzgerald Fixes this crash: https://lore.kernel.

[PATCH] kunit: Protect string comparisons against NULL

2023-12-20 Thread Richard Fitzgerald
terminate the test at that point. It's preferable that the KUNIT_EXPECT_STR*() macros can handle NULL pointers as a failure. Signed-off-by: Richard Fitzgerald --- include/kunit/test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h

[PATCH v2 2/2] kunit: Add example of kunit_activate_static_stub() with pointer-to-function

2023-12-21 Thread Richard Fitzgerald
add_one directly. Signed-off-by: Richard Fitzgerald --- V2: Added comment for add_one_fn_ptr. --- lib/kunit/kunit-example-test.c | 35 ++ 1 file changed, 35 insertions(+) diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index

[PATCH v2 1/2] kunit: Allow passing function pointer to kunit_activate_static_stub()

2023-12-21 Thread Richard Fitzgerald
nd in the second case the RHS is already a pointer to the same type. Signed-off-by: Richard Fitzgerald Reviewed-by: Rae Moar --- No changes since V1. --- include/kunit/static_stub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/kunit/static_stub.h b/include/kunit/

Re: [PATCH] kunit: Protect string comparisons against NULL

2024-01-04 Thread Richard Fitzgerald
On 22/12/23 08:39, David Gow wrote: On Wed, 20 Dec 2023 at 23:52, Richard Fitzgerald wrote: Add NULL checks to KUNIT_BINARY_STR_ASSERTION() so that it will fail cleanly if either pointer is NULL, instead of causing a NULL pointer dereference in the strcmp(). A test failure could be that a

Re: Regression on drm-tip

2024-01-31 Thread Richard Fitzgerald
issue and have found the following commit to be the first bad commit. ` commit a0b84213f947176ddcd0e96e0751a109f28cde21 Author: Richard Fitzgerald r...@opensource.cirrus.com Date: Mon Dec 18 15