From: simran singhal <singhalsimran0@gmail.com>
To: pablo@netfilter.org
Cc: kadlec@blackhole.kfki.hu, davem@davemloft.net,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
gregkh@linuxfoundation.org, outreachy-kernel@googlegroups.com
Subject: [PATCH 3/5] netfilter: nf_tables_api: Clean up tests if NULL returned on failure
Date: Tue, 21 Mar 2017 14:14:37 +0530 [thread overview]
Message-ID: <1490085879-1827-4-git-send-email-singhalsimran0@gmail.com> (raw)
In-Reply-To: <1490085879-1827-1-git-send-email-singhalsimran0@gmail.com>
Some functions like kmalloc/kzalloc return NULL on failure. When NULL
represents failure, !x is commonly used.
This was done using Coccinelle:
@@
expression *e;
identifier l1;
@@
e = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\)(...);
...
- e == NULL
+ !e
Signed-off-by: simran singhal <singhalsimran0@gmail.com>
---
--This is my contribution to the netfilter project of
Outreachy Round 14.
net/netfilter/nf_tables_api.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 5e0ccfd..25a3951 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -117,7 +117,7 @@ static struct nft_trans *nft_trans_alloc_gfp(const struct nft_ctx *ctx,
struct nft_trans *trans;
trans = kzalloc(sizeof(struct nft_trans) + size, gfp);
- if (trans == NULL)
+ if (!trans)
return NULL;
trans->msg_type = msg_type;
@@ -720,7 +720,7 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
err = -ENOMEM;
table = kzalloc(sizeof(*table), GFP_KERNEL);
- if (table == NULL)
+ if (!table)
goto err2;
nla_strlcpy(table->name, name, NFT_TABLE_MAXNAMELEN);
@@ -1478,7 +1478,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
return err;
basechain = kzalloc(sizeof(*basechain), GFP_KERNEL);
- if (basechain == NULL) {
+ if (!basechain) {
nft_chain_release_hook(&hook);
return -ENOMEM;
}
@@ -1526,7 +1526,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
basechain->policy = policy;
} else {
chain = kzalloc(sizeof(*chain), GFP_KERNEL);
- if (chain == NULL)
+ if (!chain)
return -ENOMEM;
}
@@ -1800,7 +1800,7 @@ struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
err = -ENOMEM;
expr = kzalloc(info.ops->size, GFP_KERNEL);
- if (expr == NULL)
+ if (!expr)
goto err2;
err = nf_tables_newexpr(ctx, &info, expr);
@@ -2214,7 +2214,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
err = -ENOMEM;
rule = kzalloc(sizeof(*rule) + size + usize, GFP_KERNEL);
- if (rule == NULL)
+ if (!rule)
goto err1;
nft_activate_next(net, rule);
@@ -2810,7 +2810,7 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,
struct nft_ctx *ctx_dump;
ctx_dump = kmalloc(sizeof(*ctx_dump), GFP_KERNEL);
- if (ctx_dump == NULL)
+ if (!ctx_dump)
return -ENOMEM;
*ctx_dump = ctx;
@@ -3014,7 +3014,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
err = -ENOMEM;
set = kzalloc(sizeof(*set) + size + udlen, GFP_KERNEL);
- if (set == NULL)
+ if (!set)
goto err1;
nla_strlcpy(name, nla[NFTA_SET_NAME], sizeof(set->name));
@@ -3543,7 +3543,7 @@ void *nft_set_elem_init(const struct nft_set *set,
void *elem;
elem = kzalloc(set->ops->elemsize + tmpl->len, gfp);
- if (elem == NULL)
+ if (!elem)
return NULL;
ext = nft_set_elem_ext(set, elem);
@@ -3998,7 +3998,7 @@ struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
struct nft_set_gc_batch *gcb;
gcb = kzalloc(sizeof(*gcb), gfp);
- if (gcb == NULL)
+ if (!gcb)
return gcb;
gcb->head.set = set;
return gcb;
@@ -4084,7 +4084,7 @@ static struct nft_object *nft_obj_init(const struct nft_object_type *type,
err = -ENOMEM;
obj = kzalloc(sizeof(struct nft_object) + type->size, GFP_KERNEL);
- if (obj == NULL)
+ if (!obj)
goto err1;
err = type->init((const struct nlattr * const *)tb, obj);
@@ -5567,7 +5567,7 @@ static int __init nf_tables_module_init(void)
info = kmalloc(sizeof(struct nft_expr_info) * NFT_RULE_MAXEXPRS,
GFP_KERNEL);
- if (info == NULL) {
+ if (!info) {
err = -ENOMEM;
goto err1;
}
--
2.7.4
next prev parent reply other threads:[~2017-03-21 8:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-21 8:44 [PATCH 0/5] netfilter: Clean up tests if NULL returned on failure simran singhal
2017-03-21 8:44 ` [PATCH 1/5] netfilter: ipvs: " simran singhal
2017-03-21 8:44 ` [PATCH 2/5] netfilter: " simran singhal
2017-03-21 8:44 ` simran singhal [this message]
2017-03-21 8:44 ` [PATCH 4/5] netfilter: nfnetlink: " simran singhal
2017-03-21 8:44 ` [PATCH 5/5] netfilter: xt_TEE: " simran singhal
2017-03-22 13:38 ` [PATCH 0/5] netfilter: " Pablo Neira Ayuso
2017-03-22 13:45 ` SIMRAN SINGHAL
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=1490085879-1827-4-git-send-email-singhalsimran0@gmail.com \
--to=singhalsimran0@gmail.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=kadlec@blackhole.kfki.hu \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=outreachy-kernel@googlegroups.com \
--cc=pablo@netfilter.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).