There is no need to call kfree(im_node) when updating element fails, because im_node must be NULL. Remove the unnecessary kfree() for im_node.
Unified · Split
| @@ -315,7 +315,7 @@ static long trie_update_elem(struct bpf_map *map, · 314 unmodified lines | |||
| 315 | void *_key, void *value, u64 flags) | 315 | void *_key, void *value, u64 flags) |
| 316 | { | 316 | { |
| 317 | struct lpm_trie *trie = container_of(map, struct lpm_trie, map); | 317 | struct lpm_trie *trie = container_of(map, struct lpm_trie, map); |
| 318 | struct lpm_trie_node *node, *im_node = NULL, *new_node = NULL; | 318 | struct lpm_trie_node *node, *im_node, *new_node = NULL; |
| 319 | struct lpm_trie_node *free_node = NULL; | 319 | struct lpm_trie_node *free_node = NULL; |
| 320 | struct lpm_trie_node __rcu **slot; | 320 | struct lpm_trie_node __rcu **slot; |
| 321 | struct bpf_lpm_trie_key_u8 *key = _key; | 321 | struct bpf_lpm_trie_key_u8 *key = _key; |
| @@ -431,9 +431,7 @@ out: · 109 unmodified lines | |||
| 431 | if (ret) { | 431 | if (ret) { |
| 432 | if (new_node) | 432 | if (new_node) |
| 433 | trie->n_entries--; | 433 | trie->n_entries--; |
| 434 | |||
| 435 | kfree(new_node); | 434 | kfree(new_node); |
| 436 | kfree(im_node); | ||
| 437 | } | 435 | } |
| 438 | 436 | ||
| 439 | spin_unlock_irqrestore(&trie->lock, irq_flags); | 437 | spin_unlock_irqrestore(&trie->lock, irq_flags); |