netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check
@ 2016-09-26 14:13 fgao
  2016-09-26 15:17 ` Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: fgao @ 2016-09-26 14:13 UTC (permalink / raw)
  To: pablo, netfilter-devel; +Cc: gfree.wind, Gao Feng

From: Gao Feng <fgao@ikuai8.com>

Use not operation instead of condition check to simplify the codes.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 net/netfilter/xt_nfacct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/xt_nfacct.c b/net/netfilter/xt_nfacct.c
index cf32759..7abb5b5 100644
--- a/net/netfilter/xt_nfacct.c
+++ b/net/netfilter/xt_nfacct.c
@@ -28,7 +28,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
 
 	overquota = nfnl_acct_overquota(par->net, skb, info->nfacct);
 
-	return overquota == NFACCT_UNDERQUOTA ? false : true;
+	return !(overquota == NFACCT_UNDERQUOTA);
 }
 
 static int
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check
  2016-09-26 14:13 [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check fgao
@ 2016-09-26 15:17 ` Florian Westphal
  2016-09-27  0:36   ` Gao Feng
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2016-09-26 15:17 UTC (permalink / raw)
  To: fgao; +Cc: pablo, netfilter-devel, gfree.wind

fgao@ikuai8.com <fgao@ikuai8.com> wrote:
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/xt_nfacct.c b/net/netfilter/xt_nfacct.c
> index cf32759..7abb5b5 100644
> --- a/net/netfilter/xt_nfacct.c
> +++ b/net/netfilter/xt_nfacct.c
> @@ -28,7 +28,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
>  
>  	overquota = nfnl_acct_overquota(par->net, skb, info->nfacct);
>  
> -	return overquota == NFACCT_UNDERQUOTA ? false : true;
> +	return !(overquota == NFACCT_UNDERQUOTA);

I don't find one better than the other.  If you need to change
it for some reason consider

"return overquota != NFACCT_UNDERQUOTA"

instead of this strange negation.

But really, I think its fine as-is.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check
  2016-09-26 15:17 ` Florian Westphal
@ 2016-09-27  0:36   ` Gao Feng
  2016-09-27  0:39     ` Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Feng @ 2016-09-27  0:36 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Pablo Neira Ayuso, Netfilter Developer Mailing List

Hi Florian,

On Mon, Sep 26, 2016 at 11:17 PM, Florian Westphal <fw@strlen.de> wrote:
> fgao@ikuai8.com <fgao@ikuai8.com> wrote:
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/netfilter/xt_nfacct.c b/net/netfilter/xt_nfacct.c
>> index cf32759..7abb5b5 100644
>> --- a/net/netfilter/xt_nfacct.c
>> +++ b/net/netfilter/xt_nfacct.c
>> @@ -28,7 +28,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
>>
>>       overquota = nfnl_acct_overquota(par->net, skb, info->nfacct);
>>
>> -     return overquota == NFACCT_UNDERQUOTA ? false : true;
>> +     return !(overquota == NFACCT_UNDERQUOTA);
>
> I don't find one better than the other.  If you need to change
> it for some reason consider
>
> "return overquota != NFACCT_UNDERQUOTA"
>
> instead of this strange negation.

Thanks, it is more simple use "!=".

>
> But really, I think its fine as-is.

It could decrease one condition check and jump.


Regards
Feng



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check
  2016-09-27  0:36   ` Gao Feng
@ 2016-09-27  0:39     ` Florian Westphal
  2016-09-27  1:04       ` Gao Feng
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2016-09-27  0:39 UTC (permalink / raw)
  To: Gao Feng
  Cc: Florian Westphal, Pablo Neira Ayuso,
	Netfilter Developer Mailing List

Gao Feng <fgao@ikuai8.com> wrote:
> >> diff --git a/net/netfilter/xt_nfacct.c b/net/netfilter/xt_nfacct.c
> >> index cf32759..7abb5b5 100644
> >> --- a/net/netfilter/xt_nfacct.c
> >> +++ b/net/netfilter/xt_nfacct.c
> >> @@ -28,7 +28,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
> >>
> >>       overquota = nfnl_acct_overquota(par->net, skb, info->nfacct);
> >>
> >> -     return overquota == NFACCT_UNDERQUOTA ? false : true;
> >> +     return !(overquota == NFACCT_UNDERQUOTA);
> >
> > I don't find one better than the other.  If you need to change
> > it for some reason consider
> >
> > "return overquota != NFACCT_UNDERQUOTA"
> >
> > instead of this strange negation.
> 
> Thanks, it is more simple use "!=".
> >
> > But really, I think its fine as-is.
> 
> It could decrease one condition check and jump.

gcc should emit same instructions for all these variants.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check
  2016-09-27  0:39     ` Florian Westphal
@ 2016-09-27  1:04       ` Gao Feng
  0 siblings, 0 replies; 5+ messages in thread
From: Gao Feng @ 2016-09-27  1:04 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Pablo Neira Ayuso, Netfilter Developer Mailing List

On Tue, Sep 27, 2016 at 8:39 AM, Florian Westphal <fw@strlen.de> wrote:
> Gao Feng <fgao@ikuai8.com> wrote:
>> >> diff --git a/net/netfilter/xt_nfacct.c b/net/netfilter/xt_nfacct.c
>> >> index cf32759..7abb5b5 100644
>> >> --- a/net/netfilter/xt_nfacct.c
>> >> +++ b/net/netfilter/xt_nfacct.c
>> >> @@ -28,7 +28,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
>> >>
>> >>       overquota = nfnl_acct_overquota(par->net, skb, info->nfacct);
>> >>
>> >> -     return overquota == NFACCT_UNDERQUOTA ? false : true;
>> >> +     return !(overquota == NFACCT_UNDERQUOTA);
>> >
>> > I don't find one better than the other.  If you need to change
>> > it for some reason consider
>> >
>> > "return overquota != NFACCT_UNDERQUOTA"
>> >
>> > instead of this strange negation.
>>
>> Thanks, it is more simple use "!=".
>> >
>> > But really, I think its fine as-is.
>>
>> It could decrease one condition check and jump.
>
> gcc should emit same instructions for all these variants.

Thanks Florian.
It is unnecessary to simplify it now.

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-27  1:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-26 14:13 [PATCH nf-next] netfilter: xt_nfacct: Use not operation instead of condition check fgao
2016-09-26 15:17 ` Florian Westphal
2016-09-27  0:36   ` Gao Feng
2016-09-27  0:39     ` Florian Westphal
2016-09-27  1:04       ` Gao Feng

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).