Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] kunit: Fix potential null dereference in kunit_device_driver_test()
@ 2024-11-15  5:17 Gax-c
  2024-11-15  5:35 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Gax-c @ 2024-11-15  5:17 UTC (permalink / raw)
  To: brendan.higgins, davidgow, rmoar, mripard, skhan, mazziesaccount,
	gregkh
  Cc: linux-kselftest, kunit-dev, chenyuan0y, zzjas98, Zichen Xie

From: Zichen Xie <zichenxie0106@gmail.com>

kunit_kzalloc() may return a NULL pointer, dereferencing it without
NULL check may lead to NULL dereference.
Add a NULL check for test_state.

Fixes: d03c720e03bd ("kunit: Add APIs for managing devices")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
---
 lib/kunit/kunit-test.c | 2 ++
 1 file changed, 2 insertions(+)

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");
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-15  5:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-15  5:17 [PATCH] kunit: Fix potential null dereference in kunit_device_driver_test() Gax-c
2024-11-15  5:35 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox