selftests/bpf: Fix the address is NULL
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 selftests/bpf: Fix the address is NULL
Fix the following coccicheck error:
tools/testing/selftests/bpf/progs/test_ksyms_weak.c:53:6-20: ERROR: test of a variable/field address
--- tools/testing/selftests/bpf/progs/test_ksyms_weak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/test_ksyms_weak.c +1 -1
@@ -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))
Quoted 3 lines · On 6/14/23 12:42 AM, [email protected] 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?
Quoted 21 lines
Signed-off-by Yonggang Wu <[email protected]>--- tools/testing/selftests/bpf/progs/test_ksyms_weak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/progs/test_ksyms_weak.c +1
-1@@ -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))
Quoted 6 lines · Yonghong Song
Quoted 2 lines · On 6/14/23 12:42 AM, [email protected] wrote:
Fix the following coccicheck error:
Quoted 8 lines
Quoted 2 lines
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.
Quoted 23 lines
Quoted 23 lines
Signed-off-by Yonggang Wu <[email protected]>--- tools/testing/selftests/bpf/progs/test_ksyms_weak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/progs/test_ksyms_weak.c +1
-1@@ -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))