diff mbox series

selftests/bpf: Fix the address is NULL

Message ID 7f34bd3ce377d9d89626c2df8fa584e0@208suo.com (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series selftests/bpf: Fix the address is NULL | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for veristat

Commit Message

Yonggang Wu June 14, 2023, 7:42 a.m. UTC
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(-)

      if (!bpf_ksym_exists(bpf_task_acquire))

Comments

Yonghong Song June 14, 2023, 2:08 p.m. UTC | #1
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))
>
Andrii Nakryiko June 16, 2023, 4:33 p.m. UTC | #2
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))
> >
diff mbox series

Patch

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);