Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 2 | # |
| 3 | # headers_check.pl execute a number of trivial consistency checks |
| 4 | # |
| 5 | # Usage: headers_check.pl dir [files...] |
| 6 | # dir: dir to look for included files |
| 7 | # arch: architecture |
| 8 | # files: list of files to check |
| 9 | # |
| 10 | # The script reads the supplied files line by line and: |
| 11 | # |
| 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. |
| 16 | # |
Mike Frysinger | 46b8af5 | 2008-12-27 02:43:36 -0500 | [diff] [blame] | 17 | # 2) It is checked that prototypes does not use "extern" |
| 18 | # |
Sam Ravnborg | 7e557a2 | 2008-12-27 19:52:20 +0100 | [diff] [blame^] | 19 | # 3) Check for leaked CONFIG_ symbols |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 20 | |
| 21 | use strict; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 22 | |
| 23 | my ($dir, $arch, @files) = @ARGV; |
| 24 | |
| 25 | my $ret = 0; |
| 26 | my $line; |
| 27 | my $lineno = 0; |
| 28 | my $filename; |
| 29 | |
| 30 | foreach my $file (@files) { |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 31 | local *FH; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 32 | $filename = $file; |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 33 | open(FH, "<$filename") or die "$filename: $!\n"; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 34 | $lineno = 0; |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 35 | while ($line = <FH>) { |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 36 | $lineno++; |
| 37 | check_include(); |
Mike Frysinger | 46b8af5 | 2008-12-27 02:43:36 -0500 | [diff] [blame] | 38 | check_prototypes(); |
Sam Ravnborg | 7e557a2 | 2008-12-27 19:52:20 +0100 | [diff] [blame^] | 39 | check_config(); |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 40 | } |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 41 | close FH; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 42 | } |
| 43 | exit $ret; |
| 44 | |
| 45 | sub check_include |
| 46 | { |
| 47 | if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) { |
| 48 | my $inc = $1; |
| 49 | my $found; |
| 50 | $found = stat($dir . "/" . $inc); |
| 51 | if (!$found) { |
| 52 | $inc =~ s#asm/#asm-$arch/#; |
| 53 | $found = stat($dir . "/" . $inc); |
| 54 | } |
| 55 | if (!$found) { |
| 56 | printf STDERR "$filename:$lineno: included file '$inc' is not exported\n"; |
| 57 | $ret = 1; |
| 58 | } |
| 59 | } |
| 60 | } |
Mike Frysinger | 46b8af5 | 2008-12-27 02:43:36 -0500 | [diff] [blame] | 61 | |
| 62 | sub check_prototypes |
| 63 | { |
| 64 | if ($line =~ m/^\s*extern\b/) { |
| 65 | printf STDERR "$filename:$lineno: extern's make no sense in userspace\n"; |
| 66 | } |
| 67 | } |
Sam Ravnborg | 7e557a2 | 2008-12-27 19:52:20 +0100 | [diff] [blame^] | 68 | |
| 69 | sub check_config |
| 70 | { |
| 71 | if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9]+)[^a-zA-Z0-9]/) { |
| 72 | printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n"; |
| 73 | } |
| 74 | } |
| 75 | |