From: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> To: shuah@kernel.org Cc: linux-kernel-mentees@lists.linuxfoundation.org, linux-kselftest@vger.kernel.org, Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> Subject: [PATCH v0] selftests/bpf: replace manual array size calc with ARRAYSIZE. Date: Mon, 10 Jul 2023 17:04:48 +0400 [thread overview] Message-ID: <20230710130448.1558118-1-mahmoudmatook.mm@gmail.com> (raw) fixes coccinelle warnings due to manual calculation of array size. Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> --- tools/testing/selftests/bpf/progs/syscall.c | 6 +++++- tools/testing/selftests/bpf/progs/test_rdonly_maps.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/syscall.c b/tools/testing/selftests/bpf/progs/syscall.c index e550f728962d..9cc25d93c601 100644 --- a/tools/testing/selftests/bpf/progs/syscall.c +++ b/tools/testing/selftests/bpf/progs/syscall.c @@ -27,6 +27,10 @@ struct args { BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \ BTF_INT_ENC(encoding, bits_offset, bits) +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) +#endif + static int btf_load(void) { struct btf_blob { @@ -82,7 +86,7 @@ int bpf_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; diff --git a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c index fc8e8a34a3db..7431936ab26c 100644 --- a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c +++ b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c @@ -21,6 +21,10 @@ struct { unsigned sum; } res = {}; +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) +#endif + SEC("raw_tracepoint/sys_enter:skip_loop") int skip_loop(struct pt_regs *ctx) { @@ -64,7 +68,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 */ -- 2.34.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
WARNING: multiple messages have this Message-ID (diff)
From: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> To: shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> Subject: [PATCH v0] selftests/bpf: replace manual array size calc with ARRAYSIZE. Date: Mon, 10 Jul 2023 17:04:48 +0400 [thread overview] Message-ID: <20230710130448.1558118-1-mahmoudmatook.mm@gmail.com> (raw) fixes coccinelle warnings due to manual calculation of array size. Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com> --- tools/testing/selftests/bpf/progs/syscall.c | 6 +++++- tools/testing/selftests/bpf/progs/test_rdonly_maps.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/syscall.c b/tools/testing/selftests/bpf/progs/syscall.c index e550f728962d..9cc25d93c601 100644 --- a/tools/testing/selftests/bpf/progs/syscall.c +++ b/tools/testing/selftests/bpf/progs/syscall.c @@ -27,6 +27,10 @@ struct args { BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz), \ BTF_INT_ENC(encoding, bits_offset, bits) +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) +#endif + static int btf_load(void) { struct btf_blob { @@ -82,7 +86,7 @@ int bpf_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; diff --git a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c index fc8e8a34a3db..7431936ab26c 100644 --- a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c +++ b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c @@ -21,6 +21,10 @@ struct { unsigned sum; } res = {}; +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) +#endif + SEC("raw_tracepoint/sys_enter:skip_loop") int skip_loop(struct pt_regs *ctx) { @@ -64,7 +68,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 */ -- 2.34.1
next reply other threads:[~2023-07-10 13:05 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-10 13:04 Mahmoud Maatuq [this message] 2023-07-10 13:04 ` [PATCH v0] selftests/bpf: replace manual array size calc with ARRAYSIZE Mahmoud Maatuq
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=20230710130448.1558118-1-mahmoudmatook.mm@gmail.com \ --to=mahmoudmatook.mm@gmail.com \ --cc=linux-kernel-mentees@lists.linuxfoundation.org \ --cc=linux-kselftest@vger.kernel.org \ --cc=shuah@kernel.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.