mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-07 09:09:06 +08:00
libbpf: Simplify the find_elf_sec_sz() function
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> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20220223085244.3058118-1-ytcoode@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
c85a8bbe9c
commit
426672106e
@@ -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)
|
static int find_elf_sec_sz(const struct bpf_object *obj, const char *name, __u32 *size)
|
||||||
{
|
{
|
||||||
int ret = -ENOENT;
|
|
||||||
Elf_Data *data;
|
Elf_Data *data;
|
||||||
Elf_Scn *scn;
|
Elf_Scn *scn;
|
||||||
|
|
||||||
*size = 0;
|
|
||||||
if (!name)
|
if (!name)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
scn = elf_sec_by_name(obj, name);
|
scn = elf_sec_by_name(obj, name);
|
||||||
data = elf_sec_data(obj, scn);
|
data = elf_sec_data(obj, scn);
|
||||||
if (data) {
|
if (data) {
|
||||||
ret = 0; /* found it */
|
|
||||||
*size = data->d_size;
|
*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)
|
static int find_elf_var_offset(const struct bpf_object *obj, const char *name, __u32 *off)
|
||||||
|
|||||||
Reference in New Issue
Block a user