* [PATCH] selftests/bpf: Fix the address is NULL
[not found] <20230614073443.4894-1-zhanglibing@cdjrlc.com>
@ 2023-06-14 7:42 ` wuyonggang001
2023-06-14 14:08 ` Yonghong Song
0 siblings, 1 reply; 3+ messages in thread
From: wuyonggang001 @ 2023-06-14 7:42 UTC (permalink / raw)
To: andrii, shuah; +Cc: bpf, linux-kselftest, linux-kernel
Fix the following coccicheck error:
tools/testing/selftests/bpf/progs/test_ksyms_weak.c:53:6-20: ERROR: test
of a variable/field address
Signed-off-by: Yonggang Wu <wuyonggang001@208suo.com>
---
tools/testing/selftests/bpf/progs/test_ksyms_weak.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
b/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
index d00268c91e19..768a4d6ee6f5 100644
--- a/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
+++ b/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
@@ -50,7 +50,7 @@ int pass_handler(const void *ctx)
/* tests non-existent symbols. */
out__non_existent_typed = (__u64)&bpf_link_fops2;
- if (&bpf_link_fops2) /* can't happen */
+ if (&bpf_link_fops2 != NULL) /* can't happen */
out__non_existent_typed =
(__u64)bpf_per_cpu_ptr(&bpf_link_fops2, 0);
if (!bpf_ksym_exists(bpf_task_acquire))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/bpf: Fix the address is NULL
2023-06-14 7:42 ` [PATCH] selftests/bpf: Fix the address is NULL wuyonggang001
@ 2023-06-14 14:08 ` Yonghong Song
2023-06-16 16:33 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2023-06-14 14:08 UTC (permalink / raw)
To: wuyonggang001, andrii, shuah; +Cc: bpf, linux-kselftest, linux-kernel
On 6/14/23 12:42 AM, wuyonggang001@208suo.com wrote:
> Fix the following coccicheck error:
>
> tools/testing/selftests/bpf/progs/test_ksyms_weak.c:53:6-20: ERROR: test
> of a variable/field address
I didn't see clang/gcc compiler warns about this. Maybe need some
additional flags beyond what current selftest/bpf already has
in order to trigger this warning?
If you feel this warning has some merit, could you propose
it to gcc/llvm community?
>
> Signed-off-by: Yonggang Wu <wuyonggang001@208suo.com>
> ---
> tools/testing/selftests/bpf/progs/test_ksyms_weak.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> b/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> index d00268c91e19..768a4d6ee6f5 100644
> --- a/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> +++ b/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> @@ -50,7 +50,7 @@ int pass_handler(const void *ctx)
> /* tests non-existent symbols. */
> out__non_existent_typed = (__u64)&bpf_link_fops2;
>
> - if (&bpf_link_fops2) /* can't happen */
> + if (&bpf_link_fops2 != NULL) /* can't happen */
> out__non_existent_typed =
> (__u64)bpf_per_cpu_ptr(&bpf_link_fops2, 0);
>
> if (!bpf_ksym_exists(bpf_task_acquire))
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/bpf: Fix the address is NULL
2023-06-14 14:08 ` Yonghong Song
@ 2023-06-16 16:33 ` Andrii Nakryiko
0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2023-06-16 16:33 UTC (permalink / raw)
To: Yonghong Song
Cc: wuyonggang001, andrii, shuah, bpf, linux-kselftest, linux-kernel
On Wed, Jun 14, 2023 at 7:09 AM Yonghong Song <yhs@meta.com> wrote:
>
>
>
> On 6/14/23 12:42 AM, wuyonggang001@208suo.com wrote:
> > Fix the following coccicheck error:
> >
> > tools/testing/selftests/bpf/progs/test_ksyms_weak.c:53:6-20: ERROR: test
> > of a variable/field address
>
> I didn't see clang/gcc compiler warns about this. Maybe need some
> additional flags beyond what current selftest/bpf already has
> in order to trigger this warning?
> If you feel this warning has some merit, could you propose
> it to gcc/llvm community?
bpf_link_fops2 is a weak symbol, this check is totally valid and reasonable.
There are two problems here, though:
a) coccicheck shouldn't warn about "test of a variable/field address"
for weak symbols, because they can be NULL.
b) this patch is not even fixing that warning, it does a no-op change
from implicit non-NULL check to explicit non-NULL check. And the
former is actually the preferred style.
So this patch is doubly wrong.
>
> >
> > Signed-off-by: Yonggang Wu <wuyonggang001@208suo.com>
> > ---
> > tools/testing/selftests/bpf/progs/test_ksyms_weak.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> > b/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> > index d00268c91e19..768a4d6ee6f5 100644
> > --- a/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> > +++ b/tools/testing/selftests/bpf/progs/test_ksyms_weak.c
> > @@ -50,7 +50,7 @@ int pass_handler(const void *ctx)
> > /* tests non-existent symbols. */
> > out__non_existent_typed = (__u64)&bpf_link_fops2;
> >
> > - if (&bpf_link_fops2) /* can't happen */
> > + if (&bpf_link_fops2 != NULL) /* can't happen */
> > out__non_existent_typed =
> > (__u64)bpf_per_cpu_ptr(&bpf_link_fops2, 0);
> >
> > if (!bpf_ksym_exists(bpf_task_acquire))
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-16 16:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230614073443.4894-1-zhanglibing@cdjrlc.com>
2023-06-14 7:42 ` [PATCH] selftests/bpf: Fix the address is NULL wuyonggang001
2023-06-14 14:08 ` Yonghong Song
2023-06-16 16:33 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox