netfilter: nf_nat_h323: fix logical-not-parentheses warning

Submitted by Nick Desaulniers on July 31, 2017, 6:39 p.m.

Details

Message ID 20170731183949.73763-1-ndesaulniers@google.com
State Changes Requested
Delegated to: Pablo Neira
Headers show

Commit Message

Nick Desaulniers July 31, 2017, 6:39 p.m.
Clang produces the following warning:

net/ipv4/netfilter/nf_nat_h323.c:553:6: error:
logical not is only applied to the left hand side of this comparison
  [-Werror,-Wlogical-not-parentheses]
if (!set_h225_addr(skb, protoff, data, dataoff, taddr,
    ^
add parentheses after the '!' to evaluate the comparison first
add parentheses around left hand side expression to silence this warning

There's not necessarily a bug here, but it's cleaner to use the form:

if (x != 0)

rather than:

if (!x == 0)

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Also, it's even cleaner to use the form:

if (x)

but then if the return codes change from treating 0 as success (unlikely),
then all call sites must be updated.

I'm happy to send v2 that changes to that form, and updates the other call
sites to be:

if (set_h225_addr())
  handle_failures()
else
  handle_success()

 net/ipv4/netfilter/nf_nat_h323.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Nick Desaulniers Aug. 8, 2017, 11:28 p.m.
bumping for review

On Mon, Jul 31, 2017 at 11:39 AM, Nick Desaulniers
<ndesaulniers@google.com> wrote:
> Clang produces the following warning:
>
> net/ipv4/netfilter/nf_nat_h323.c:553:6: error:
> logical not is only applied to the left hand side of this comparison
>   [-Werror,-Wlogical-not-parentheses]
> if (!set_h225_addr(skb, protoff, data, dataoff, taddr,
>     ^
> add parentheses after the '!' to evaluate the comparison first
> add parentheses around left hand side expression to silence this warning
>
> There's not necessarily a bug here, but it's cleaner to use the form:
>
> if (x != 0)
>
> rather than:
>
> if (!x == 0)
>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> Also, it's even cleaner to use the form:
>
> if (x)
>
> but then if the return codes change from treating 0 as success (unlikely),
> then all call sites must be updated.
>
> I'm happy to send v2 that changes to that form, and updates the other call
> sites to be:
>
> if (set_h225_addr())
>   handle_failures()
> else
>   handle_success()
>
>  net/ipv4/netfilter/nf_nat_h323.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
> index 574f7ebba0b6..d8fb251fa6e3 100644
> --- a/net/ipv4/netfilter/nf_nat_h323.c
> +++ b/net/ipv4/netfilter/nf_nat_h323.c
> @@ -550,9 +550,9 @@ static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct,
>         }
>
>         /* Modify signal */
> -       if (!set_h225_addr(skb, protoff, data, dataoff, taddr,
> -                          &ct->tuplehash[!dir].tuple.dst.u3,
> -                          htons(nated_port)) == 0) {
> +       if (set_h225_addr(skb, protoff, data, dataoff, taddr,
> +                         &ct->tuplehash[!dir].tuple.dst.u3,
> +                         htons(nated_port)) != 0) {
>                 nf_ct_unexpect_related(exp);
>                 return -1;
>         }
> --
> 2.14.0.rc0.400.g1c36432dff-goog
>
Pablo Neira Aug. 11, 2017, 5:42 p.m.
Hi Nick,

On Mon, Jul 31, 2017 at 11:39:49AM -0700, Nick Desaulniers wrote:
> Clang produces the following warning:
[...]
> Also, it's even cleaner to use the form:
> 
> if (x)
> 
> but then if the return codes change from treating 0 as success (unlikely),
> then all call sites must be updated.
> 
> I'm happy to send v2 that changes to that form, and updates the other call
> sites to be:
> 
> if (set_h225_addr())
>   handle_failures()
> else
>   handle_success()

That sounds very reasonable, send a v2 if this triggers a larger
patch.

Or I can just take this patch, as you prefer.

Thanks!
--
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

Patch hide | download patch | download mbox

diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index 574f7ebba0b6..d8fb251fa6e3 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -550,9 +550,9 @@  static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct,
 	}
 
 	/* Modify signal */
-	if (!set_h225_addr(skb, protoff, data, dataoff, taddr,
-			   &ct->tuplehash[!dir].tuple.dst.u3,
-			   htons(nated_port)) == 0) {
+	if (set_h225_addr(skb, protoff, data, dataoff, taddr,
+			  &ct->tuplehash[!dir].tuple.dst.u3,
+			  htons(nated_port)) != 0) {
 		nf_ct_unexpect_related(exp);
 		return -1;
 	}