Skip to content

Commit 5b8f82e

Browse files
liu-song-6torvalds
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: Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Song Liu <[email protected]> Acked-by: Joe Perches <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 263afd3 commit 5b8f82e

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
@@ -2453,6 +2453,15 @@ sub get_raw_comment {
24532453
return $comment;
24542454
}
24552455

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+
24562465
sub process {
24572466
my $filename = shift;
24582467

@@ -4358,7 +4367,8 @@ sub process {
43584367
}
43594368

43604369
# check for global initialisers.
4361-
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) {
4370+
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ &&
4371+
!exclude_global_initialisers($realfile)) {
43624372
if (ERROR("GLOBAL_INITIALISERS",
43634373
"do not initialise globals to $1\n" . $herecurr) &&
43644374
$fix) {

0 commit comments

Comments
 (0)