From: Lv Ruyi <lv.ruyi@xxxxxxxxxx> kmalloc and kcalloc is a memory allocation function which can return NULL when some internal memory errors happen. Add null pointer check to avoid dereferencing null pointer. Reported-by: Zeal Robot <zealci@xxxxxxxxxx> Signed-off-by: Lv Ruyi <lv.ruyi@xxxxxxxxxx> --- lib/kunit/executor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 22640c9ee819..be21d0451367 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -71,9 +71,13 @@ kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob) /* Use memcpy to workaround copy->name being const. */ copy = kmalloc(sizeof(*copy), GFP_KERNEL); + if (!copy) + return NULL; memcpy(copy, suite, sizeof(*copy)); filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL); + if (!filtered) + return NULL; n = 0; kunit_suite_for_each_test_case(suite, test_case) { -- 2.25.1