Back to home page

LXR

 
 

    


0001 #! /usr/bin/perl
0002 #
0003 # checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION
0004 # without including <linux/version.h>, or cases of
0005 # including <linux/version.h> that don't need it.
0006 # Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net>
0007 
0008 use strict;
0009 
0010 $| = 1;
0011 
0012 my $debugging;
0013 
0014 foreach my $file (@ARGV) {
0015     next if $file =~ "include/linux/version\.h";
0016     # Open this file.
0017     open( my $f, '<', $file )
0018       or die "Can't open $file: $!\n";
0019 
0020     # Initialize variables.
0021     my ($fInComment, $fInString, $fUseVersion);
0022     my $iLinuxVersion = 0;
0023 
0024     while (<$f>) {
0025     # Strip comments.
0026     $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
0027     m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
0028 
0029     # Pick up definitions.
0030     if ( m/^\s*#/o ) {
0031         $iLinuxVersion      = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
0032     }
0033 
0034     # Strip strings.
0035     $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
0036     m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
0037 
0038     # Pick up definitions.
0039     if ( m/^\s*#/o ) {
0040         $iLinuxVersion      = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
0041     }
0042 
0043     # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE
0044     if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
0045         $fUseVersion = 1;
0046             last if $iLinuxVersion;
0047         }
0048     }
0049 
0050     # Report used version IDs without include?
0051     if ($fUseVersion && ! $iLinuxVersion) {
0052     print "$file: $.: need linux/version.h\n";
0053     }
0054 
0055     # Report superfluous includes.
0056     if ($iLinuxVersion && ! $fUseVersion) {
0057     print "$file: $iLinuxVersion linux/version.h not needed.\n";
0058     }
0059 
0060     # debug: report OK results:
0061     if ($debugging) {
0062         if ($iLinuxVersion && $fUseVersion) {
0063         print "$file: version use is OK ($iLinuxVersion)\n";
0064         }
0065         if (! $iLinuxVersion && ! $fUseVersion) {
0066         print "$file: version use is OK (none)\n";
0067         }
0068     }
0069 
0070     close($f);
0071 }