netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Patrick McHardy <kaber@trash.net>,
	netfilter-devel@vger.kernel.org
Subject: netfilter 07/09: simplify nf_conntrack_alloc() error handling
Date: Mon, 12 Jan 2009 11:06:08 +0100 (MET)	[thread overview]
Message-ID: <20090112100608.9280.46239.sendpatchset@x2.localnet> (raw)
In-Reply-To: <20090112100559.9280.23431.sendpatchset@x2.localnet>

commit 74259cac7b03c2db8d046aa70aa53f4633290fd9
Author: Julia Lawall <julia@diku.dk>
Date:   Mon Jan 12 10:50:52 2009 +0100

    netfilter: simplify nf_conntrack_alloc() error handling
    
    nf_conntrack_alloc cannot return NULL, so there is no need to check for
    NULL before using the value.  I have also removed the initialization of ct
    to NULL in nf_conntrack_alloc, since the value is never used, and since
    perhaps it might lead one to think that return ct at the end might return
    NULL.
    
    The semantic patch that finds this problem is as follows:
    (http://www.emn.fr/x-info/coccinelle/)
    
    // <smpl>
    @match exists@
    expression x, E;
    position p1,p2;
    statement S1, S2;
    @@
    
    x@p1 = nf_conntrack_alloc(...)
    ... when != x = E
    (
      if (x@p2 == NULL || ...) S1 else S2
    |
      if (x@p2 == NULL && ...) S1 else S2
    )
    
    @other_match exists@
    expression match.x, E1, E2;
    position p1!=match.p1,match.p2;
    @@
    
    x@p1 = E1
    ... when != x = E2
    x@p2
    
    @ script:python depends on !other_match@
    p1 << match.p1;
    p2 << match.p2;
    @@
    
    print "%s: call to nf_conntrack_alloc %s bad test %s" % (p1[0].file,p1[0].line,p2[0].line)
    // </smpl>
    
    Signed-off-by: Julia Lawall <julia@diku.dk>
    Signed-off-by: Patrick McHardy <kaber@trash.net>

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 7e83f74..90ce9dd 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -469,7 +469,7 @@ struct nf_conn *nf_conntrack_alloc(struct net *net,
 				   const struct nf_conntrack_tuple *repl,
 				   gfp_t gfp)
 {
-	struct nf_conn *ct = NULL;
+	struct nf_conn *ct;
 
 	if (unlikely(!nf_conntrack_hash_rnd_initted)) {
 		get_random_bytes(&nf_conntrack_hash_rnd, 4);
@@ -551,7 +551,7 @@ init_conntrack(struct net *net,
 	}
 
 	ct = nf_conntrack_alloc(net, tuple, &repl_tuple, GFP_ATOMIC);
-	if (ct == NULL || IS_ERR(ct)) {
+	if (IS_ERR(ct)) {
 		pr_debug("Can't allocate conntrack.\n");
 		return (struct nf_conntrack_tuple_hash *)ct;
 	}
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 00e8c27..3dddec6 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1134,7 +1134,7 @@ ctnetlink_create_conntrack(struct nlattr *cda[],
 	struct nf_conntrack_helper *helper;
 
 	ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC);
-	if (ct == NULL || IS_ERR(ct))
+	if (IS_ERR(ct))
 		return -ENOMEM;
 
 	if (!cda[CTA_TIMEOUT])

  parent reply	other threads:[~2009-01-12 10:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-12 10:05 netfilter 00/09: netfilter fixes/trivial patches Patrick McHardy
2009-01-12 10:06 ` netfilter 01/09: remove "happy cracking" message Patrick McHardy
2009-01-12 10:06 ` netfilter 02/09: bridge: Fix handling of non-IP packets in FORWARD/POST_ROUTING Patrick McHardy
2009-01-12 10:06 ` netfilter 03/09: bridge: Disable PPPOE/VLAN processing by default Patrick McHardy
2009-01-12 10:06 ` netfilter 04/09: x_tables: fix match/target revision lookup Patrick McHardy
2009-01-12 10:06 ` netfilter 05/09: ebtables: fix inversion in match code Patrick McHardy
2009-01-12 10:06 ` netfilter 06/09: nf_conntrack: fix ICMP/ICMPv6 timeout sysctls on big-endian Patrick McHardy
2009-01-12 10:06 ` Patrick McHardy [this message]
2009-01-12 10:06 ` netfilter 08/09: xt_time: print timezone for user information Patrick McHardy
2009-01-12 10:06 ` netfilter 09/09: remove padding from struct xt_match on 64bit builds Patrick McHardy
2009-01-13  0:39 ` netfilter 00/09: netfilter fixes/trivial patches David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090112100608.9280.46239.sendpatchset@x2.localnet \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).