2008-10-29 21:20:13 +00:00
|
|
|
#!/usr/bin/perl -w
|
2008-06-15 19:41:09 +00:00
|
|
|
#
|
|
|
|
# headers_check.pl execute a number of trivial consistency checks
|
|
|
|
#
|
|
|
|
# Usage: headers_check.pl dir [files...]
|
|
|
|
# dir: dir to look for included files
|
|
|
|
# arch: architecture
|
|
|
|
# files: list of files to check
|
|
|
|
#
|
|
|
|
# The script reads the supplied files line by line and:
|
|
|
|
#
|
|
|
|
# 1) for each include statement it checks if the
|
|
|
|
# included file actually exists.
|
|
|
|
# Only include files located in asm* and linux* are checked.
|
|
|
|
# The rest are assumed to be system include files.
|
|
|
|
#
|
2008-12-27 07:43:36 +00:00
|
|
|
# 2) It is checked that prototypes does not use "extern"
|
|
|
|
#
|
2008-12-27 18:52:20 +00:00
|
|
|
# 3) Check for leaked CONFIG_ symbols
|
2008-06-15 19:41:09 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my ($dir, $arch, @files) = @ARGV;
|
|
|
|
|
|
|
|
my $ret = 0;
|
|
|
|
my $line;
|
|
|
|
my $lineno = 0;
|
|
|
|
my $filename;
|
|
|
|
|
|
|
|
foreach my $file (@files) {
|
2008-10-29 21:20:13 +00:00
|
|
|
local *FH;
|
2008-06-15 19:41:09 +00:00
|
|
|
$filename = $file;
|
2008-10-29 21:20:13 +00:00
|
|
|
open(FH, "<$filename") or die "$filename: $!\n";
|
2008-06-15 19:41:09 +00:00
|
|
|
$lineno = 0;
|
2008-10-29 21:20:13 +00:00
|
|
|
while ($line = <FH>) {
|
2008-06-15 19:41:09 +00:00
|
|
|
$lineno++;
|
|
|
|
check_include();
|
2008-12-27 07:43:36 +00:00
|
|
|
check_prototypes();
|
2008-12-27 18:52:20 +00:00
|
|
|
check_config();
|
2008-06-15 19:41:09 +00:00
|
|
|
}
|
2008-10-29 21:20:13 +00:00
|
|
|
close FH;
|
2008-06-15 19:41:09 +00:00
|
|
|
}
|
|
|
|
exit $ret;
|
|
|
|
|
|
|
|
sub check_include
|
|
|
|
{
|
|
|
|
if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
|
|
|
|
my $inc = $1;
|
|
|
|
my $found;
|
|
|
|
$found = stat($dir . "/" . $inc);
|
|
|
|
if (!$found) {
|
|
|
|
$inc =~ s#asm/#asm-$arch/#;
|
|
|
|
$found = stat($dir . "/" . $inc);
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
|
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-27 07:43:36 +00:00
|
|
|
|
|
|
|
sub check_prototypes
|
|
|
|
{
|
|
|
|
if ($line =~ m/^\s*extern\b/) {
|
|
|
|
printf STDERR "$filename:$lineno: extern's make no sense in userspace\n";
|
|
|
|
}
|
|
|
|
}
|
2008-12-27 18:52:20 +00:00
|
|
|
|
|
|
|
sub check_config
|
|
|
|
{
|
|
|
|
if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9]+)[^a-zA-Z0-9]/) {
|
|
|
|
printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|