Commit c0885f61 authored by Wang Sheng-Hui's avatar Wang Sheng-Hui Committed by Daniel Borkmann

samples, bpf: remove redundant ret assignment in bpf_load_program()

2 redundant ret assignments removed:

* 'ret = 1' before the logic 'if (data_maps)', and if any errors jump to
  label 'done'. No 'ret = 1' needed before the error jump.

* After the '/* load programs */' part, if everything goes well, then
  the BPF code will be loaded and 'ret' set to 0 by load_and_attach().
  If something goes wrong, 'ret' set to none-O, the redundant 'ret = 0'
  after the for clause will make the error skipped.

  For example, if some BPF code cannot provide supported program types
  in ELF SEC("unknown"), the for clause will not call load_and_attach()
  to load the BPF code. 1 should be returned to callees instead of 0.
Signed-off-by: default avatarWang Sheng-Hui <shhuiw@foxmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent a6712d45
...@@ -549,7 +549,6 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map) ...@@ -549,7 +549,6 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map)
if (nr_maps < 0) { if (nr_maps < 0) {
printf("Error: Failed loading ELF maps (errno:%d):%s\n", printf("Error: Failed loading ELF maps (errno:%d):%s\n",
nr_maps, strerror(-nr_maps)); nr_maps, strerror(-nr_maps));
ret = 1;
goto done; goto done;
} }
if (load_maps(map_data, nr_maps, fixup_map)) if (load_maps(map_data, nr_maps, fixup_map))
...@@ -615,7 +614,6 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map) ...@@ -615,7 +614,6 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map)
} }
} }
ret = 0;
done: done:
close(fd); close(fd);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment