[PATCH] selftests/bpf: Fix warning comparing pointer to 0

Haowen Bai posted 1 patch 4 years, 2 months ago
There is a newer version of this series
tools/testing/selftests/bpf/progs/map_ptr_kern.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] selftests/bpf: Fix warning comparing pointer to 0
Posted by Haowen Bai 4 years, 2 months ago
Avoid pointer type value compared with 0 to make code clear.

Signed-off-by: Haowen Bai <baihaowen@meizu.com>
---
 tools/testing/selftests/bpf/progs/map_ptr_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
index b64df94..db388f5 100644
--- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
+++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
@@ -367,7 +367,7 @@ static inline int check_array_of_maps(void)
 
 	VERIFY(check_default(&array_of_maps->map, map));
 	inner_map = bpf_map_lookup_elem(array_of_maps, &key);
-	VERIFY(inner_map != 0);
+	VERIFY(inner_map != NULL);
 	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
 
 	return 1;
@@ -394,7 +394,7 @@ static inline int check_hash_of_maps(void)
 
 	VERIFY(check_default(&hash_of_maps->map, map));
 	inner_map = bpf_map_lookup_elem(hash_of_maps, &key);
-	VERIFY(inner_map != 0);
+	VERIFY(inner_map != NULL);
 	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
 
 	return 1;
-- 
2.7.4
Re: [PATCH] selftests/bpf: Fix warning comparing pointer to 0
Posted by Martin KaFai Lau 4 years, 2 months ago
On Thu, Mar 24, 2022 at 10:08:45AM +0800, Haowen Bai wrote:
> Avoid pointer type value compared with 0 to make code clear.
Which compiler version that warns ?
I don't see it with the latest llvm-project from github.

The patch lgtm.

Acked-by: Martin KaFai Lau <kafai@fb.com>
答复: [PATCH] selftests/bpf: Fix warning comparing pointer to 0
Posted by 白浩文 4 years, 2 months ago
hi, kafai

./scripts/coccicheck report this warning.
________________________________________
发件人: Martin KaFai Lau <kafai@fb.com>
发送时间: 2022年3月25日 4:28:48
收件人: 白浩文
抄送: shuah@kernel.org; ast@kernel.org; daniel@iogearbox.net; andrii@kernel.org; songliubraving@fb.com; yhs@fb.com; john.fastabend@gmail.com; kpsingh@kernel.org; linux-kselftest@vger.kernel.org; netdev@vger.kernel.org; bpf@vger.kernel.org; linux-kernel@vger.kernel.org
主题: Re: [PATCH] selftests/bpf: Fix warning comparing pointer to 0

On Thu, Mar 24, 2022 at 10:08:45AM +0800, Haowen Bai wrote:
> Avoid pointer type value compared with 0 to make code clear.
Which compiler version that warns ?
I don't see it with the latest llvm-project from github.

The patch lgtm.

Acked-by: Martin KaFai Lau <kafai@fb.com>
Re: [PATCH] selftests/bpf: Fix warning comparing pointer to 0
Posted by Shuah Khan 4 years, 2 months ago
On 3/23/22 8:08 PM, Haowen Bai wrote:
> Avoid pointer type value compared with 0 to make code clear.
> 

Patch looks good to me. Please include the error/warn message
in the commit log. This gives reviewers information on how
this problem is found.

> Signed-off-by: Haowen Bai <baihaowen@meizu.com>
> ---
>   tools/testing/selftests/bpf/progs/map_ptr_kern.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> index b64df94..db388f5 100644
> --- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> +++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> @@ -367,7 +367,7 @@ static inline int check_array_of_maps(void)
>   
>   	VERIFY(check_default(&array_of_maps->map, map));
>   	inner_map = bpf_map_lookup_elem(array_of_maps, &key);
> -	VERIFY(inner_map != 0);
> +	VERIFY(inner_map != NULL);
>   	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
>   
>   	return 1;
> @@ -394,7 +394,7 @@ static inline int check_hash_of_maps(void)
>   
>   	VERIFY(check_default(&hash_of_maps->map, map));
>   	inner_map = bpf_map_lookup_elem(hash_of_maps, &key);
> -	VERIFY(inner_map != 0);
> +	VERIFY(inner_map != NULL);
>   	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
>   
>   	return 1;
> 

With the change to commit log including the error/warn message and
details on how the problems is found:

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah
[PATCH V2] selftests/bpf: Fix warning comparing pointer to 0
Posted by Haowen Bai 4 years, 2 months ago
Avoid pointer type value compared with 0 to make code clear.

reported by coccicheck:
tools/testing/selftests/bpf/progs/map_ptr_kern.c:370:21-22:
WARNING comparing pointer to 0
tools/testing/selftests/bpf/progs/map_ptr_kern.c:397:21-22:
WARNING comparing pointer to 0

Signed-off-by: Haowen Bai <baihaowen@meizu.com>
---
V1->V2: include the error/warn message.

 tools/testing/selftests/bpf/progs/map_ptr_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
index b64df94..db388f5 100644
--- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
+++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
@@ -367,7 +367,7 @@ static inline int check_array_of_maps(void)
 
 	VERIFY(check_default(&array_of_maps->map, map));
 	inner_map = bpf_map_lookup_elem(array_of_maps, &key);
-	VERIFY(inner_map != 0);
+	VERIFY(inner_map != NULL);
 	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
 
 	return 1;
@@ -394,7 +394,7 @@ static inline int check_hash_of_maps(void)
 
 	VERIFY(check_default(&hash_of_maps->map, map));
 	inner_map = bpf_map_lookup_elem(hash_of_maps, &key);
-	VERIFY(inner_map != 0);
+	VERIFY(inner_map != NULL);
 	VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
 
 	return 1;
-- 
2.7.4
Re: [PATCH V2] selftests/bpf: Fix warning comparing pointer to 0
Posted by Yonghong Song 4 years, 2 months ago

On 3/29/22 6:59 PM, Haowen Bai wrote:
> Avoid pointer type value compared with 0 to make code clear.
> 
> reported by coccicheck:
> tools/testing/selftests/bpf/progs/map_ptr_kern.c:370:21-22:
> WARNING comparing pointer to 0
> tools/testing/selftests/bpf/progs/map_ptr_kern.c:397:21-22:
> WARNING comparing pointer to 0
> 
> Signed-off-by: Haowen Bai <baihaowen@meizu.com>

Acked-by: Yonghong Song <yhs@fb.com>
Re: [PATCH V2] selftests/bpf: Fix warning comparing pointer to 0
Posted by patchwork-bot+netdevbpf@kernel.org 4 years, 2 months ago
Hello:

This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed, 30 Mar 2022 09:59:48 +0800 you wrote:
> Avoid pointer type value compared with 0 to make code clear.
> 
> reported by coccicheck:
> tools/testing/selftests/bpf/progs/map_ptr_kern.c:370:21-22:
> WARNING comparing pointer to 0
> tools/testing/selftests/bpf/progs/map_ptr_kern.c:397:21-22:
> WARNING comparing pointer to 0
> 
> [...]

Here is the summary with links:
  - [V2] selftests/bpf: Fix warning comparing pointer to 0
    https://git.kernel.org/bpf/bpf/c/2609f635a20d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html