Skip to content

Commit a2a5580

Browse files
bjdooks-sifiveanakryiko
authored andcommitted
bpf: Fix check against plain integer v 'NULL'
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> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220714100322.260467-1-ben.dooks@sifive.com
1 parent 9c7c48d commit a2a5580

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/bpf/btf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,8 @@ __printf(2, 3) static void btf_show(struct btf_show *show, const char *fmt, ...)
11161116
*/
11171117
#define btf_show_type_value(show, fmt, value) \
11181118
do { \
1119-
if ((value) != 0 || (show->flags & BTF_SHOW_ZERO) || \
1119+
if ((value) != (__typeof__(value))0 || \
1120+
(show->flags & BTF_SHOW_ZERO) || \
11201121
show->state.depth == 0) { \
11211122
btf_show(show, "%s%s" fmt "%s%s", \
11221123
btf_show_indent(show), \

0 commit comments

Comments
 (0)