aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2009-01-11 19:06:08 -0500
committerDavid S. Miller <davem@davemloft.net>2009-01-13 00:18:36 -0500
commitcd7fcbf1cb6933bfb9171452b4a370c92923544d (patch)
tree5f1aeff8208d3ab70c3001fbb32f4d3b6044219a /net
parent71320afcdb33b3f0b754ba1fac6a8c77aa469041 (diff)
netfilter 07/09: 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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/netfilter/nf_conntrack_core.c4
-rw-r--r--net/netfilter/nf_conntrack_netlink.c2
2 files changed, 3 insertions, 3 deletions
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 7e83f74cd5d..90ce9ddb945 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,
469 const struct nf_conntrack_tuple *repl, 469 const struct nf_conntrack_tuple *repl,
470 gfp_t gfp) 470 gfp_t gfp)
471{ 471{
472 struct nf_conn *ct = NULL; 472 struct nf_conn *ct;
473 473
474 if (unlikely(!nf_conntrack_hash_rnd_initted)) { 474 if (unlikely(!nf_conntrack_hash_rnd_initted)) {
475 get_random_bytes(&nf_conntrack_hash_rnd, 4); 475 get_random_bytes(&nf_conntrack_hash_rnd, 4);
@@ -551,7 +551,7 @@ init_conntrack(struct net *net,
551 } 551 }
552 552
553 ct = nf_conntrack_alloc(net, tuple, &repl_tuple, GFP_ATOMIC); 553 ct = nf_conntrack_alloc(net, tuple, &repl_tuple, GFP_ATOMIC);
554 if (ct == NULL || IS_ERR(ct)) { 554 if (IS_ERR(ct)) {
555 pr_debug("Can't allocate conntrack.\n"); 555 pr_debug("Can't allocate conntrack.\n");
556 return (struct nf_conntrack_tuple_hash *)ct; 556 return (struct nf_conntrack_tuple_hash *)ct;
557 } 557 }
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 00e8c27130f..3dddec6d2f7 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[],
1134 struct nf_conntrack_helper *helper; 1134 struct nf_conntrack_helper *helper;
1135 1135
1136 ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC); 1136 ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC);
1137 if (ct == NULL || IS_ERR(ct)) 1137 if (IS_ERR(ct))
1138 return -ENOMEM; 1138 return -ENOMEM;
1139 1139
1140 if (!cda[CTA_TIMEOUT]) 1140 if (!cda[CTA_TIMEOUT])