Commit 588c6ead authored by Hou Tao's avatar Hou Tao Committed by Alexei Starovoitov
Browse files

bpf: Bail out early in __htab_map_lookup_and_delete_elem()



Use goto statement to bail out early when the target element is not
found, instead of using a large else branch to handle the more likely
case. This change doesn't affect functionality and simply make the code
cleaner.

Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
Reviewed-by: default avatarToke Høiland-Jørgensen <toke@kernel.org>
Link: https://lore.kernel.org/r/20250117101816.2101857-3-houtao@huaweicloud.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 45dc92c3
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -1635,7 +1635,9 @@ static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key,
	l = lookup_elem_raw(head, hash, key, key_size);
	if (!l) {
		ret = -ENOENT;
	} else {
		goto out_unlock;
	}

	if (is_percpu) {
		u32 roundup_value_size = round_up(map->value_size, 8);
		void __percpu *pptr;
@@ -1660,12 +1662,11 @@ static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key,
		/* Zeroing special fields in the temp buffer */
		check_and_init_map_value(map, value);
	}

	hlist_nulls_del_rcu(&l->hash_node);
	if (!is_lru_map)
		free_htab_elem(htab, l);
	}

out_unlock:
	htab_unlock_bucket(htab, b, hash, bflags);

	if (is_lru_map && l)