* [PATCH] selftests/bpf: Use ARRAY_SIZE for array length
@ 2024-02-02 9:06 Jiapeng Chong
2024-02-02 21:50 ` Martin KaFai Lau
0 siblings, 1 reply; 2+ messages in thread
From: Jiapeng Chong @ 2024-02-02 9:06 UTC (permalink / raw)
To: andrii
Cc: eddyz87, mykolal, ast, daniel, martin.lau, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, bpf,
linux-kselftest, linux-kernel, Jiapeng Chong, Abaci Robot
Use of macro ARRAY_SIZE to calculate array size minimizes
the redundant code and improves code reusability.
./tools/testing/selftests/bpf/progs/syscall.c:122:26-27: WARNING: Use ARRAY_SIZE.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=8170
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
tools/testing/selftests/bpf/progs/syscall.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/progs/syscall.c b/tools/testing/selftests/bpf/progs/syscall.c
index 3d3cafdebe72..297a34f224c3 100644
--- a/tools/testing/selftests/bpf/progs/syscall.c
+++ b/tools/testing/selftests/bpf/progs/syscall.c
@@ -119,7 +119,7 @@ int load_prog(struct args *ctx)
static __u64 value = 34;
static union bpf_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
- .insn_cnt = sizeof(insns) / sizeof(insns[0]),
+ .insn_cnt = ARRAY_SIZE(insns)
};
int ret;
--
2.20.1.7.g153144c
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/bpf: Use ARRAY_SIZE for array length
2024-02-02 9:06 [PATCH] selftests/bpf: Use ARRAY_SIZE for array length Jiapeng Chong
@ 2024-02-02 21:50 ` Martin KaFai Lau
0 siblings, 0 replies; 2+ messages in thread
From: Martin KaFai Lau @ 2024-02-02 21:50 UTC (permalink / raw)
To: Jiapeng Chong
Cc: eddyz87, mykolal, ast, daniel, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, bpf,
linux-kselftest, linux-kernel, Abaci Robot, andrii
On 2/2/24 1:06 AM, Jiapeng Chong wrote:
> Use of macro ARRAY_SIZE to calculate array size minimizes
> the redundant code and improves code reusability.
>
> ./tools/testing/selftests/bpf/progs/syscall.c:122:26-27: WARNING: Use ARRAY_SIZE.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=8170
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> tools/testing/selftests/bpf/progs/syscall.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/syscall.c b/tools/testing/selftests/bpf/progs/syscall.c
> index 3d3cafdebe72..297a34f224c3 100644
> --- a/tools/testing/selftests/bpf/progs/syscall.c
> +++ b/tools/testing/selftests/bpf/progs/syscall.c
> @@ -119,7 +119,7 @@ int load_prog(struct args *ctx)
> static __u64 value = 34;
> static union bpf_attr prog_load_attr = {
> .prog_type = BPF_PROG_TYPE_XDP,
> - .insn_cnt = sizeof(insns) / sizeof(insns[0]),
> + .insn_cnt = ARRAY_SIZE(insns)
This does not even compile:
https://github.com/kernel-patches/bpf/actions/runs/7761734279/job/21170796228
The existing code here is fine.
> };
> int ret;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-02 21:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-02 9:06 [PATCH] selftests/bpf: Use ARRAY_SIZE for array length Jiapeng Chong
2024-02-02 21:50 ` Martin KaFai Lau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox