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
25 my ($dir, $arch, @files) = @ARGV;
32 foreach my $file (@files) {
35 open(my $fh, '<', $filename)
36 or die "$filename: $!\n";
38 while ($line = <$fh>) {
43 &check_declarations();
44 # Dropped for now. Too much noise &check_config();
52 if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
55 $found = stat($dir . "/" . $inc);
57 $inc =~ s#asm/#asm-$arch/#;
58 $found = stat($dir . "/" . $inc);
61 printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
67 sub check_declarations
69 # soundcard.h is what it is
70 if ($line =~ m/^void seqbuf_dump\(void\);/) {
73 # drm headers are being C++ friendly
74 if ($line =~ m/^extern "C"/) {
77 if ($line =~ m/^(\s*extern|unsigned|char|short|int|long|void)\b/) {
78 printf STDERR "$filename:$lineno: " .
79 "userspace cannot reference function or " .
80 "variable defined in the kernel\n";
86 if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
87 printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n";
94 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
99 } elsif ($linux_asm_types >= 1) {
102 if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
103 $linux_asm_types = 1;
104 printf STDERR "$filename:$lineno: " .
105 "include of <linux/types.h> is preferred over <asm/types.h>\n"
106 # Warn until headers are all fixed
112 my %import_stack = ();
113 sub check_include_typesh
119 my @file_paths = ($path, $dir . "/" . $path, dirname($filename) . "/" . $path);
120 for my $possible ( @file_paths ) {
121 if (not $import_stack{$possible} and open($fh, '<', $possible)) {
122 $import_path = $possible;
123 $import_stack{$import_path} = 1;
132 while ($line = <$fh>) {
133 if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
137 if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
138 check_include_typesh($included);
142 delete $import_stack{$import_path};
147 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
152 } elsif ($linux_types >= 1) {
155 if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
159 if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
160 check_include_typesh($included);
162 if ($line =~ m/__[us](8|16|32|64)\b/) {
163 printf STDERR "$filename:$lineno: " .
164 "found __[us]{8,16,32,64} type " .
165 "without #include <linux/types.h>\n";
167 # Warn until headers are all fixed