Commit 25cec756 authored by Matthias Kaehlcke's avatar Matthias Kaehlcke Committed by David S. Miller

net/ipv4: fib_trie: Avoid cryptic ternary expressions

empty_child_inc/dec() use the ternary operator for conditional
operations. The conditions involve the post/pre in/decrement
operator and the operation is only performed when the condition
is *not* true. This is hard to parse for humans, use a regular
'if' construct instead and perform the in/decrement separately.

This also fixes two warnings that are emitted about the value
of the ternary expression being unused, when building the kernel
with clang + "kbuild: Remove unnecessary -Wno-unused-value"
(https://lore.kernel.org/patchwork/patch/1089869/):

CC      net/ipv4/fib_trie.o
net/ipv4/fib_trie.c:351:2: error: expression result unused [-Werror,-Wunused-value]
        ++tn_info(n)->empty_children ? : ++tn_info(n)->full_children;

Fixes: 95f60ea3 ("fib_trie: Add collapse() and should_collapse() to resize")
Signed-off-by: default avatarMatthias Kaehlcke <mka@chromium.org>
Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Acked-by: default avatarAlexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 16e5a266
...@@ -338,12 +338,18 @@ static struct tnode *tnode_alloc(int bits) ...@@ -338,12 +338,18 @@ static struct tnode *tnode_alloc(int bits)
static inline void empty_child_inc(struct key_vector *n) static inline void empty_child_inc(struct key_vector *n)
{ {
++tn_info(n)->empty_children ? : ++tn_info(n)->full_children; tn_info(n)->empty_children++;
if (!tn_info(n)->empty_children)
tn_info(n)->full_children++;
} }
static inline void empty_child_dec(struct key_vector *n) static inline void empty_child_dec(struct key_vector *n)
{ {
tn_info(n)->empty_children-- ? : tn_info(n)->full_children--; if (!tn_info(n)->empty_children)
tn_info(n)->full_children--;
tn_info(n)->empty_children--;
} }
static struct key_vector *leaf_new(t_key key, struct fib_alias *fa) static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment