Skip to content

Commit 08894d9

Browse files
ytcoodeanakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a19df71 commit 08894d9

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,22 +1374,20 @@ static bool bpf_map_type__is_map_in_map(enum bpf_map_type type)
13741374

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

1381-
*size = 0;
13821380
if (!name)
13831381
return -EINVAL;
13841382

13851383
scn = elf_sec_by_name(obj, name);
13861384
data = elf_sec_data(obj, scn);
13871385
if (data) {
1388-
ret = 0; /* found it */
13891386
*size = data->d_size;
1387+
return 0; /* found it */
13901388
}
13911389

1392-
return *size ? 0 : ret;
1390+
return -ENOENT;
13931391
}
13941392

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

0 commit comments

Comments
 (0)