Skip to contentSkip to conversation

xfrm_hash: kmalloc + memset conversion to kzalloc

PATCH In review Joonwoo Park 4 participants 6 messages Nov 26, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 xfrm_hash: kmalloc + memset conversion to kzalloc

xfrm_hash: kmalloc + memset conversion to kzalloc

Thanks.
Joonwoo

---

net/xfrm/xfrm_hash.c +11 -10
index 55ab579..37795bd 100644
@@ -17,16 +17,17 @@ struct hlist_head *xfrm_hash_alloc(unsigned int sz)
 	struct hlist_head *n;
 
 	if (sz <= PAGE_SIZE)
-		n = kmalloc(sz, GFP_KERNEL);
-	else if (hashdist)
-		n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);
-	else
-		n = (struct hlist_head *)
-			__get_free_pages(GFP_KERNEL | __GFP_NOWARN,
-					 get_order(sz));
-
-	if (n)
-		memset(n, 0, sz);
+		n = kzalloc(sz, GFP_KERNEL);
+	else {
+		if (hashdist)
+			n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);
+		else
+			n = (struct hlist_head *)
+				__get_free_pages(GFP_KERNEL | __GFP_NOWARN,
+						 get_order(sz));
+		if (n)
+			memset(n, 0, sz);
+	}
 
 	return n;
 }

---

#1 lore raw
Quoted 19 lines · Joonwoo Park

xfrm_hash: kmalloc + memset conversion to kzalloc

Thanks.
Joonwoo

---

net/xfrm/xfrm_hash.c +0 -3
index 55ab579..37795bd 100644
@@ -17,16 +17,17 @@ struct hlist_head *xfrm_hash_alloc(unsigned int sz)
 	struct hlist_head *n;
 
 	if (sz <= PAGE_SIZE)
-		n = kmalloc(sz, GFP_KERNEL);
-	else if (hashdist)
-		n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);

net/xfrm/xfrm_hash.c struct hlist_head *xfrm_hash_alloc(unsigned int sz) · line 22

Quoted 10 lines
net/xfrm/xfrm_hash.c +3 -7
-	else
-		n = (struct hlist_head *)
-			__get_free_pages(GFP_KERNEL | __GFP_NOWARN,
-					 get_order(sz));
-
-	if (n)
-		memset(n, 0, sz);
+		n = kzalloc(sz, GFP_KERNEL);
+	else {
+		if (hashdist)

i believe the more common standard for the above is:

  else if (hashdist) {

to reduce the level of overall indentation, no?

rday

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

#2 lore raw
Quoted 7 lines

i believe the more common standard for the above is:

else if (hashdist) {

to reduce the level of overall indentation, no?

No, it was.
Because there was a memset in that indentation, but I made it by removing memset.

Thanks.
Joonwoo

#3 lore raw
In reply to Joonwoo Park
Quoted 18 lines · Joonwoo Park
net/xfrm/xfrm_hash.c +0 -10
index 55ab579..37795bd 100644
@@ -17,16 +17,17 @@ struct hlist_head *xfrm_hash_alloc(unsigned int sz)
 	struct hlist_head *n;
 
 	if (sz <= PAGE_SIZE)
-		n = kmalloc(sz, GFP_KERNEL);
-	else if (hashdist)
-		n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);
-	else
-		n = (struct hlist_head *)
-			__get_free_pages(GFP_KERNEL | __GFP_NOWARN,
-					 get_order(sz));
-
-	if (n)
-		memset(n, 0, sz);

net/xfrm/xfrm_hash.c struct hlist_head *xfrm_hash_alloc(unsigned int sz) · line 29

Quoted 10 lines
net/xfrm/xfrm_hash.c +10 -0
+		n = kzalloc(sz, GFP_KERNEL);
+	else {
+		if (hashdist)
+			n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);
+		else
+			n = (struct hlist_head *)
+				__get_free_pages(GFP_KERNEL | __GFP_NOWARN,
+						 get_order(sz));
+		if (n)
+			memset(n, 0, sz);

How about also switching vmalloc/get_free_pages to GFP_ZERO and getting rid of the memset entirely while you're at it?

#4 lore raw

2007/11/26, Patrick McHardy <[email protected]>:

Quoted 3 lines

How about also switching vmalloc/get_free_pages to GFP_ZERO and getting rid of the memset entirely while you're at it?

xfrm_hash: kmalloc + memset conversion to kzalloc
fix to avoid memset entirely.
Thanks Patrick.

Thanks.
Joonwoo

---

net/xfrm/xfrm_hash.c +3 -6
index 55ab579..a2023ec 100644
@@ -17,17 +17,14 @@ struct hlist_head *xfrm_hash_alloc(unsigned int sz)
 	struct hlist_head *n;
 
 	if (sz <= PAGE_SIZE)
-		n = kmalloc(sz, GFP_KERNEL);
+		n = kzalloc(sz, GFP_KERNEL);
 	else if (hashdist)
-		n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);
+		n = __vmalloc(sz, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
 	else
 		n = (struct hlist_head *)
-			__get_free_pages(GFP_KERNEL | __GFP_NOWARN,
+			__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
 					 get_order(sz));
 
-	if (n)
-		memset(n, 0, sz);
-
 	return n;
 }
 

---

maintainer
#5 lore raw
Quoted 7 lines · Joonwoo Park

2007/11/26, Patrick McHardy <[email protected]>:

Quoted 3 lines

How about also switching vmalloc/get_free_pages to GFP_ZERO and getting rid of the memset entirely while you're at it?

xfrm_hash: kmalloc + memset conversion to kzalloc
fix to avoid memset entirely.

Patch applied. Thanks everyone!

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt