#!/usr/bin/perl -w # # headers_check.pl execute a number of trivial consistency checks # # Usage: headers_check.pl dir arch [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. # # 2) It is checked that prototypes does not use "extern" # # 3) Check for leaked CONFIG_ symbols use strict; use File::Basename; my ($dir, $arch, @files) = @ARGV; my $ret = 0; my $line; my $lineno = 0; my $filename; foreach my $file (@files) { $filename = $file; open(my $fh, '<', $filename) or die "$filename: $!\n"; $lineno = 0; while ($line = <$fh>) { $lineno++; &check_include(); &check_asm_types(); &check_sizetypes(); &check_declarations(); # Dropped for now. Too much noise &check_config(); } close $fh; } 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; } } } sub check_declarations { # soundcard.h is what it is if ($line =~ m/^void seqbuf_dump\(void\);/) { return; } # drm headers are being C++ friendly if ($line =~ m/^extern "C"/) { return; } if ($line =~ m/^(\s*extern|unsigned|char|short|int|long|void)\b/) { printf STDERR "$filename:$lineno: " . "userspace cannot reference function or " . "variable defined in the kernel\n"; } } 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"; } } my $linux_asm_types; sub check_asm_types { if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) { return; } if ($lineno == 1) { $linux_asm_types = 0; } elsif ($linux_asm_types >= 1) { return; } if ($line =~ m/^\s*#\s*include\s+/) { $linux_asm_types = 1; printf STDERR "$filename:$lineno: " . "include of is preferred over \n" # Warn until headers are all fixed #$ret = 1; } } my $linux_types; my %import_stack = (); sub check_include_typesh { my $path = $_[0]; my $import_path; my $fh; my @file_paths = ($path, $dir . "/" . $path, dirname($filename) . "/" . $path); for my $possible ( @file_paths ) { if (not $import_stack{$possible} and open($fh, '<', $possible)) { $import_path = $possible; $import_stack{$import_path} = 1; last; } } if (eof $fh) { return; } my $line; while ($line = <$fh>) { if ($line =~ m/^\s*#\s*include\s+/) { $linux_types = 1; last; } if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) { check_include_typesh($included); } } close $fh; delete $import_stack{$import_path}; } sub check_sizetypes { if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) { return; } if ($lineno == 1) { $linux_types = 0; } elsif ($linux_types >= 1) { return; } if ($line =~ m/^\s*#\s*include\s+/) { $linux_types = 1; return; } if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) { check_include_typesh($included); } if ($line =~ m/__[us](8|16|32|64)\b/) { printf STDERR "$filename:$lineno: " . "found __[us]{8,16,32,64} type " . "without #include \n"; $linux_types = 2; # Warn until headers are all fixed #$ret = 1; } } /span>lwtunnel: valid encap attr check should return 0 when lwtunnel is disabledDavid Ahern1-1/+4 2017-02-07Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netLinus Torvalds3-7/+10 2017-02-07udp: properly cope with csum errorsEric Dumazet1-1/+3 2017-02-04netlabel: out of bound access in cipso_v4_validate()Eric Dumazet1-0/+4 2017-02-04Merge branch 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/ker...Linus Torvalds1-0/+17 2017-02-04Merge tag 'char-misc-4.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/g...Linus Torvalds1-2/+30 2017-02-03base/memory, hotplug: fix a kernel oops in show_valid_zones()Toshi Kani1-1/+2 2017-02-03Merge tag 'drm-fixes-for-v4.10-rc7' of git://people.freedesktop.org/~airlied/...Linus Torvalds2-1/+16 2017-02-03Merge branch 'modversions' (modversions fixes for powerpc from Ard)Linus Torvalds3-17/+25 2017-02-03log2: make order_base_2() behave correctly on const input value zeroArd Biesheuvel1-1/+12 2017-02-03module: unify absolute krctab definitions for 32-bit and 64-bitArd Biesheuvel1-7/+0 2017-02-03modversions: treat symbol CRCs as 32 bit quantitiesArd Biesheuvel3-12/+27 2017-02-03ipv6: sr: remove cleanup flag and fix HMAC computationDavid Lebrun1-6/+3 2017-02-02Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/ke...Linus Torvalds1-3/+0 2017-02-01Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netLinus Torvalds4-19/+26 2017-02-01Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/vir...Linus Torvalds1-0/+1 2017-02-01net: fix ndo_features_check/ndo_fix_features comment orderingDimitris Michailidis1-14/+15 2017-02-01perf/x86/intel/uncore: Make package handling more robustThomas Gleixner1-2/+0