Skip to content

Commit

Permalink
libbpf: Simplify the find_elf_sec_sz() function
Browse files Browse the repository at this point in the history
The check in the last return statement is unnecessary, we can just return
the ret variable.

But we can simplify the function further by returning 0 immediately if we
find the section size and -ENOENT otherwise.

Thus we can also remove the ret variable.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
  • Loading branch information
ytcoode authored and Nobody committed Feb 23, 2022
1 parent 8f17ab2 commit 279eb09
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,22 +1374,20 @@ static bool bpf_map_type__is_map_in_map(enum bpf_map_type type)

static int find_elf_sec_sz(const struct bpf_object *obj, const char *name, __u32 *size)
{
int ret = -ENOENT;
Elf_Data *data;
Elf_Scn *scn;

*size = 0;
if (!name)
return -EINVAL;

scn = elf_sec_by_name(obj, name);
data = elf_sec_data(obj, scn);
if (data) {
ret = 0; /* found it */
*size = data->d_size;
return 0; /* found it */
}

return *size ? 0 : ret;
return -ENOENT;
}

static int find_elf_var_offset(const struct bpf_object *obj, const char *name, __u32 *off)
Expand Down

0 comments on commit 279eb09

Please sign in to comment.