浏览代码

netfilter: nf_tables: eliminate useless condition checks

The return value of nf_tables_table_lookup() is valid pointer or one
pointer error. There are two cases:

1) IS_ERR(table) is true, it would return the error or reset the
   table as NULL, it is unnecessary to perform the latter check
   "table != NULL".

2) IS_ERR(obj) is false, the table is one valid pointer. It is also
   unnecessary to perform that check.

The nf_tables_newset() and nf_tables_newobj() have same logic codes.

In summary, we could move the block of condition check "table != NULL"
in the else block to eliminate the original condition checks.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Gao Feng 8 年之前
父节点
当前提交
1a28ad74eb
共有 1 个文件被更改,包括 3 次插入12 次删除
  1. 3 12
      net/netfilter/nf_tables_api.c

+ 3 - 12
net/netfilter/nf_tables_api.c

@@ -696,10 +696,7 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
 	if (IS_ERR(table)) {
 	if (IS_ERR(table)) {
 		if (PTR_ERR(table) != -ENOENT)
 		if (PTR_ERR(table) != -ENOENT)
 			return PTR_ERR(table);
 			return PTR_ERR(table);
-		table = NULL;
-	}
-
-	if (table != NULL) {
+	} else {
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 			return -EEXIST;
 			return -EEXIST;
 		if (nlh->nlmsg_flags & NLM_F_REPLACE)
 		if (nlh->nlmsg_flags & NLM_F_REPLACE)
@@ -2963,10 +2960,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
 	if (IS_ERR(set)) {
 	if (IS_ERR(set)) {
 		if (PTR_ERR(set) != -ENOENT)
 		if (PTR_ERR(set) != -ENOENT)
 			return PTR_ERR(set);
 			return PTR_ERR(set);
-		set = NULL;
-	}
-
-	if (set != NULL) {
+	} else {
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 			return -EEXIST;
 			return -EEXIST;
 		if (nlh->nlmsg_flags & NLM_F_REPLACE)
 		if (nlh->nlmsg_flags & NLM_F_REPLACE)
@@ -4153,10 +4147,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
 		if (err != -ENOENT)
 		if (err != -ENOENT)
 			return err;
 			return err;
 
 
-		obj = NULL;
-	}
-
-	if (obj != NULL) {
+	} else {
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 			return -EEXIST;
 			return -EEXIST;