diff options
| author | Zichen Xie <zichenxie0106@gmail.com> | 2024-11-14 23:43:36 -0600 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-12-09 10:41:00 +0100 |
| commit | 5d28fac59369b5d3c48cdf09e50275a61ff91202 (patch) | |
| tree | 6414330245292a7b140d65d194a1858353262daa /lib | |
| parent | b544be374458009b65d16296291fbd6fbb824ba6 (diff) | |
| download | linux-5d28fac59369b5d3c48cdf09e50275a61ff91202.tar.gz linux-5d28fac59369b5d3c48cdf09e50275a61ff91202.tar.bz2 linux-5d28fac59369b5d3c48cdf09e50275a61ff91202.zip | |
kunit: Fix potential null dereference in kunit_device_driver_test()
commit 435c20eed572a95709b1536ff78832836b2f91b1 upstream.
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: d03c720e03bd ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/kunit/kunit-test.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index 37e02be1e710..d9c781c859fd 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -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"); |
