Skip to content

Commit

Permalink
kunit: Fix potential null dereference in kunit_device_driver_test()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Gax-c authored and shuahkh committed Nov 19, 2024
1 parent aadf9cb commit 435c20e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/kunit/kunit-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ static void kunit_device_driver_test(struct kunit *test)
struct device *test_device;
struct driver_test_state *test_state = kunit_kzalloc(test, sizeof(*test_state), GFP_KERNEL);

KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_state);

test->priv = test_state;
test_driver = kunit_driver_create(test, "my_driver");

Expand Down

0 comments on commit 435c20e

Please sign in to comment.