lkml.org 
[lkml]   [2022]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
SubjectRe: [PATCH v2] selftests/bpf: fix array_size.cocci warning
From
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

\
 
 \ /
  Last update: 2022-03-15 12:49    [W:0.068 / U:0.672 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site