Skip to content

Commit 156c977

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Remove unnecessary check when updating LPM trie
When "node->prefixlen == matchlen" is true, it means that the node is fully matched. If "node->prefixlen == key->prefixlen" is false, it means the prefix length of key is greater than the prefix length of node, otherwise, matchlen will not be equal with node->prefixlen. However, it also implies that the prefix length of node must be less than max_prefixlen. Therefore, "node->prefixlen == trie->max_prefixlen" will always be false when the check of "node->prefixlen == key->prefixlen" returns false. Remove this unnecessary comparison. Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: Hou Tao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e2cf913 commit 156c977

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/bpf/lpm_trie.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ static long trie_update_elem(struct bpf_map *map,
364364
matchlen = longest_prefix_match(trie, node, key);
365365

366366
if (node->prefixlen != matchlen ||
367-
node->prefixlen == key->prefixlen ||
368-
node->prefixlen == trie->max_prefixlen)
367+
node->prefixlen == key->prefixlen)
369368
break;
370369

371370
next_bit = extract_bit(key->data, node->prefixlen);

0 commit comments

Comments
 (0)