aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/headers_check.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/headers_check.pl')
-rw-r--r--scripts/headers_check.pl70
1 files changed, 68 insertions, 2 deletions
diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
index 488a3b1f760f..db30fac3083e 100644
--- a/scripts/headers_check.pl
+++ b/scripts/headers_check.pl
@@ -14,7 +14,9 @@
14# Only include files located in asm* and linux* are checked. 14# Only include files located in asm* and linux* are checked.
15# The rest are assumed to be system include files. 15# The rest are assumed to be system include files.
16# 16#
17# 2) TODO: check for leaked CONFIG_ symbols 17# 2) It is checked that prototypes does not use "extern"
18#
19# 3) Check for leaked CONFIG_ symbols
18 20
19use strict; 21use strict;
20 22
@@ -32,7 +34,11 @@ foreach my $file (@files) {
32 $lineno = 0; 34 $lineno = 0;
33 while ($line = <FH>) { 35 while ($line = <FH>) {
34 $lineno++; 36 $lineno++;
35 check_include(); 37 &check_include();
38 &check_asm_types();
39 &check_sizetypes();
40 &check_prototypes();
41 &check_config();
36 } 42 }
37 close FH; 43 close FH;
38} 44}
@@ -54,3 +60,63 @@ sub check_include
54 } 60 }
55 } 61 }
56} 62}
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}
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
78my $linux_asm_types;
79sub check_asm_types()
80{
81 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
82 return;
83 }
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{
101 if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
102 return;
103 }
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