* [PATCH] selftests/bpf: fix array_size.cocci warning:
@ 2021-11-17 13:20 Guo Zhengkui
2021-11-17 22:42 ` Daniel Borkmann
0 siblings, 1 reply; 3+ messages in thread
From: Guo Zhengkui @ 2021-11-17 13:20 UTC (permalink / raw)
To: Shuah Khan, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Guo Zhengkui, Yucong Sun, Dave Marchevsky,
linux-kselftest, netdev, bpf, linux-kernel
Cc: kernel
Use ARRAY_SIZE() because it uses __must_be_array(arr) to make sure
arr is really an array.
Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
.../testing/selftests/bpf/prog_tests/cgroup_attach_override.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c
index 356547e849e2..1921c5040d8c 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
#include <test_progs.h>
#include "cgroup_helpers.h"
@@ -16,10 +17,9 @@ static int prog_load(int verdict)
BPF_MOV64_IMM(BPF_REG_0, verdict), /* r0 = verdict */
BPF_EXIT_INSN(),
};
- size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
return bpf_test_load_program(BPF_PROG_TYPE_CGROUP_SKB,
- prog, insns_cnt, "GPL", 0,
+ prog, ARRAY_SIZE(prog), "GPL", 0,
bpf_log_buf, BPF_LOG_BUF_SIZE);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/bpf: fix array_size.cocci warning:
2021-11-17 13:20 [PATCH] selftests/bpf: fix array_size.cocci warning: Guo Zhengkui
@ 2021-11-17 22:42 ` Daniel Borkmann
2021-11-18 7:11 ` [PATCH] selftests/bpf: fix array_size.cocci warning Guo Zhengkui
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2021-11-17 22:42 UTC (permalink / raw)
To: Guo Zhengkui, Shuah Khan, Alexei Starovoitov, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Yucong Sun, Dave Marchevsky, linux-kselftest, netdev,
bpf, linux-kernel
Cc: kernel
On 11/17/21 2:20 PM, Guo Zhengkui wrote:
> Use ARRAY_SIZE() because it uses __must_be_array(arr) to make sure
> arr is really an array.
>
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> ---
> .../testing/selftests/bpf/prog_tests/cgroup_attach_override.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c
> index 356547e849e2..1921c5040d8c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_override.c
> @@ -1,5 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
>
> +#include <linux/kernel.h>
> #include <test_progs.h>
No need for the extra include. test_progs.h already includes bpf_util.h, please check
such trivialities before submission. Simple grep would have revealed use of ARRAY_SIZE()
in various places under tools/testing/selftests/bpf/prog_tests/.
> #include "cgroup_helpers.h"
> @@ -16,10 +17,9 @@ static int prog_load(int verdict)
> BPF_MOV64_IMM(BPF_REG_0, verdict), /* r0 = verdict */
> BPF_EXIT_INSN(),
> };
> - size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
>
> return bpf_test_load_program(BPF_PROG_TYPE_CGROUP_SKB,
> - prog, insns_cnt, "GPL", 0,
> + prog, ARRAY_SIZE(prog), "GPL", 0,
> bpf_log_buf, BPF_LOG_BUF_SIZE);
There are many more similar occurrences. Please just send one cleanup patch to reduce
churn in the git log.
Thanks,
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/bpf: fix array_size.cocci warning
2021-11-17 22:42 ` Daniel Borkmann
@ 2021-11-18 7:11 ` Guo Zhengkui
0 siblings, 0 replies; 3+ messages in thread
From: Guo Zhengkui @ 2021-11-18 7:11 UTC (permalink / raw)
To: daniel
Cc: andrii, ast, bpf, davemarchevsky, guozhengkui, john.fastabend,
kafai, kernel, kpsingh, linux-kernel, linux-kselftest, netdev,
shuah, songliubraving, sunyucong, yhs
> No need for the extra include. test_progs.h already includes bpf_util.h, please check
> such trivialities before submission. Simple grep would have revealed use of ARRAY_SIZE()
> in various places under tools/testing/selftests/bpf/prog_tests/.
Actually, ARRAY_SIZE() in ./include/linux/kernel.h is diffrent from the one defined in bpf_util.h:
./include/linux/kernel.h
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
./tools/testing/selftests/bpf/bpf_util.h
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
__must_be_array() ensures arr is an array, which is better than the one defined in bpf_util.h
> here are many more similar occurrences. Please just send one cleanup patch to reduce churn in the git log.
Yes, I will commit another patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-18 7:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 13:20 [PATCH] selftests/bpf: fix array_size.cocci warning: Guo Zhengkui
2021-11-17 22:42 ` Daniel Borkmann
2021-11-18 7:11 ` [PATCH] selftests/bpf: fix array_size.cocci warning Guo Zhengkui
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).