Commit 7e8c328c authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann

libbpf: simplify two pieces of logic

Extra check for type is unnecessary in first case.

Extra zeroing is unnecessary, as snprintf guarantees that it will
zero-terminate string.
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent fba01a06
...@@ -1430,8 +1430,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1430,8 +1430,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
if (maps[map_idx].libbpf_type != type) if (maps[map_idx].libbpf_type != type)
continue; continue;
if (type != LIBBPF_MAP_UNSPEC || if (type != LIBBPF_MAP_UNSPEC ||
(type == LIBBPF_MAP_UNSPEC && maps[map_idx].offset == sym.st_value) {
maps[map_idx].offset == sym.st_value)) {
pr_debug("relocation: find map %zd (%s) for insn %u\n", pr_debug("relocation: find map %zd (%s) for insn %u\n",
map_idx, maps[map_idx].name, insn_idx); map_idx, maps[map_idx].name, insn_idx);
break; break;
...@@ -2354,7 +2353,6 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf, ...@@ -2354,7 +2353,6 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf,
snprintf(tmp_name, sizeof(tmp_name), "%lx-%lx", snprintf(tmp_name, sizeof(tmp_name), "%lx-%lx",
(unsigned long)obj_buf, (unsigned long)obj_buf,
(unsigned long)obj_buf_sz); (unsigned long)obj_buf_sz);
tmp_name[sizeof(tmp_name) - 1] = '\0';
name = tmp_name; name = tmp_name;
} }
pr_debug("loading object '%s' from buffer\n", pr_debug("loading object '%s' from buffer\n",
......
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