bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: fix check against plain integer v 'NULL'
@ 2022-07-14 10:03 Ben Dooks
  2022-07-14 20:28 ` Yonghong Song
  2022-07-15 17:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Dooks @ 2022-07-14 10:03 UTC (permalink / raw)
  To: linux-kernel, bpf; +Cc: Sudip Mukherjee, Jude Onyenegecha, Ben Dooks

When checking with sparse, btf_show_type_value() is causing a
warning about checking integer vs NULL when the macro is passed
a pointer, due to the 'value != 0' check. Stop sparse complaining
about any type-casting by adding a cast to the typeof(value).

This fixes the following sparse warnings:

kernel/bpf/btf.c:2579:17: warning: Using plain integer as NULL pointer
kernel/bpf/btf.c:2581:17: warning: Using plain integer as NULL pointer
kernel/bpf/btf.c:3407:17: warning: Using plain integer as NULL pointer
kernel/bpf/btf.c:3758:9: warning: Using plain integer as NULL pointer

Signed-off-by: Ben Dooks <ben.dooks@sifive.com>
---
 kernel/bpf/btf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index eb12d4f705cc..9a6e5f71bbd2 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -1108,7 +1108,8 @@ __printf(2, 3) static void btf_show(struct btf_show *show, const char *fmt, ...)
  */
 #define btf_show_type_value(show, fmt, value)				       \
 	do {								       \
-		if ((value) != 0 || (show->flags & BTF_SHOW_ZERO) ||	       \
+		if ((value) != (__typeof__(value))0 ||			       \
+		    (show->flags & BTF_SHOW_ZERO) ||			       \
 		    show->state.depth == 0) {				       \
 			btf_show(show, "%s%s" fmt "%s%s",		       \
 				 btf_show_indent(show),			       \
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: fix check against plain integer v 'NULL'
  2022-07-14 10:03 [PATCH] bpf: fix check against plain integer v 'NULL' Ben Dooks
@ 2022-07-14 20:28 ` Yonghong Song
  2022-07-15 17:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Yonghong Song @ 2022-07-14 20:28 UTC (permalink / raw)
  To: Ben Dooks, linux-kernel, bpf; +Cc: Sudip Mukherjee, Jude Onyenegecha



On 7/14/22 3:03 AM, Ben Dooks wrote:
> When checking with sparse, btf_show_type_value() is causing a
> warning about checking integer vs NULL when the macro is passed
> a pointer, due to the 'value != 0' check. Stop sparse complaining
> about any type-casting by adding a cast to the typeof(value).
> 
> This fixes the following sparse warnings:
> 
> kernel/bpf/btf.c:2579:17: warning: Using plain integer as NULL pointer
> kernel/bpf/btf.c:2581:17: warning: Using plain integer as NULL pointer
> kernel/bpf/btf.c:3407:17: warning: Using plain integer as NULL pointer
> kernel/bpf/btf.c:3758:9: warning: Using plain integer as NULL pointer
> 
> Signed-off-by: Ben Dooks <ben.dooks@sifive.com>

Acked-by: Yonghong Song <yhs@fb.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: fix check against plain integer v 'NULL'
  2022-07-14 10:03 [PATCH] bpf: fix check against plain integer v 'NULL' Ben Dooks
  2022-07-14 20:28 ` Yonghong Song
@ 2022-07-15 17:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-15 17:00 UTC (permalink / raw)
  To: Ben Dooks; +Cc: linux-kernel, bpf, sudip.mukherjee, jude.onyenegecha

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu, 14 Jul 2022 11:03:22 +0100 you wrote:
> When checking with sparse, btf_show_type_value() is causing a
> warning about checking integer vs NULL when the macro is passed
> a pointer, due to the 'value != 0' check. Stop sparse complaining
> about any type-casting by adding a cast to the typeof(value).
> 
> This fixes the following sparse warnings:
> 
> [...]

Here is the summary with links:
  - bpf: fix check against plain integer v 'NULL'
    https://git.kernel.org/bpf/bpf-next/c/a2a5580fcbf8

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-15 17:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-14 10:03 [PATCH] bpf: fix check against plain integer v 'NULL' Ben Dooks
2022-07-14 20:28 ` Yonghong Song
2022-07-15 17:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).