| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 |
|
| 21 | use warnings;
|
| 22 | use strict;
|
| 23 | use File::Basename;
|
| 24 |
|
| 25 | my ($dir, @files) = @ARGV;
|
| 26 |
|
| 27 | my $ret = 0;
|
| 28 | my $line;
|
| 29 | my $lineno = 0;
|
| 30 | my $filename;
|
| 31 |
|
| 32 | foreach my $file (@files) {
|
| 33 | $filename = $file;
|
| 34 |
|
| 35 | open(my $fh, '<', $filename)
|
| 36 | or die "$filename: $!\n";
|
| 37 | $lineno = 0;
|
| 38 | while ($line = <$fh>) {
|
| 39 | $lineno++;
|
| 40 | &check_include();
|
| 41 | &check_asm_types();
|
| 42 | &check_declarations();
|
| 43 | }
|
| 44 | close $fh;
|
| 45 | }
|
| 46 | exit $ret;
|
| 47 |
|
| 48 | sub check_include
|
| 49 | {
|
| 50 | if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
|
| 51 | my $inc = $1;
|
| 52 | my $found;
|
| 53 | $found = stat($dir . "/" . $inc);
|
| 54 | if (!$found) {
|
| 55 | printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
|
| 56 | $ret = 1;
|
| 57 | }
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | sub check_declarations
|
| 62 | {
|
| 63 | |
| 64 | if ($line =~ m/^void seqbuf_dump\(void\);/) {
|
| 65 | return;
|
| 66 | }
|
| 67 | |
| 68 | if ($line =~ m/^extern "C"/) {
|
| 69 | return;
|
| 70 | }
|
| 71 | if ($line =~ m/^(\s*extern|unsigned|char|short|int|long|void)\b/) {
|
| 72 | printf STDERR "$filename:$lineno: " .
|
| 73 | "userspace cannot reference function or " .
|
| 74 | "variable defined in the kernel\n";
|
| 75 | $ret = 1;
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | my $linux_asm_types;
|
| 80 | sub check_asm_types
|
| 81 | {
|
| 82 | if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
|
| 83 | return;
|
| 84 | }
|
| 85 | if ($lineno == 1) {
|
| 86 | $linux_asm_types = 0;
|
| 87 | } elsif ($linux_asm_types >= 1) {
|
| 88 | return;
|
| 89 | }
|
| 90 | if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
|
| 91 | $linux_asm_types = 1;
|
| 92 | printf STDERR "$filename:$lineno: " .
|
| 93 | "include of <linux/types.h> is preferred over <asm/types.h>\n";
|
| 94 | $ret = 1;
|
| 95 | }
|
| 96 | }
|