Skip to content

Commit 435c20e

Browse files
Gax-cshuahkh
authored andcommitted
kunit: Fix potential null dereference in kunit_device_driver_test()
kunit_kzalloc() may return a NULL pointer, dereferencing it without NULL check may lead to NULL dereference. Add a NULL check for test_state. Link: https://lore.kernel.org/r/20241115054335.21673-1-zichenxie0106@gmail.com Fixes: d03c720 ("kunit: Add APIs for managing devices") Signed-off-by: Zichen Xie <zichenxie0106@gmail.com> Cc: stable@vger.kernel.org Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent aadf9cb commit 435c20e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/kunit/kunit-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ static void kunit_device_driver_test(struct kunit *test)
805805
struct device *test_device;
806806
struct driver_test_state *test_state = kunit_kzalloc(test, sizeof(*test_state), GFP_KERNEL);
807807

808+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_state);
809+
808810
test->priv = test_state;
809811
test_driver = kunit_driver_create(test, "my_driver");
810812

0 commit comments

Comments
 (0)