]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
kunit: Fix potential null dereference in kunit_device_driver_test()
authorZichen Xie <zichenxie0106@gmail.com>
Fri, 15 Nov 2024 05:43:36 +0000 (23:43 -0600)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 19 Nov 2024 22:17:51 +0000 (15:17 -0700)
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>
lib/kunit/kunit-test.c

index 37e02be1e71015a19ac50dd00c6d74e9ec550702..d9c781c859fde1f3623eb71b6829e82aa4803762 100644 (file)
@@ -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");