3 # headers_check.pl execute a number of trivial consistency checks
5 # Usage: headers_check.pl dir arch [files...]
6 # dir: dir to look for included files
8 # files: list of files to check
10 # The script reads the supplied files line by line and:
12 # 1) for each include statement it checks if the
13 # included file actually exists.
14 # Only include files located in asm* and linux* are checked.
15 # The rest are assumed to be system include files.
17 # 2) It is checked that prototypes does not use "extern"
19 # 3) Check for leaked CONFIG_ symbols
24 my ($dir, $arch, @files) = @ARGV;
31 foreach my $file (@files) {
34 open(my $fh, '<', $filename)
35 or die "$filename: $!\n";
37 while ($line = <$fh>) {
42 &check_declarations();
43 # Dropped for now. Too much noise &check_config();
51 if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
54 $found = stat($dir . "/" . $inc);
56 $inc =~ s#asm/#asm-$arch/#;
57 $found = stat($dir . "/" . $inc);
60 printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
66 sub check_declarations
68 # soundcard.h is what it is
69 if ($line =~ m/^void seqbuf_dump\(void\);/) {
72 # drm headers are being C++ friendly
73 if ($line =~ m/^extern "C"/) {
76 if ($line =~ m/^(\s*extern|unsigned|char|short|int|long|void)\b/) {
77 printf STDERR "$filename:$lineno: " .
78 "userspace cannot reference function or " .
79 "variable defined in the kernel\n";
85 if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
86 printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n";
93 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
98 } elsif ($linux_asm_types >= 1) {
101 if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
102 $linux_asm_types = 1;
103 printf STDERR "$filename:$lineno: " .
104 "include of <linux/types.h> is preferred over <asm/types.h>\n"
105 # Warn until headers are all fixed
111 my %import_stack = ();
112 sub check_include_typesh
118 my @file_paths = ($path, $dir . "/" . $path, dirname($filename) . "/" . $path);
119 for my $possible ( @file_paths ) {
120 if (not $import_stack{$possible} and open($fh, '<', $possible)) {
121 $import_path = $possible;
122 $import_stack{$import_path} = 1;
131 while ($line = <$fh>) {
132 if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
136 if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
137 check_include_typesh($included);
141 delete $import_stack{$import_path};
146 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
151 } elsif ($linux_types >= 1) {
154 if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
158 if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
159 check_include_typesh($included);
161 if ($line =~ m/__[us](8|16|32|64)\b/) {
162 printf STDERR "$filename:$lineno: " .
163 "found __[us]{8,16,32,64} type " .
164 "without #include <linux/types.h>\n";
166 # Warn until headers are all fixed