[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzY0F3g8oH7+u14DTs707STVSCi8j=A5_S=hn6VRXHzzXg@mail.gmail.com>
Date: Fri, 11 Mar 2022 10:38:31 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Guo Zhengkui <guozhengkui@...o.com>
Cc: Shuah Khan <shuah@...nel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Yucong Sun <sunyucong@...il.com>,
Dave Marchevsky <davemarchevsky@...com>,
Christy Lee <christylee@...com>,
Toke Høiland-Jørgensen <toke@...hat.com>,
Delyan Kratunov <delyank@...com>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@...r.kernel.org>,
"open list:BPF (Safe dynamic programs and tools)"
<netdev@...r.kernel.org>,
"open list:BPF (Safe dynamic programs and tools)"
<bpf@...r.kernel.org>, open list <linux-kernel@...r.kernel.org>,
zhengkui_guo@...look.com
Subject: Re: [PATCH v2] selftests/bpf: fix array_size.cocci warning
On Tue, Mar 8, 2022 at 7:36 PM Guo Zhengkui <guozhengkui@...o.com> wrote:
>
> Fix the array_size.cocci warning in tools/testing/selftests/bpf/
>
> Use `ARRAY_SIZE(arr)` in bpf_util.h instead of forms like
> `sizeof(arr)/sizeof(arr[0])`.
>
> Signed-off-by: Guo Zhengkui <guozhengkui@...o.com>
> ---
> .../selftests/bpf/prog_tests/cgroup_attach_autodetach.c | 2 +-
> .../testing/selftests/bpf/prog_tests/cgroup_attach_multi.c | 2 +-
> .../selftests/bpf/prog_tests/cgroup_attach_override.c | 2 +-
> tools/testing/selftests/bpf/prog_tests/global_data.c | 6 +++---
> tools/testing/selftests/bpf/prog_tests/obj_name.c | 2 +-
> tools/testing/selftests/bpf/progs/syscall.c | 3 ++-
> tools/testing/selftests/bpf/progs/test_rdonly_maps.c | 3 ++-
> tools/testing/selftests/bpf/test_cgroup_storage.c | 2 +-
> tools/testing/selftests/bpf/test_lru_map.c | 4 ++--
> tools/testing/selftests/bpf/test_sock_addr.c | 6 +++---
> tools/testing/selftests/bpf/test_sockmap.c | 4 ++--
> 11 files changed, 19 insertions(+), 17 deletions(-)
>
[...]
> diff --git a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c
> index fc8e8a34a3db..a500f2c15970 100644
> --- a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c
> +++ b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c
> @@ -3,6 +3,7 @@
>
> #include <linux/ptrace.h>
> #include <linux/bpf.h>
> +#include <bpf_util.h>
bpf_util.h isn't supposed to be included from BPF source code side. Is
this ARRAY_SIZE() use so important for BPF programs? Maybe just leave
existing code under progs/*.c as is?
> #include <bpf/bpf_helpers.h>
>
> const struct {
> @@ -64,7 +65,7 @@ int full_loop(struct pt_regs *ctx)
> {
> /* prevent compiler to optimize everything out */
> unsigned * volatile p = (void *)&rdonly_values.a;
> - int i = sizeof(rdonly_values.a) / sizeof(rdonly_values.a[0]);
> + int i = ARRAY_SIZE(rdonly_values.a);
> unsigned iters = 0, sum = 0;
>
> /* validate verifier can allow full loop as well */
[...]
Powered by blists - more mailing lists