mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tony Ambardar <tony.ambardar@gmail.com>
To: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: andrii@kernel.org, eddyz87@gmail.com, mykolal@fb.com,
	ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
	song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, shuah@kernel.org,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Abaci Robot <abaci@linux.alibaba.com>
Subject: Re: [PATCH v2 -next] selftests/bpf: Use ARRAY_SIZE for array length
Date: Mon, 30 Sep 2024 00:30:49 -0700	[thread overview]
Message-ID: <ZvpTqammU0DqcKyz@kodidev-ubuntu> (raw)
In-Reply-To: <20240929092811.7103-1-jiapeng.chong@linux.alibaba.com>

On Sun, Sep 29, 2024 at 05:28:11PM +0800, Jiapeng Chong wrote:
> Use of macro ARRAY_SIZE to calculate array size minimizes
> the redundant code and improves code reusability.
> 
> ./tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c:98:34-35: WARNING: Use ARRAY_SIZE.
> ./tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c:93:29-30: WARNING: Use ARRAY_SIZE.
> ./tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c:101:34-35: WARNING: Use ARRAY_SIZE.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11167
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> Changes in v2:
>   -Modify the header file "kselftest.h" to "linux/kernel.h".
> 
>  tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> index a18d3680fb16..7534014279ca 100644
> --- a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> @@ -7,6 +7,7 @@
>  #include <sys/syscall.h>
>  #include <bpf/libbpf.h>
>  #include <bpf/btf.h>
> +#include <linux/kernel.h>

Hi Jiapeng,

I don't believe adding this header is needed, since ARRAY_SIZE is defined
in bpf_utils.h and already pulled in by test_progs.h below. Maybe try
without "#include <linux/kernel.h"> to check?

Take care,
Tony

>  
>  #include "test_progs.h"
>  #include "test_btf.h"
> @@ -90,15 +91,15 @@ static void test_bad_local_id(void)
>  	attr.prog_type = BPF_TRACE_RAW_TP;
>  	attr.license = (__u64)"GPL";
>  	attr.insns = (__u64)&insns;
> -	attr.insn_cnt = sizeof(insns) / sizeof(*insns);
> +	attr.insn_cnt = ARRAY_SIZE(insns);
>  	attr.log_buf = (__u64)log;
>  	attr.log_size = sizeof(log);
>  	attr.log_level = log_level;
>  	attr.func_info = (__u64)funcs;
> -	attr.func_info_cnt = sizeof(funcs) / sizeof(*funcs);
> +	attr.func_info_cnt = ARRAY_SIZE(funcs);
>  	attr.func_info_rec_size = sizeof(*funcs);
>  	attr.core_relos = (__u64)relos;
> -	attr.core_relo_cnt = sizeof(relos) / sizeof(*relos);
> +	attr.core_relo_cnt = ARRAY_SIZE(relos);
>  	attr.core_relo_rec_size = sizeof(*relos);
>  	prog_fd = sys_bpf_prog_load(&attr, sizeof(attr), 1);
>  	saved_errno = errno;
> -- 
> 2.32.0.3.g01195cf9f
> 

      reply	other threads:[~2024-09-30  7:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-29  9:28 Jiapeng Chong
2024-09-30  7:30 ` Tony Ambardar [this message]

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=ZvpTqammU0DqcKyz@kodidev-ubuntu \
    --to=tony.ambardar@gmail.com \
    --cc=abaci@linux.alibaba.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®