netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net, ipv6: remove redundant NULL checks before kfree in ip6_flowlabel.c
@ 2005-03-16 23:36 Jesper Juhl
  2005-03-17  2:54 ` YOSHIFUJI Hideaki / 吉藤英明
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2005-03-16 23:36 UTC (permalink / raw)
  To: Alexey Kuznetsov
  Cc: David S. Miller, Pekka Savola, netdev, linux-net, linux-kernel


kfree() has no problems dealing with NULL pointers, so wrapping checks for 
null round calls to it is redundant. This patch gets rid of two such 
checks in net/ipv6/ip6_flowlabel.c

I considered also rewriting the 
        if (fl)
                fl_free(fl);
bit as simply fl_free(fl) as well, but that if() potentially saves two 
calls to kfree() inside fl_free as well as the call to fl_free itself, so 
I guess that's worth the if().

Please consider applying.


Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

diff -up linux-2.6.11-mm4-orig/net/ipv6/ip6_flowlabel.c linux-2.6.11-mm4/net/ipv6/ip6_flowlabel.c
--- linux-2.6.11-mm4-orig/net/ipv6/ip6_flowlabel.c	2005-03-02 08:37:50.000000000 +0100
+++ linux-2.6.11-mm4/net/ipv6/ip6_flowlabel.c	2005-03-17 00:23:30.000000000 +0100
@@ -87,8 +87,7 @@ static struct ip6_flowlabel * fl_lookup(
 
 static void fl_free(struct ip6_flowlabel *fl)
 {
-	if (fl->opt)
-		kfree(fl->opt);
+	kfree(fl->opt);
 	kfree(fl);
 }
 
@@ -553,8 +552,7 @@ release:
 done:
 	if (fl)
 		fl_free(fl);
-	if (sfl1)
-		kfree(sfl1);
+	kfree(sfl1);
 	return err;
 }
 



-- 
Jesper Juhl

PS. Please CC me on replies from lists other than linux-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net, ipv6: remove redundant NULL checks before kfree in ip6_flowlabel.c
  2005-03-16 23:36 [PATCH] net, ipv6: remove redundant NULL checks before kfree in ip6_flowlabel.c Jesper Juhl
@ 2005-03-17  2:54 ` YOSHIFUJI Hideaki / 吉藤英明
  2005-03-17  4:58   ` David S. Miller
  2005-03-17  6:21   ` Jesper Juhl
  0 siblings, 2 replies; 4+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2005-03-17  2:54 UTC (permalink / raw)
  To: davem, juhl-lkml
  Cc: kuznet, davem, pekkas, netdev, linux-net, linux-kernel, yoshfuji

In article <Pine.LNX.4.62.0503170027390.2558@dragon.hyggekrogen.localhost> (at Thu, 17 Mar 2005 00:36:35 +0100 (CET)), Jesper Juhl <juhl-lkml@dif.dk> says:

> I considered also rewriting the 
>         if (fl)
>                 fl_free(fl);
> bit as simply fl_free(fl) as well, but that if() potentially saves two 
> calls to kfree() inside fl_free as well as the call to fl_free itself, so 
> I guess that's worth the if().

I don't mind calling kfree twice itself (because that function is not
so performance critical), but fl_free(NULL) is out because
if fl is NULL, kfree(fl->opt) is out.

So, what do you think of checking fl inside fl_free like this?

We can even make fl_free inline and check as following:
  if (fl) {
    kfree(fl->opt);
    kfree(fl);
  }

Based on patch from Jesper Juhl <juhl-lkml@dif.dk>.

David?

Signed-off-by: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>

===== net/ipv6/ip6_flowlabel.c 1.18 vs edited =====
--- 1.18/net/ipv6/ip6_flowlabel.c	2005-01-14 13:41:06 +09:00
+++ edited/net/ipv6/ip6_flowlabel.c	2005-03-17 11:23:32 +09:00
@@ -87,7 +87,7 @@
 
 static void fl_free(struct ip6_flowlabel *fl)
 {
-	if (fl->opt)
+	if (fl)
 		kfree(fl->opt);
 	kfree(fl);
 }
@@ -351,8 +351,7 @@
 	return fl;
 
 done:
-	if (fl)
-		fl_free(fl);
+	fl_free(fl);
 	*err_p = err;
 	return NULL;
 }
@@ -551,10 +550,8 @@
 	}
 
 done:
-	if (fl)
-		fl_free(fl);
-	if (sfl1)
-		kfree(sfl1);
+	fl_free(fl);
+	kfree(sfl1);
 	return err;
 }
 

-- 
Hideaki YOSHIFUJI @ USAGI Project <yoshfuji@linux-ipv6.org>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net, ipv6: remove redundant NULL checks before kfree in ip6_flowlabel.c
  2005-03-17  2:54 ` YOSHIFUJI Hideaki / 吉藤英明
@ 2005-03-17  4:58   ` David S. Miller
  2005-03-17  6:21   ` Jesper Juhl
  1 sibling, 0 replies; 4+ messages in thread
From: David S. Miller @ 2005-03-17  4:58 UTC (permalink / raw)
  To: yoshfuji; +Cc: juhl-lkml, kuznet, pekkas, netdev, linux-net, linux-kernel

On Thu, 17 Mar 2005 11:54:44 +0900 (JST)
YOSHIFUJI Hideaki / ^[$B5HF#1QL@^[(B <yoshfuji@linux-ipv6.org> wrote:

> Based on patch from Jesper Juhl <juhl-lkml@dif.dk>.
> 
> David?
> 
> Signed-off-by: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>

This version of the patch is fine, applied.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net, ipv6: remove redundant NULL checks before kfree in ip6_flowlabel.c
  2005-03-17  2:54 ` YOSHIFUJI Hideaki / 吉藤英明
  2005-03-17  4:58   ` David S. Miller
@ 2005-03-17  6:21   ` Jesper Juhl
  1 sibling, 0 replies; 4+ messages in thread
From: Jesper Juhl @ 2005-03-17  6:21 UTC (permalink / raw)
  To: YOSHIFUJI Hideaki / 吉藤英明
  Cc: davem, kuznet, pekkas, netdev, linux-net, linux-kernel

On Thu, 17 Mar 2005, YOSHIFUJI Hideaki / [iso-2022-jp] µÈÆ£±ÑÌÀ wrote:

> In article <Pine.LNX.4.62.0503170027390.2558@dragon.hyggekrogen.localhost> (at Thu, 17 Mar 2005 00:36:35 +0100 (CET)), Jesper Juhl <juhl-lkml@dif.dk> says:
> 
> > I considered also rewriting the 
> >         if (fl)
> >                 fl_free(fl);
> > bit as simply fl_free(fl) as well, but that if() potentially saves two 
> > calls to kfree() inside fl_free as well as the call to fl_free itself, so 
> > I guess that's worth the if().
> 
> I don't mind calling kfree twice itself (because that function is not
> so performance critical), but fl_free(NULL) is out because
> if fl is NULL, kfree(fl->opt) is out.
> 
Yes, you are right ofcourse. 
Thanks.

-- 
Jesper

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-17  6:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-16 23:36 [PATCH] net, ipv6: remove redundant NULL checks before kfree in ip6_flowlabel.c Jesper Juhl
2005-03-17  2:54 ` YOSHIFUJI Hideaki / 吉藤英明
2005-03-17  4:58   ` David S. Miller
2005-03-17  6:21   ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).