Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

checkpatch: do not apply "initialise globals to 0" check to BPF progs

BPF programs explicitly initialise global variables to 0 to make sure
clang (v10 or older) do not put the variables in the common section. Skip
"initialise globals to 0" check for BPF programs to elimiate error
messages like:

ERROR: do not initialise globals to 0
#19: FILE: samples/bpf/tracex1_kern.c:21:

Link: https://lkml.kernel.org/r/20210209211954.490077-1-songliubraving@fb.com
Signed-off-by: Song Liu <songliubraving@fb.com>
Acked-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Song Liu and committed by
Linus Torvalds
5b8f82e1 263afd39

+11 -1
+11 -1
scripts/checkpatch.pl
··· 2453 2453 return $comment; 2454 2454 } 2455 2455 2456 + sub exclude_global_initialisers { 2457 + my ($realfile) = @_; 2458 + 2459 + # Do not check for BPF programs (tools/testing/selftests/bpf/progs/*.c, samples/bpf/*_kern.c, *.bpf.c). 2460 + return $realfile =~ m@^tools/testing/selftests/bpf/progs/.*\.c$@ || 2461 + $realfile =~ m@^samples/bpf/.*_kern\.c$@ || 2462 + $realfile =~ m@/bpf/.*\.bpf\.c$@; 2463 + } 2464 + 2456 2465 sub process { 2457 2466 my $filename = shift; 2458 2467 ··· 4367 4358 } 4368 4359 4369 4360 # check for global initialisers. 4370 - if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) { 4361 + if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ && 4362 + !exclude_global_initialisers($realfile)) { 4371 4363 if (ERROR("GLOBAL_INITIALISERS", 4372 4364 "do not initialise globals to $1\n" . $herecurr) && 4373 4365 $fix) {