Skip to contentSkip to conversation

netfilter: ipset: Use max macro instead of ternary operator

PATCH In review simran singhal 3 participants 3 messages Mar 28, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ipset: Use max macro instead of ternary operator

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.

---
 net/netfilter/ipset/ip_set_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_core.c +1 -1
index 10a3694..248fef7 100644
@@ -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);
 
Signature · 1 line
2.7.4
#1 lore raw

net/netfilter/ipset/ip_set_core.c ip_set_test(ip_set_id_t index, const struct sk_buff *skb, · line 574

Quoted 5 lines · simran singhal

This patch replaces ternary operator with macro max as it shorter and thus increases code readability.

net/netfilter/ipset/ip_set_core.c +1 -1
-	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.

#2 lore raw
In reply to simran singhal

From: simran singhal

Quoted 4 lines

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.

...

net/netfilter/ipset/ip_set_core.c ip_set_test(ip_set_id_t index, const struct sk_buff *skb, · line 574

Quoted 3 lines
net/netfilter/ipset/ip_set_core.c +1 -1
 	/* 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