Skip to contentSkip to conversation

lib: Use kzalloc() instead of kmalloc() with flag GFP_ZERO.

PATCH In review Yi Wang 2 participants 2 messages Feb 12, 2020 Library code

lore
Share & tools
lore

Yi Wang

author
#0 lore raw

PATCH 1/1 lib: Use kzalloc() instead of kmalloc() with flag GFP_ZERO.

From: Huang Zijiang <[email protected]>

Use kzalloc instead of manually setting kmalloc with flag GFP_ZERO since kzalloc sets allocated memory to zero.

Change in v2:
add indation

---
 lib/test_kasan.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/test_kasan.c +3 -3
index 328d33b..79be158 100644
@@ -599,7 +599,7 @@ static noinline void __init kasan_memchr(void)
 	size_t size = 24;
 
 	pr_info("out-of-bounds in memchr\n");
-	ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
+	ptr = kzalloc(size, GFP_KERNEL);
 	if (!ptr)
 		return;
 
@@ -614,7 +614,7 @@ static noinline void __init kasan_memcmp(void)
 	int arr[9];
 
 	pr_info("out-of-bounds in memcmp\n");
-	ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
+	ptr = kzalloc(size, GFP_KERNEL);
 	if (!ptr)
 		return;
 
@@ -629,7 +629,7 @@ static noinline void __init kasan_strings(void)
 	size_t size = 24;
 
 	pr_info("use-after-free in strchr\n");
-	ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
+	ptr = kzalloc(size, GFP_KERNEL);
 	if (!ptr)
 		return;
 
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yi Wang

From: Huang Zijiang <[email protected]>

Use kzalloc instead of manually setting kmalloc with flag GFP_ZERO since kzalloc sets allocated memory to zero.

Quoted 5 lines

Change in v2:
add indation

Quoted 42 lines
---
 lib/test_kasan.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/test_kasan.c +3 -4
index 328d33b..79be158 100644
@@ -599,7 +599,7 @@ static noinline void __init kasan_memchr(void)
        size_t size = 24;
 
        pr_info("out-of-bounds in memchr\n");
-       ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
+       ptr = kzalloc(size, GFP_KERNEL);
        if (!ptr)
                return;
 
@@ -614,7 +614,7 @@ static noinline void __init kasan_memcmp(void)
        int arr[9];
 
        pr_info("out-of-bounds in memcmp\n");
-       ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
+       ptr = kzalloc(size, GFP_KERNEL);
        if (!ptr)
                return;
 
@@ -629,7 +629,7 @@ static noinline void __init kasan_strings(void)
        size_t size = 24;
 
        pr_info("use-after-free in strchr\n");
-       ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
+       ptr = kzalloc(size, GFP_KERNEL);
        if (!ptr)
                return;
 
--

1.9.1

--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/1581501228-5393-1-git-send-email-wang.yi59%40zte.com.cn.

Signature · 10 lines
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg