Skip to content

Commit f9a5e36

Browse files
Jianyun GaoKernel Patches Daemon
authored andcommitted
libbpf: optimize the redundant code in the bpf_object__init_user_btf_maps() function.
In the elf_sec_data() function, the input parameter 'scn' will be evaluated. If it is NULL, then it will directly return NULL. Therefore, the return value of the elf_sec_data() function already takes into account the case where the input parameter scn is NULL. Therefore, subsequently, the code only needs to check whether the return value of the elf_sec_data() function is NULL. Signed-off-by: Jianyun Gao <[email protected]>
1 parent 4d1f3ab commit f9a5e36

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,15 +2988,15 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict,
29882988
int nr_types, i, vlen, err;
29892989
const struct btf_type *t;
29902990
const char *name;
2991-
Elf_Data *data;
2991+
Elf_Data *scn_data;
29922992
Elf_Scn *scn;
29932993

29942994
if (obj->efile.btf_maps_shndx < 0)
29952995
return 0;
29962996

29972997
scn = elf_sec_by_idx(obj, obj->efile.btf_maps_shndx);
2998-
data = elf_sec_data(obj, scn);
2999-
if (!scn || !data) {
2998+
scn_data = elf_sec_data(obj, scn);
2999+
if (!scn_data) {
30003000
pr_warn("elf: failed to get %s map definitions for %s\n",
30013001
MAPS_ELF_SEC, obj->path);
30023002
return -EINVAL;

0 commit comments

Comments
 (0)