Skip to content

Commit 9c95e41

Browse files
liu-song-6kernel-patches-bot
authored andcommitted
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: Cc: Andy Whitcroft <[email protected]> Cc: Joe Perches <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent 1f4d2b7 commit 9c95e41

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

scripts/checkpatch.pl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,15 @@ sub get_raw_comment {
24282428
return $comment;
24292429
}
24302430

2431+
sub exclude_global_initialisers {
2432+
my ($realfile) = @_;
2433+
2434+
# Do not check for BPF programs (tools/testing/selftests/bpf/progs/*.c, samples/bpf/*_kern.c, *.bpf.c).
2435+
return $realfile =~ m@/^tools\/testing\/selftests\/bpf\/progs\/.*\.c@ ||
2436+
$realfile =~ m@^samples\/bpf\/.*_kern.c@ ||
2437+
$realfile =~ m@/bpf/.*\.bpf\.c$@;
2438+
}
2439+
24312440
sub process {
24322441
my $filename = shift;
24332442

@@ -4330,7 +4339,8 @@ sub process {
43304339
}
43314340

43324341
# check for global initialisers.
4333-
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) {
4342+
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ &&
4343+
!exclude_global_initialisers($realfile)) {
43344344
if (ERROR("GLOBAL_INITIALISERS",
43354345
"do not initialise globals to $1\n" . $herecurr) &&
43364346
$fix) {

0 commit comments

Comments
 (0)