diff mbox

[nf-next,1/1] netfilter: nf_tables: Remove one useless condition check in nf_tables_newobj

Message ID 1483667388-30814-1-git-send-email-fgao@ikuai8.com
State Not Applicable
Delegated to: Pablo Neira
Headers show

Commit Message

高峰 Jan. 6, 2017, 1:49 a.m. UTC
From: Gao Feng <fgao@ikuai8.com>

The return value of nf_tables_obj_lookup is valid pointer or one error.
There are two cases in nf_tables_newobj totally.
case1: return value is -ENOENT, the obj is NULL, it is unnecessary to
perform the latter check "obj != NULL".
case2: IS_ERR(obj) is false, the obj is one valid pointer. It is also
unnecessary to perform that check.

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

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 net/netfilter/nf_tables_api.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Feng Gao Jan. 11, 2017, 1:34 a.m. UTC | #1
On Fri, Jan 6, 2017 at 9:49 AM,  <fgao@ikuai8.com> wrote:
> From: Gao Feng <fgao@ikuai8.com>
>
> The return value of nf_tables_obj_lookup is valid pointer or one error.
> There are two cases in nf_tables_newobj totally.
> case1: return value is -ENOENT, the obj is NULL, it is unnecessary to
> perform the latter check "obj != NULL".
> case2: IS_ERR(obj) is false, the obj is one valid pointer. It is also
> unnecessary to perform that check.
>
> In summary, we could move the block of condition check "obj != NULL" in
> the else block to erase the original condition check.
>
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
>  net/netfilter/nf_tables_api.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index a019a87..bc55086 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -4154,9 +4154,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
>                         return err;
>
>                 obj = NULL;
> -       }
> -
> -       if (obj != NULL) {
> +       } else {
>                 if (nlh->nlmsg_flags & NLM_F_EXCL)
>                         return -EEXIST;
>
> --
> 1.9.1
>
>

Hi all,

Please ignore this patch.
Because I find the nf_tables_newtable and nf_tables_newset have same
logic, so I update them too, and send another patch.

The link is https://patchwork.ozlabs.org/patch/713533/.

Regards
Feng
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index a019a87..bc55086 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4154,9 +4154,7 @@  static int nf_tables_newobj(struct net *net, struct sock *nlsk,
 			return err;
 
 		obj = NULL;
-	}
-
-	if (obj != NULL) {
+	} else {
 		if (nlh->nlmsg_flags & NLM_F_EXCL)
 			return -EEXIST;