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