Re: [PATCH v2] selftests/bpf: fix array_size.cocci warning

From: Daniel Borkmann
Date: Thu Mar 10 2022 - 17:08:56 EST


On 3/9/22 4:35 AM, Guo Zhengkui 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@xxxxxxxx>

BPF CI fails with:

https://github.com/kernel-patches/bpf/runs/5498238267?check_suite_focus=true

pahole: Multithreading requires elfutils >= 0.178. Continuing with a single thread...
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:130:8: error: redefinition of 'bpf_map_def'
struct bpf_map_def {
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:685:8: note: previous definition is here
struct bpf_map_def {
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:138:6: error: redefinition of 'libbpf_pin_type'
enum libbpf_pin_type {
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:191:6: note: previous definition is here
enum libbpf_pin_type {
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:139:2: error: redefinition of enumerator 'LIBBPF_PIN_NONE'
LIBBPF_PIN_NONE,
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:192:2: note: previous definition is here
LIBBPF_PIN_NONE,
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:141:2: error: redefinition of enumerator 'LIBBPF_PIN_BY_NAME'
LIBBPF_PIN_BY_NAME,
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:194:2: note: previous definition is here
LIBBPF_PIN_BY_NAME,
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:144:6: error: redefinition of 'libbpf_tristate'
enum libbpf_tristate {
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:1304:6: note: previous definition is here
enum libbpf_tristate {
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:145:2: error: redefinition of enumerator 'TRI_NO'
TRI_NO = 0,
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:1305:2: note: previous definition is here
TRI_NO = 0,
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:146:2: error: redefinition of enumerator 'TRI_YES'
TRI_YES = 1,
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:1306:2: note: previous definition is here
TRI_YES = 1,
^
In file included from progs/test_rdonly_maps.c:7:
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:147:2: error: redefinition of enumerator 'TRI_MODULE'
TRI_MODULE = 2,
^
/tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/bpf/libbpf.h:1307:2: note: previous definition is here
TRI_MODULE = 2,
^
8 errors generated.
make: *** [Makefile:488: /tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/test_rdonly_maps.o] Error 1
make: *** Waiting for unfinished jobs....
Error: Process completed with exit code 2.