kernel/kallsyms.c: replace deprecated __initcall with device_initcall and fix whitespace
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / scripts / headers_check.pl
CommitLineData
15a2ee74 1#!/usr/bin/perl -w
7712401a
SR
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#
46b8af50
MF
17# 2) It is checked that prototypes does not use "extern"
18#
7e557a25 19# 3) Check for leaked CONFIG_ symbols
7712401a
SR
20
21use strict;
7712401a
SR
22
23my ($dir, $arch, @files) = @ARGV;
24
25my $ret = 0;
26my $line;
27my $lineno = 0;
28my $filename;
29
30foreach my $file (@files) {
15a2ee74 31 local *FH;
7712401a 32 $filename = $file;
15a2ee74 33 open(FH, "<$filename") or die "$filename: $!\n";
7712401a 34 $lineno = 0;
15a2ee74 35 while ($line = <FH>) {
7712401a 36 $lineno++;
483b4121
SR
37 &check_include();
38 &check_asm_types();
39 &check_sizetypes();
40 &check_prototypes();
7e3fa561 41 # Dropped for now. Too much noise &check_config();
7712401a 42 }
15a2ee74 43 close FH;
7712401a
SR
44}
45exit $ret;
46
47sub check_include
48{
49 if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
50 my $inc = $1;
51 my $found;
52 $found = stat($dir . "/" . $inc);
53 if (!$found) {
54 $inc =~ s#asm/#asm-$arch/#;
55 $found = stat($dir . "/" . $inc);
56 }
57 if (!$found) {
58 printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
59 $ret = 1;
60 }
61 }
62}
46b8af50
MF
63
64sub check_prototypes
65{
66 if ($line =~ m/^\s*extern\b/) {
67 printf STDERR "$filename:$lineno: extern's make no sense in userspace\n";
68 }
69}
7e557a25
SR
70
71sub check_config
72{
73 if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9]+)[^a-zA-Z0-9]/) {
74 printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n";
75 }
76}
77
483b4121
SR
78my $linux_asm_types;
79sub check_asm_types()
80{
b67ff8ce
SR
81 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
82 return;
83 }
483b4121
SR
84 if ($lineno == 1) {
85 $linux_asm_types = 0;
86 } elsif ($linux_asm_types >= 1) {
87 return;
88 }
89 if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
90 $linux_asm_types = 1;
91 printf STDERR "$filename:$lineno: " .
92 "include of <linux/types.h> is preferred over <asm/types.h>\n"
93 # Warn until headers are all fixed
94 #$ret = 1;
95 }
96}
97
98my $linux_types;
99sub check_sizetypes
100{
b67ff8ce
SR
101 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
102 return;
103 }
483b4121
SR
104 if ($lineno == 1) {
105 $linux_types = 0;
106 } elsif ($linux_types >= 1) {
107 return;
108 }
109 if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
110 $linux_types = 1;
111 return;
112 }
113 if ($line =~ m/__[us](8|16|32|64)\b/) {
114 printf STDERR "$filename:$lineno: " .
115 "found __[us]{8,16,32,64} type " .
116 "without #include <linux/types.h>\n";
117 $linux_types = 2;
118 # Warn until headers are all fixed
119 #$ret = 1;
120 }
121}
122