* [PATCH] netfilter: ipset: Use max macro instead of ternary operator
@ 2017-03-28 13:32 simran singhal
2017-03-28 14:03 ` Jan Engelhardt
2017-03-28 14:13 ` David Laight
0 siblings, 2 replies; 3+ messages in thread
From: simran singhal @ 2017-03-28 13:32 UTC (permalink / raw)
To: pablo
Cc: outreachy-kernel, Jozsef Kadlecsik, David S. Miller,
netfilter-devel, coreteam, netdev, linux-kernel
This patch replaces ternary operator with macro max as it shorter and
thus increases code readability. Macro max return the maximum of the two
compared values.
Signed-off-by: simran singhal <singhalsimran0@gmail.com>
---
net/netfilter/ipset/ip_set_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 10a3694..248fef7 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -571,7 +571,7 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb,
}
/* Convert error codes to nomatch */
- return (ret < 0 ? 0 : ret);
+ return max(0, ret);
}
EXPORT_SYMBOL_GPL(ip_set_test);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] netfilter: ipset: Use max macro instead of ternary operator
2017-03-28 13:32 [PATCH] netfilter: ipset: Use max macro instead of ternary operator simran singhal
@ 2017-03-28 14:03 ` Jan Engelhardt
2017-03-28 14:13 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: Jan Engelhardt @ 2017-03-28 14:03 UTC (permalink / raw)
To: simran singhal
Cc: pablo, outreachy-kernel, Jozsef Kadlecsik, David S. Miller,
netfilter-devel, coreteam, netdev, linux-kernel
On Tuesday 2017-03-28 15:32, simran singhal wrote:
>This patch replaces ternary operator with macro max as it shorter and
>thus increases code readability.
>
>- return (ret < 0 ? 0 : ret);
>+ return max(0, ret);
While the two are functionally equivalent, "max" conveys a meaning of
"upper bound" (think ceil(3)), i.e. a _count of something_, but the
function still returns a logical "error or bool".
Such a change may be usable in an IOCCC or a codegolf contest,
but it destroys rather than improves readability IMHO.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] netfilter: ipset: Use max macro instead of ternary operator
2017-03-28 13:32 [PATCH] netfilter: ipset: Use max macro instead of ternary operator simran singhal
2017-03-28 14:03 ` Jan Engelhardt
@ 2017-03-28 14:13 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2017-03-28 14:13 UTC (permalink / raw)
To: 'simran singhal', pablo@netfilter.org
Cc: outreachy-kernel@googlegroups.com, Jozsef Kadlecsik,
David S. Miller, netfilter-devel@vger.kernel.org,
coreteam@netfilter.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
From: simran singhal
> Sent: 28 March 2017 14:33
> This patch replaces ternary operator with macro max as it shorter and
> thus increases code readability. Macro max return the maximum of the two
> compared values.
...
> /* Convert error codes to nomatch */
> - return (ret < 0 ? 0 : ret);
> + return max(0, ret);
It might be shorter but it isn't more readable.
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-28 14:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-28 13:32 [PATCH] netfilter: ipset: Use max macro instead of ternary operator simran singhal
2017-03-28 14:03 ` Jan Engelhardt
2017-03-28 14:13 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox