All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers
@ 2023-03-01  8:53 Viktor Malik
  2023-03-01  8:53 ` [PATCH bpf-next 1/3] libbpf: remove unnecessary ternary operator Viktor Malik
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Viktor Malik @ 2023-03-01  8:53 UTC (permalink / raw)
  To: bpf
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, Viktor Malik

Fixing several issues reported by Coverity and Clang Static Analyzer
(scan-build) for libbpf, mostly removing unnecessary symbols and
assignments.

No functional changes should be introduced.

Viktor Malik (3):
  libbpf: remove unnecessary ternary operator
  libbpf: remove several dead assignments
  libbpf: cleanup linker_append_elf_relos

 tools/lib/bpf/btf.c       |  2 --
 tools/lib/bpf/libbpf.c    |  3 +--
 tools/lib/bpf/linker.c    | 11 ++---------
 tools/lib/bpf/relo_core.c |  3 ---
 4 files changed, 3 insertions(+), 16 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 1/3] libbpf: remove unnecessary ternary operator
  2023-03-01  8:53 [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers Viktor Malik
@ 2023-03-01  8:53 ` Viktor Malik
  2023-03-01  8:53 ` [PATCH bpf-next 2/3] libbpf: remove several dead assignments Viktor Malik
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Viktor Malik @ 2023-03-01  8:53 UTC (permalink / raw)
  To: bpf
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, Viktor Malik

Coverity reports that the first check of 'err' in bpf_object__init_maps
is always false as 'err' is initialized to 0 at that point. Remove the
unnecessary ternary operator.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 05c4db355f28..905193d98885 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2615,7 +2615,7 @@ static int bpf_object__init_maps(struct bpf_object *obj,
 	strict = !OPTS_GET(opts, relaxed_maps, false);
 	pin_root_path = OPTS_GET(opts, pin_root_path, NULL);
 
-	err = err ?: bpf_object__init_user_btf_maps(obj, strict, pin_root_path);
+	err = bpf_object__init_user_btf_maps(obj, strict, pin_root_path);
 	err = err ?: bpf_object__init_global_data_maps(obj);
 	err = err ?: bpf_object__init_kconfig_map(obj);
 	err = err ?: bpf_object__init_struct_ops_maps(obj);
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 2/3] libbpf: remove several dead assignments
  2023-03-01  8:53 [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers Viktor Malik
  2023-03-01  8:53 ` [PATCH bpf-next 1/3] libbpf: remove unnecessary ternary operator Viktor Malik
@ 2023-03-01  8:53 ` Viktor Malik
  2023-03-01  8:53 ` [PATCH bpf-next 3/3] libbpf: cleanup linker_append_elf_relos Viktor Malik
  2023-03-01 19:20 ` [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Viktor Malik @ 2023-03-01  8:53 UTC (permalink / raw)
  To: bpf
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, Viktor Malik

Clang Static Analyzer (scan-build) reports several dead assignments in
libbpf where the assigned value is unconditionally overridden by another
value before it is read. Remove these assignments.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
---
 tools/lib/bpf/btf.c       | 2 --
 tools/lib/bpf/libbpf.c    | 1 -
 tools/lib/bpf/relo_core.c | 3 ---
 3 files changed, 6 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 9181d36118d2..0a2c079244b6 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1000,8 +1000,6 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
 		}
 	}
 
-	err = 0;
-
 	if (!btf_data) {
 		pr_warn("failed to find '%s' ELF section in %s\n", BTF_ELF_SEC, path);
 		err = -ENODATA;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 905193d98885..ba9e7e2b7951 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -798,7 +798,6 @@ bpf_object__add_programs(struct bpf_object *obj, Elf_Data *sec_data,
 	progs = obj->programs;
 	nr_progs = obj->nr_programs;
 	nr_syms = symbols->d_size / sizeof(Elf64_Sym);
-	sec_off = 0;
 
 	for (i = 0; i < nr_syms; i++) {
 		sym = elf_sym_by_idx(obj, i);
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index c4b0e81ae293..a26b2f5fa0fc 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -1551,9 +1551,6 @@ int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const st
 	if (level <= 0)
 		return -EINVAL;
 
-	local_t = btf_type_by_id(local_btf, local_id);
-	targ_t = btf_type_by_id(targ_btf, targ_id);
-
 recur:
 	depth--;
 	if (depth < 0)
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 3/3] libbpf: cleanup linker_append_elf_relos
  2023-03-01  8:53 [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers Viktor Malik
  2023-03-01  8:53 ` [PATCH bpf-next 1/3] libbpf: remove unnecessary ternary operator Viktor Malik
  2023-03-01  8:53 ` [PATCH bpf-next 2/3] libbpf: remove several dead assignments Viktor Malik
@ 2023-03-01  8:53 ` Viktor Malik
  2023-03-01 19:20 ` [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Viktor Malik @ 2023-03-01  8:53 UTC (permalink / raw)
  To: bpf
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, Viktor Malik

Clang Static Analyser (scan-build) reports some unused symbols and dead
assignments in the linker_append_elf_relos function. Clean these up.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
---
 tools/lib/bpf/linker.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
index 4ac02c28e152..d7069780984a 100644
--- a/tools/lib/bpf/linker.c
+++ b/tools/lib/bpf/linker.c
@@ -1997,7 +1997,6 @@ static int linker_append_elf_sym(struct bpf_linker *linker, struct src_obj *obj,
 static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *obj)
 {
 	struct src_sec *src_symtab = &obj->secs[obj->symtab_sec_idx];
-	struct dst_sec *dst_symtab;
 	int i, err;
 
 	for (i = 1; i < obj->sec_cnt; i++) {
@@ -2030,9 +2029,6 @@ static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *ob
 			return -1;
 		}
 
-		/* add_dst_sec() above could have invalidated linker->secs */
-		dst_symtab = &linker->secs[linker->symtab_sec_idx];
-
 		/* shdr->sh_link points to SYMTAB */
 		dst_sec->shdr->sh_link = linker->symtab_sec_idx;
 
@@ -2049,16 +2045,13 @@ static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *ob
 		dst_rel = dst_sec->raw_data + src_sec->dst_off;
 		n = src_sec->shdr->sh_size / src_sec->shdr->sh_entsize;
 		for (j = 0; j < n; j++, src_rel++, dst_rel++) {
-			size_t src_sym_idx = ELF64_R_SYM(src_rel->r_info);
-			size_t sym_type = ELF64_R_TYPE(src_rel->r_info);
-			Elf64_Sym *src_sym, *dst_sym;
-			size_t dst_sym_idx;
+			size_t src_sym_idx, dst_sym_idx, sym_type;
+			Elf64_Sym *src_sym;
 
 			src_sym_idx = ELF64_R_SYM(src_rel->r_info);
 			src_sym = src_symtab->data->d_buf + sizeof(*src_sym) * src_sym_idx;
 
 			dst_sym_idx = obj->sym_map[src_sym_idx];
-			dst_sym = dst_symtab->raw_data + sizeof(*dst_sym) * dst_sym_idx;
 			dst_rel->r_offset += src_linked_sec->dst_off;
 			sym_type = ELF64_R_TYPE(src_rel->r_info);
 			dst_rel->r_info = ELF64_R_INFO(dst_sym_idx, sym_type);
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers
  2023-03-01  8:53 [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers Viktor Malik
                   ` (2 preceding siblings ...)
  2023-03-01  8:53 ` [PATCH bpf-next 3/3] libbpf: cleanup linker_append_elf_relos Viktor Malik
@ 2023-03-01 19:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-01 19:20 UTC (permalink / raw)
  To: Viktor Malik
  Cc: bpf, andrii, ast, daniel, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, nathan, ndesaulniers, trix

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Wed,  1 Mar 2023 09:53:52 +0100 you wrote:
> Fixing several issues reported by Coverity and Clang Static Analyzer
> (scan-build) for libbpf, mostly removing unnecessary symbols and
> assignments.
> 
> No functional changes should be introduced.
> 
> Viktor Malik (3):
>   libbpf: remove unnecessary ternary operator
>   libbpf: remove several dead assignments
>   libbpf: cleanup linker_append_elf_relos
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/3] libbpf: remove unnecessary ternary operator
    https://git.kernel.org/bpf/bpf-next/c/40e1bcab1e4c
  - [bpf-next,2/3] libbpf: remove several dead assignments
    https://git.kernel.org/bpf/bpf-next/c/7832d06bd9f9
  - [bpf-next,3/3] libbpf: cleanup linker_append_elf_relos
    https://git.kernel.org/bpf/bpf-next/c/4672129127ee

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-01 19:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01  8:53 [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers Viktor Malik
2023-03-01  8:53 ` [PATCH bpf-next 1/3] libbpf: remove unnecessary ternary operator Viktor Malik
2023-03-01  8:53 ` [PATCH bpf-next 2/3] libbpf: remove several dead assignments Viktor Malik
2023-03-01  8:53 ` [PATCH bpf-next 3/3] libbpf: cleanup linker_append_elf_relos Viktor Malik
2023-03-01 19:20 ` [PATCH bpf-next 0/3] libbpf: fix several issues reported by static analysers patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.