Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1610898 > unrolled thread

[PATCH] netfilter: ipset: Use max macro instead of ternary operator

Started bysimran singhal <singhalsimran0@gmail.com>
First post2017-03-28 15:40 +0200
Last post2017-03-28 16:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] netfilter: ipset: Use max macro instead of ternary operator simran singhal <singhalsimran0@gmail.com> - 2017-03-28 15:40 +0200
    Re: [PATCH] netfilter: ipset: Use max macro instead of ternary  operator Jan Engelhardt <jengelh@inai.de> - 2017-03-28 16:10 +0200
    RE: [PATCH] netfilter: ipset: Use max macro instead of ternary  operator David Laight <David.Laight@ACULAB.COM> - 2017-03-28 16:20 +0200

#1610898 — [PATCH] netfilter: ipset: Use max macro instead of ternary operator

Fromsimran singhal <singhalsimran0@gmail.com>
Date2017-03-28 15:40 +0200
Subject[PATCH] netfilter: ipset: Use max macro instead of ternary operator
Message-ID<tpZvQ-8gn-27@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1610990 — Re: [PATCH] netfilter: ipset: Use max macro instead of ternary operator

FromJan Engelhardt <jengelh@inai.de>
Date2017-03-28 16:10 +0200
SubjectRe: [PATCH] netfilter: ipset: Use max macro instead of ternary operator
Message-ID<tpZYR-lk-9@gated-at.bofh.it>
In reply to#1610898
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.

[toc] | [prev] | [next] | [standalone]


#1610998 — RE: [PATCH] netfilter: ipset: Use max macro instead of ternary operator

FromDavid Laight <David.Laight@ACULAB.COM>
Date2017-03-28 16:20 +0200
SubjectRE: [PATCH] netfilter: ipset: Use max macro instead of ternary operator
Message-ID<tq08y-pa-11@gated-at.bofh.it>
In reply to#1610898
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web