All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf
@ 2022-07-05 22:48 Andrii Nakryiko
  2022-07-05 22:48 ` [PATCH bpf-next 1/3] selftests/bpf: fix bogus uninitialized variable warning Andrii Nakryiko
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-07-05 22:48 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Few small patches fixing compiler warning issues detected by Coverity or by
building selftests in -O2 mode.

Andrii Nakryiko (3):
  selftests/bpf: fix bogus uninitialized variable warning
  selftests/bpf: fix few more compiler warnings
  libbpf: remove unnecessary usdt_rel_ip assignments

 tools/lib/bpf/usdt.c                                       | 6 ++----
 tools/testing/selftests/bpf/network_helpers.c              | 2 +-
 tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 ++--
 tools/testing/selftests/bpf/prog_tests/usdt.c              | 2 +-
 tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c      | 2 +-
 5 files changed, 7 insertions(+), 9 deletions(-)

-- 
2.30.2


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

* [PATCH bpf-next 1/3] selftests/bpf: fix bogus uninitialized variable warning
  2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
@ 2022-07-05 22:48 ` Andrii Nakryiko
  2022-07-05 22:48 ` [PATCH bpf-next 2/3] selftests/bpf: fix few more compiler warnings Andrii Nakryiko
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-07-05 22:48 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

When compiling selftests/bpf in optimized mode (-O2), GCC erroneously
complains about uninitialized token variable:

  In file included from network_helpers.c:22:
  network_helpers.c: In function ‘open_netns’:
  test_progs.h:355:22: error: ‘token’ may be used uninitialized [-Werror=maybe-uninitialized]
    355 |         int ___err = libbpf_get_error(___res);                          \
        |                      ^~~~~~~~~~~~~~~~~~~~~~~~
  network_helpers.c:440:14: note: in expansion of macro ‘ASSERT_OK_PTR’
    440 |         if (!ASSERT_OK_PTR(token, "malloc token"))
        |              ^~~~~~~~~~~~~
  In file included from /data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:21,
                   from bpf_util.h:9,
                   from network_helpers.c:20:
  /data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/bpf/libbpf_legacy.h:113:17: note: by argument 1 of type ‘const void *’ to ‘libbpf_get_error’ declared here
    113 | LIBBPF_API long libbpf_get_error(const void *ptr);
        |                 ^~~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors
  make: *** [Makefile:522: /data/users/andriin/linux/tools/testing/selftests/bpf/network_helpers.o] Error 1

This is completely bogus becuase libbpf_get_error() doesn't dereference
pointer, but the only easy way to silence this is to allocate initialized
memory with calloc().

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/network_helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 59cf81ec55af..bec15558fd93 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -436,7 +436,7 @@ struct nstoken *open_netns(const char *name)
 	int err;
 	struct nstoken *token;
 
-	token = malloc(sizeof(struct nstoken));
+	token = calloc(1, sizeof(struct nstoken));
 	if (!ASSERT_OK_PTR(token, "malloc token"))
 		return NULL;
 
-- 
2.30.2


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

* [PATCH bpf-next 2/3] selftests/bpf: fix few more compiler warnings
  2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
  2022-07-05 22:48 ` [PATCH bpf-next 1/3] selftests/bpf: fix bogus uninitialized variable warning Andrii Nakryiko
@ 2022-07-05 22:48 ` Andrii Nakryiko
  2022-07-05 22:48 ` [PATCH bpf-next 3/3] libbpf: remove unnecessary usdt_rel_ip assignments Andrii Nakryiko
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-07-05 22:48 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

When compiling with -O2, GCC detects few problems with selftests/bpf, so
fix all of them. Two are real issues (uninitialized err and nums
out-of-bounds access), but two other uninitialized variables warnings
are due to GCC not being able to prove that variables are indeed
initialized under conditions under which they are used.

Fix all 4 cases, though.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 ++--
 tools/testing/selftests/bpf/prog_tests/usdt.c              | 2 +-
 tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 586dc52d6fb9..a8cb8a96ddaf 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -329,7 +329,7 @@ static int get_syms(char ***symsp, size_t *cntp)
 	struct hashmap *map;
 	char buf[256];
 	FILE *f;
-	int err;
+	int err = 0;
 
 	/*
 	 * The available_filter_functions contains many duplicates,
@@ -404,7 +404,7 @@ static void test_bench_attach(void)
 	double attach_delta, detach_delta;
 	struct bpf_link *link = NULL;
 	char **syms = NULL;
-	size_t cnt, i;
+	size_t cnt = 0, i;
 
 	if (!ASSERT_OK(get_syms(&syms, &cnt), "get_syms"))
 		return;
diff --git a/tools/testing/selftests/bpf/prog_tests/usdt.c b/tools/testing/selftests/bpf/prog_tests/usdt.c
index 5f733d50b0d7..9ad9da0f215e 100644
--- a/tools/testing/selftests/bpf/prog_tests/usdt.c
+++ b/tools/testing/selftests/bpf/prog_tests/usdt.c
@@ -12,7 +12,7 @@ int lets_test_this(int);
 
 static volatile int idx = 2;
 static volatile __u64 bla = 0xFEDCBA9876543210ULL;
-static volatile short nums[] = {-1, -2, -3, };
+static volatile short nums[] = {-1, -2, -3, -4};
 
 static volatile struct {
 	int x;
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c b/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
index fb77a123fe89..874a846e298c 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
@@ -63,7 +63,7 @@ static bool expect_str(char *buf, size_t size, const char *str, const char *name
 static void test_synproxy(bool xdp)
 {
 	int server_fd = -1, client_fd = -1, accept_fd = -1;
-	char *prog_id, *prog_id_end;
+	char *prog_id = NULL, *prog_id_end;
 	struct nstoken *ns = NULL;
 	FILE *ctrl_file = NULL;
 	char buf[CMD_OUT_BUF_SIZE];
-- 
2.30.2


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

* [PATCH bpf-next 3/3] libbpf: remove unnecessary usdt_rel_ip assignments
  2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
  2022-07-05 22:48 ` [PATCH bpf-next 1/3] selftests/bpf: fix bogus uninitialized variable warning Andrii Nakryiko
  2022-07-05 22:48 ` [PATCH bpf-next 2/3] selftests/bpf: fix few more compiler warnings Andrii Nakryiko
@ 2022-07-05 22:48 ` Andrii Nakryiko
  2022-07-06  6:47 ` [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Yonghong Song
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-07-05 22:48 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Coverity detected that usdt_rel_ip is unconditionally overwritten
anyways, so there is no need to unnecessarily initialize it with unused
value. Clean this up.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/usdt.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index 5159207cbfd9..d18e37982344 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -652,11 +652,9 @@ static int collect_usdt_targets(struct usdt_manager *man, Elf *elf, const char *
 		 *
 		 *   [0] https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
 		 */
-		usdt_rel_ip = usdt_abs_ip = note.loc_addr;
-		if (base_addr) {
+		usdt_abs_ip = note.loc_addr;
+		if (base_addr)
 			usdt_abs_ip += base_addr - note.base_addr;
-			usdt_rel_ip += base_addr - note.base_addr;
-		}
 
 		/* When attaching uprobes (which is what USDTs basically are)
 		 * kernel expects file offset to be specified, not a relative
-- 
2.30.2


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

* Re: [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf
  2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
                   ` (2 preceding siblings ...)
  2022-07-05 22:48 ` [PATCH bpf-next 3/3] libbpf: remove unnecessary usdt_rel_ip assignments Andrii Nakryiko
@ 2022-07-06  6:47 ` Yonghong Song
  2022-07-06  8:11 ` Jiri Olsa
  2022-07-06 14:50 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Yonghong Song @ 2022-07-06  6:47 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, ast, daniel; +Cc: kernel-team



On 7/5/22 3:48 PM, Andrii Nakryiko wrote:
> Few small patches fixing compiler warning issues detected by Coverity or by
> building selftests in -O2 mode.
> 
> Andrii Nakryiko (3):
>    selftests/bpf: fix bogus uninitialized variable warning
>    selftests/bpf: fix few more compiler warnings
>    libbpf: remove unnecessary usdt_rel_ip assignments
> 
>   tools/lib/bpf/usdt.c                                       | 6 ++----
>   tools/testing/selftests/bpf/network_helpers.c              | 2 +-
>   tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 ++--
>   tools/testing/selftests/bpf/prog_tests/usdt.c              | 2 +-
>   tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c      | 2 +-
>   5 files changed, 7 insertions(+), 9 deletions(-)
> 
Ack for the whole series:

Acked-by: Yonghong Song <yhs@fb.com>

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

* Re: [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf
  2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
                   ` (3 preceding siblings ...)
  2022-07-06  6:47 ` [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Yonghong Song
@ 2022-07-06  8:11 ` Jiri Olsa
  2022-07-06 14:50 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Jiri Olsa @ 2022-07-06  8:11 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team

On Tue, Jul 05, 2022 at 03:48:15PM -0700, Andrii Nakryiko wrote:
> Few small patches fixing compiler warning issues detected by Coverity or by
> building selftests in -O2 mode.
> 
> Andrii Nakryiko (3):
>   selftests/bpf: fix bogus uninitialized variable warning
>   selftests/bpf: fix few more compiler warnings
>   libbpf: remove unnecessary usdt_rel_ip assignments
> 
>  tools/lib/bpf/usdt.c                                       | 6 ++----
>  tools/testing/selftests/bpf/network_helpers.c              | 2 +-
>  tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 ++--
>  tools/testing/selftests/bpf/prog_tests/usdt.c              | 2 +-
>  tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c      | 2 +-
>  5 files changed, 7 insertions(+), 9 deletions(-)

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

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

* Re: [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf
  2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
                   ` (4 preceding siblings ...)
  2022-07-06  8:11 ` Jiri Olsa
@ 2022-07-06 14:50 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-06 14:50 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team

Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Tue, 5 Jul 2022 15:48:15 -0700 you wrote:
> Few small patches fixing compiler warning issues detected by Coverity or by
> building selftests in -O2 mode.
> 
> Andrii Nakryiko (3):
>   selftests/bpf: fix bogus uninitialized variable warning
>   selftests/bpf: fix few more compiler warnings
>   libbpf: remove unnecessary usdt_rel_ip assignments
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/3] selftests/bpf: fix bogus uninitialized variable warning
    https://git.kernel.org/bpf/bpf-next/c/645d5d3bc001
  - [bpf-next,2/3] selftests/bpf: fix few more compiler warnings
    https://git.kernel.org/bpf/bpf-next/c/c46a12200114
  - [bpf-next,3/3] libbpf: remove unnecessary usdt_rel_ip assignments
    https://git.kernel.org/bpf/bpf-next/c/7c8121af1bfe

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] 7+ messages in thread

end of thread, other threads:[~2022-07-06 14:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05 22:48 [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Andrii Nakryiko
2022-07-05 22:48 ` [PATCH bpf-next 1/3] selftests/bpf: fix bogus uninitialized variable warning Andrii Nakryiko
2022-07-05 22:48 ` [PATCH bpf-next 2/3] selftests/bpf: fix few more compiler warnings Andrii Nakryiko
2022-07-05 22:48 ` [PATCH bpf-next 3/3] libbpf: remove unnecessary usdt_rel_ip assignments Andrii Nakryiko
2022-07-06  6:47 ` [PATCH bpf-next 0/3] Fix few compiler warnings in selftests and libbpf Yonghong Song
2022-07-06  8:11 ` Jiri Olsa
2022-07-06 14:50 ` 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.