mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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 <toke@redhat.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Hou Tao <houtao1@huawei.com> Link: https://lore.kernel.org/r/20241206110622.1161752-2-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
		
							parent
							
								
									e2cf913314
								
							
						
					
					
						commit
						156c977c53
					
				
					 1 changed files with 1 additions and 2 deletions
				
			
		| 
						 | 
					@ -364,8 +364,7 @@ static long trie_update_elem(struct bpf_map *map,
 | 
				
			||||||
		matchlen = longest_prefix_match(trie, node, key);
 | 
							matchlen = longest_prefix_match(trie, node, key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (node->prefixlen != matchlen ||
 | 
							if (node->prefixlen != matchlen ||
 | 
				
			||||||
		    node->prefixlen == key->prefixlen ||
 | 
							    node->prefixlen == key->prefixlen)
 | 
				
			||||||
		    node->prefixlen == trie->max_prefixlen)
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		next_bit = extract_bit(key->data, node->prefixlen);
 | 
							next_bit = extract_bit(key->data, node->prefixlen);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue