[PATCH v2] list: test: potential dereference of null pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To avoid the failure of alloc, we could check the return value of
kmalloc() and kzalloc().

Signed-off-by: Ma Ke <make_ruc2021@xxxxxxx>
---
 lib/list-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/list-test.c b/lib/list-test.c
index 0cc27de9cec8..70e898976dbf 100644
--- a/lib/list-test.c
+++ b/lib/list-test.c
@@ -27,9 +27,18 @@ static void list_test_list_init(struct kunit *test)
 	INIT_LIST_HEAD(&list2);
 
 	list4 = kzalloc(sizeof(*list4), GFP_KERNEL | __GFP_NOFAIL);
+	if (!list4) {
+		KUNIT_FAIL(test, "Initialising list4 failed.\n");
+		return;
+	}
 	INIT_LIST_HEAD(list4);
 
 	list5 = kmalloc(sizeof(*list5), GFP_KERNEL | __GFP_NOFAIL);
+	if (!list5) {
+		kfree(list4);
+		KUNIT_FAIL(test, "Initialising list5 failed.\n");
+		return;
+	}
 	memset(list5, 0xFF, sizeof(*list5));
 	INIT_LIST_HEAD(list5);
 
-- 
2.37.2




[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux