1 #! /usr/bin/env perl 1 #! /usr/bin/env perl 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # 3 # 4 # checkversion finds uses of all macros in <li !! 4 # checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION 5 # where the source files do not #include <linu !! 5 # without including <linux/version.h>, or cases of 6 # of including <linux/version.h> where it is n !! 6 # including <linux/version.h> that don't need it. 7 # Copyright (C) 2003, Randy Dunlap <rdunlap@inf !! 7 # Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net> 8 8 9 use strict; 9 use strict; 10 10 11 $| = 1; 11 $| = 1; 12 12 13 my $debugging; 13 my $debugging; 14 14 15 foreach my $file (@ARGV) { 15 foreach my $file (@ARGV) { 16 next if $file =~ "include/generated/uapi/l !! 16 next if $file =~ "include/linux/version\.h"; 17 next if $file =~ "usr/include/linux/versio << 18 # Open this file. 17 # Open this file. 19 open( my $f, '<', $file ) 18 open( my $f, '<', $file ) 20 or die "Can't open $file: $!\n"; 19 or die "Can't open $file: $!\n"; 21 20 22 # Initialize variables. 21 # Initialize variables. 23 my ($fInComment, $fInString, $fUseVersion) 22 my ($fInComment, $fInString, $fUseVersion); 24 my $iLinuxVersion = 0; 23 my $iLinuxVersion = 0; 25 24 26 while (<$f>) { 25 while (<$f>) { 27 # Strip comments. 26 # Strip comments. 28 $fInComment && (s+^.*?\*/+ +o ? ($fInC 27 $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next); 29 m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.* 28 m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1))); 30 29 31 # Pick up definitions. 30 # Pick up definitions. 32 if ( m/^\s*#/o ) { 31 if ( m/^\s*#/o ) { 33 $iLinuxVersion = $. if m/^\s* 32 $iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o; 34 } 33 } 35 34 36 # Strip strings. 35 # Strip strings. 37 $fInString && (s+^.*?"+ +o ? ($fInStri 36 $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next); 38 m+"+o && (s+".*?"+ +go, (s+".*$+ +o && 37 m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1))); 39 38 40 # Pick up definitions. 39 # Pick up definitions. 41 if ( m/^\s*#/o ) { 40 if ( m/^\s*#/o ) { 42 $iLinuxVersion = $. if m/^\s* 41 $iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o; 43 } 42 } 44 43 45 # Look for uses: LINUX_VERSION_CODE, K !! 44 # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE 46 # LINUX_VERSION_MAJOR, LINUX_VERSION_P !! 45 if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) { 47 if (($_ =~ /LINUX_VERSION_CODE/) || ($ << 48 ($_ =~ /LINUX_VERSION_MAJOR/) || ( << 49 ($_ =~ /LINUX_VERSION_SUBLEVEL/)) << 50 $fUseVersion = 1; 46 $fUseVersion = 1; 51 last if $iLinuxVersion; 47 last if $iLinuxVersion; 52 } 48 } 53 } 49 } 54 50 55 # Report used version IDs without include? 51 # Report used version IDs without include? 56 if ($fUseVersion && ! $iLinuxVersion) { 52 if ($fUseVersion && ! $iLinuxVersion) { 57 print "$file: $.: need linux/version.h 53 print "$file: $.: need linux/version.h\n"; 58 } 54 } 59 55 60 # Report superfluous includes. 56 # Report superfluous includes. 61 if ($iLinuxVersion && ! $fUseVersion) { 57 if ($iLinuxVersion && ! $fUseVersion) { 62 print "$file: $iLinuxVersion linux/ver 58 print "$file: $iLinuxVersion linux/version.h not needed.\n"; 63 } 59 } 64 60 65 # debug: report OK results: 61 # debug: report OK results: 66 if ($debugging) { 62 if ($debugging) { 67 if ($iLinuxVersion && $fUseVersion) { 63 if ($iLinuxVersion && $fUseVersion) { 68 print "$file: version use is OK ($ 64 print "$file: version use is OK ($iLinuxVersion)\n"; 69 } 65 } 70 if (! $iLinuxVersion && ! $fUseVersion 66 if (! $iLinuxVersion && ! $fUseVersion) { 71 print "$file: version use is OK (n 67 print "$file: version use is OK (none)\n"; 72 } 68 } 73 } 69 } 74 70 75 close($f); 71 close($f); 76 } 72 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.