2007-11-26 09:03:09

by Joonwoo Park

[permalink] [raw]
Subject: [PATCH 1/4] xfrm_hash: kmalloc + memset conversion to kzalloc

xfrm_hash: kmalloc + memset conversion to kzalloc

Signed-off-by: Joonwoo Park <[email protected]>

Thanks.
Joonwoo

---
diff --git a/net/xfrm/xfrm_hash.c b/net/xfrm/xfrm_hash.c
index 55ab579..37795bd 100644
--- a/net/xfrm/xfrm_hash.c
+++ b/net/xfrm/xfrm_hash.c
@@ -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;
}
---


2007-11-26 09:08:19

by Robert P. J. Day

[permalink] [raw]
Subject: Re: [PATCH 1/4] xfrm_hash: kmalloc + memset conversion to kzalloc

On Mon, 26 Nov 2007, Joonwoo Park wrote:

> xfrm_hash: kmalloc + memset conversion to kzalloc
>
> Signed-off-by: Joonwoo Park <[email protected]>
>
> Thanks.
> Joonwoo
>
> ---
> diff --git a/net/xfrm/xfrm_hash.c b/net/xfrm/xfrm_hash.c
> index 55ab579..37795bd 100644
> --- a/net/xfrm/xfrm_hash.c
> +++ b/net/xfrm/xfrm_hash.c
> @@ -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)

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
========================================================================

2007-11-26 09:11:46

by Patrick McHardy

[permalink] [raw]
Subject: Re: [PATCH 1/4] xfrm_hash: kmalloc + memset conversion to kzalloc

Joonwoo Park wrote:
> diff --git a/net/xfrm/xfrm_hash.c b/net/xfrm/xfrm_hash.c
> index 55ab579..37795bd 100644
> --- a/net/xfrm/xfrm_hash.c
> +++ b/net/xfrm/xfrm_hash.c
> @@ -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);


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

2007-11-26 10:24:37

by Joonwoo Park

[permalink] [raw]
Subject: RE: [PATCH 1/4] xfrm_hash: kmalloc + memset conversion to kzalloc

2007/11/26, Patrick McHardy <[email protected]>:
> 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


Signed-off-by: Joonwoo Park <[email protected]>

---
diff --git a/net/xfrm/xfrm_hash.c b/net/xfrm/xfrm_hash.c
index 55ab579..a2023ec 100644
--- a/net/xfrm/xfrm_hash.c
+++ b/net/xfrm/xfrm_hash.c
@@ -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;
}

---

2007-11-26 10:28:48

by Joonwoo Park

[permalink] [raw]
Subject: Re: [PATCH 1/4] xfrm_hash: kmalloc + memset conversion to kzalloc

>
> 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

2007-11-26 15:24:34

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 1/4] xfrm_hash: kmalloc + memset conversion to kzalloc

On Mon, Nov 26, 2007 at 10:23:51AM +0000, Joonwoo Park wrote:
> 2007/11/26, Patrick McHardy <[email protected]>:
> > 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!
--
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