BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Thorsten Blum <thorsten.blum@toblux.com>,
	martin.lau@linux.dev,  ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, song@kernel.org,  john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	 jolsa@kernel.org, yonghong.song@linux.dev, bpf@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error
Date: Mon, 24 Jun 2024 13:16:00 -0700	[thread overview]
Message-ID: <faf99c63015c6a5f619d85bd45405b91a3498bf9.camel@gmail.com> (raw)
In-Reply-To: <20240624195426.176827-2-thorsten.blum@toblux.com>

On Mon, 2024-06-24 at 21:54 +0200, Thorsten Blum wrote:
> Explicitly test the iterator variable i > 0 to fix the following
> Coccinelle/coccicheck error reported by itnull.cocci:
> 
> 	ERROR: iterator variable bound on line 4688 cannot be NULL
> 
> Compile-tested only.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  kernel/bpf/btf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 821063660d9f..7720f8967814 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -4687,7 +4687,7 @@ static void btf_datasec_show(const struct btf *btf,
>  			    __btf_name_by_offset(btf, t->name_off));
>  	for_each_vsi(i, t, vsi) {
>  		var = btf_type_by_id(btf, vsi->type);
> -		if (i)
> +		if (i > 0)
>  			btf_show(show, ",");
>  		btf_type_ops(var)->show(btf, var, vsi->type,
>  					data + vsi->offset, bits_offset, show);

Could you please elaborate a bit?
Here is for_each_vsi is defined:

#define for_each_vsi(i, datasec_type, member)			\
	for (i = 0, member = btf_type_var_secinfo(datasec_type);	\
	     i < btf_type_vlen(datasec_type);			\
	     i++, member++)

Here it sets 'i' to zero for the first iteration.
Why would the tool report that 'i' can't be zero?

  parent reply	other threads:[~2024-06-24 20:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 19:54 [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error Thorsten Blum
2024-06-24 20:15 ` Alexei Starovoitov
2024-06-24 20:16 ` Eduard Zingerman [this message]
2024-06-24 23:08   ` Thorsten Blum
2024-06-24 23:27     ` Eduard Zingerman

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=faf99c63015c6a5f619d85bd45405b91a3498bf9.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=thorsten.blum@toblux.com \
    --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