From: Guo Zhengkui <guozhengkui@vivo.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: "Shuah Khan" <shuah@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Yucong Sun" <sunyucong@gmail.com>,
"Dave Marchevsky" <davemarchevsky@fb.com>,
"Christy Lee" <christylee@fb.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Delyan Kratunov" <delyank@fb.com>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
"open list:BPF (Safe dynamic programs and tools)"
<netdev@vger.kernel.org>,
"open list:BPF (Safe dynamic programs and tools)"
<bpf@vger.kernel.org>, "open list" <linux-kernel@vger.kernel.org>,
"zhengkui_guo@outlook.com" <zhengkui_guo@outlook.com>
Subject: Re: [PATCH v2] selftests/bpf: fix array_size.cocci warning
Date: Tue, 15 Mar 2022 19:48:16 +0800 [thread overview]
Message-ID: <9aa7d222-57ff-ad0c-7094-a3ee160ddb83@vivo.com> (raw)
In-Reply-To: <CAEf4BzY0F3g8oH7+u14DTs707STVSCi8j=A5_S=hn6VRXHzzXg@mail.gmail.com>
On 2022/3/12 2:38, Andrii Nakryiko wrote:
> On Tue, Mar 8, 2022 at 7:36 PM Guo Zhengkui <guozhengkui@vivo.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@vivo.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?
I think so. Just leave progs/*.c unchanged. I'll commit PATCH v3.
>
>> #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 */
>
> [...]
Zhengkui
prev parent reply other threads:[~2022-03-15 11:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 9:17 [PATCH] selftests/bpf: fix array_size.cocci warning Guo Zhengkui
2022-03-08 14:59 ` Daniel Borkmann
2022-03-08 15:00 ` Daniel Borkmann
2022-03-09 3:22 ` [PATCH v2] " Guo Zhengkui
2022-03-09 3:27 ` Guo Zhengkui
2022-03-09 3:35 ` Guo Zhengkui
2022-03-10 22:08 ` Daniel Borkmann
2022-03-15 13:01 ` [PATCH v3] " Guo Zhengkui
2022-03-15 16:20 ` patchwork-bot+netdevbpf
2022-03-11 18:38 ` [PATCH v2] " Andrii Nakryiko
2022-03-15 11:48 ` Guo Zhengkui [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9aa7d222-57ff-ad0c-7094-a3ee160ddb83@vivo.com \
--to=guozhengkui@vivo.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=christylee@fb.com \
--cc=daniel@iogearbox.net \
--cc=davemarchevsky@fb.com \
--cc=delyank@fb.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=sunyucong@gmail.com \
--cc=toke@redhat.com \
--cc=yhs@fb.com \
--cc=zhengkui_guo@outlook.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).