| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 |
|
| 21 | use strict;
|
| 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) {
|
| 31 | $filename = $file;
|
| 32 |
|
| 33 | open(my $fh, '<', $filename)
|
| 34 | or die "$filename: $!\n";
|
| 35 | $lineno = 0;
|
| 36 | while ($line = <$fh>) {
|
| 37 | $lineno++;
|
| 38 | &check_include();
|
| 39 | &check_asm_types();
|
| 40 | &check_sizetypes();
|
| 41 | &check_declarations();
|
| 42 | |
| 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 | $inc =~ s |
| 56 | $found = stat($dir . "/" . $inc);
|
| 57 | }
|
| 58 | if (!$found) {
|
| 59 | printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
|
| 60 | $ret = 1;
|
| 61 | }
|
| 62 | }
|
| 63 | }
|
| 64 |
|
| 65 | sub check_declarations
|
| 66 | {
|
| 67 | if ($line =~m/^\s*extern\b/) {
|
| 68 | printf STDERR "$filename:$lineno: " .
|
| 69 | "userspace cannot call function or variable " .
|
| 70 | "defined in the kernel\n";
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | sub check_config
|
| 75 | {
|
| 76 | if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
|
| 77 | printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n";
|
| 78 | }
|
| 79 | }
|
| 80 |
|
| 81 | my $linux_asm_types;
|
| 82 | sub check_asm_types
|
| 83 | {
|
| 84 | if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
|
| 85 | return;
|
| 86 | }
|
| 87 | if ($lineno == 1) {
|
| 88 | $linux_asm_types = 0;
|
| 89 | } elsif ($linux_asm_types >= 1) {
|
| 90 | return;
|
| 91 | }
|
| 92 | if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
|
| 93 | $linux_asm_types = 1;
|
| 94 | printf STDERR "$filename:$lineno: " .
|
| 95 | "include of <linux/types.h> is preferred over <asm/types.h>\n"
|
| 96 | |
| 97 | |
| 98 | }
|
| 99 | }
|
| 100 |
|
| 101 | my $linux_types;
|
| 102 | sub check_sizetypes
|
| 103 | {
|
| 104 | if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
|
| 105 | return;
|
| 106 | }
|
| 107 | if ($lineno == 1) {
|
| 108 | $linux_types = 0;
|
| 109 | } elsif ($linux_types >= 1) {
|
| 110 | return;
|
| 111 | }
|
| 112 | if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
|
| 113 | $linux_types = 1;
|
| 114 | return;
|
| 115 | }
|
| 116 | if ($line =~ m/__[us](8|16|32|64)\b/) {
|
| 117 | printf STDERR "$filename:$lineno: " .
|
| 118 | "found __[us]{8,16,32,64} type " .
|
| 119 | "without #include <linux/types.h>\n";
|
| 120 | $linux_types = 2;
|
| 121 | |
| 122 | |
| 123 | }
|
| 124 | }
|
| 125 |
|