* [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error
@ 2024-06-24 19:54 Thorsten Blum
2024-06-24 20:15 ` Alexei Starovoitov
2024-06-24 20:16 ` Eduard Zingerman
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2024-06-24 19:54 UTC (permalink / raw)
To: martin.lau, ast, daniel, andrii, eddyz87, song, john.fastabend,
kpsingh, sdf, haoluo, jolsa, yonghong.song, bpf, linux-kernel
Cc: Thorsten Blum
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);
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error
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
1 sibling, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2024-06-24 20:15 UTC (permalink / raw)
To: Thorsten Blum
Cc: Martin KaFai Lau, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Eddy Z, Song Liu, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, Jiri Olsa, Yonghong Song, bpf, LKML
On Mon, Jun 24, 2024 at 12:56 PM Thorsten Blum <thorsten.blum@toblux.com> 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, ",");
Sorry, I don't think this is a sustainable approach.
We cannot fix such things all over the kernel.
Pls make cocci smarter instead.
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error
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
2024-06-24 23:08 ` Thorsten Blum
1 sibling, 1 reply; 5+ messages in thread
From: Eduard Zingerman @ 2024-06-24 20:16 UTC (permalink / raw)
To: Thorsten Blum, martin.lau, ast, daniel, andrii, song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, yonghong.song, bpf,
linux-kernel
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?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error
2024-06-24 20:16 ` Eduard Zingerman
@ 2024-06-24 23:08 ` Thorsten Blum
2024-06-24 23:27 ` Eduard Zingerman
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2024-06-24 23:08 UTC (permalink / raw)
To: Eduard Zingerman
Cc: martin.lau, ast, daniel, andrii, song, john.fastabend, kpsingh,
sdf, haoluo, jolsa, yonghong.song, bpf, linux-kernel
On 24. Jun 2024, at 13:16, Eduard Zingerman <eddyz87@gmail.com> wrote:
> 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?
Coccinelle thinks i can't be a NULL pointer (not the number zero). It's
essentially a false-positive warning, but since there are only 4 such
warnings under kernel/, I thought it would be worthwhile to remove some
of them by making the tests explicit.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf, btf: Make if test explicit to fix Coccinelle error
2024-06-24 23:08 ` Thorsten Blum
@ 2024-06-24 23:27 ` Eduard Zingerman
0 siblings, 0 replies; 5+ messages in thread
From: Eduard Zingerman @ 2024-06-24 23:27 UTC (permalink / raw)
To: Thorsten Blum
Cc: martin.lau, ast, daniel, andrii, song, john.fastabend, kpsingh,
sdf, haoluo, jolsa, yonghong.song, bpf, linux-kernel
On Mon, 2024-06-24 at 16:08 -0700, Thorsten Blum wrote:
> On 24. Jun 2024, at 13:16, Eduard Zingerman <eddyz87@gmail.com> wrote:
> > 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
[...]
> > #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?
>
> Coccinelle thinks i can't be a NULL pointer (not the number zero). It's
> essentially a false-positive warning, but since there are only 4 such
> warnings under kernel/, I thought it would be worthwhile to remove some
> of them by making the tests explicit.
Sorry, not really familiar with the tool, but it seems like the
following part of the itnull.cocci fires the warning:
@r depends on !patch exists@
iterator I;
expression x,E;
position p1,p2;
@@
*I@p1(x,...)
{ ... when != x = E
(
* x@p2 == NULL
|
* x@p2 != NULL
)
... when any
}
@script:python depends on org@
p1 << r.p1;
p2 << r.p2;
@@
cocci.print_main("iterator-bound variable",p1)
cocci.print_secs("useless NULL test",p2)
@script:python depends on report@
p1 << r.p1;
p2 << r.p2;
@@
msg = "ERROR: iterator variable bound on line %s cannot be NULL" % (p1[0].line)
coccilib.report.print_report(p2[0], msg)
Is there a way to add a constraint here, requiring 'x' to have a pointer type?
(So that the rule does not match, as it clearly shouldn't).
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-24 23:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-06-24 23:08 ` Thorsten Blum
2024-06-24 23:27 ` Eduard Zingerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox