cb77f0d623ff3 (Kamil Rytarowski 2017-05-07 23:25:26 +0200 1) #!/usr/bin/env perl
882ea1d64eb39 (Joe Perches 2018-06-07 17:04:33 -0700 2) # SPDX-License-Identifier: GPL-2.0
882ea1d64eb39 (Joe Perches 2018-06-07 17:04:33 -0700 3) #
dbf004d7883b3 (Dave Jones 2010-01-12 16:59:52 -0500 4) # (c) 2001, Dave Jones. (the file handling bit)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 5) # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
2a5a2c25224e2 (Andy Whitcroft 2009-01-06 14:41:23 -0800 6) # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
015830be9779a (Andy Whitcroft 2010-10-26 14:23:17 -0700 7) # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
882ea1d64eb39 (Joe Perches 2018-06-07 17:04:33 -0700 8) # (c) 2010-2018 Joe Perches <joe@perches.com>
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 9)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 10) use strict;
cb77f0d623ff3 (Kamil Rytarowski 2017-05-07 23:25:26 +0200 11) use warnings;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 12) use POSIX;
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 13) use File::Basename;
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 14) use Cwd 'abs_path';
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 15) use Term::ANSIColor qw(:constants);
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 16) use Encode qw(decode encode);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 17)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 18) my $P = $0;
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 19) my $D = dirname(abs_path($P));
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 20)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 21) my $V = '0.32';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 22)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 23) use Getopt::Long qw(:config no_auto_abbrev);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 24)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 25) my $quiet = 0;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 26) my $verbose = 0;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 27) my %verbose_messages = ();
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 28) my %verbose_emitted = ();
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 29) my $tree = 1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 30) my $chk_signoff = 1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 31) my $chk_patch = 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 32) my $tst_only;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 33) my $emacs = 0;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 34) my $terse = 0;
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 35) my $showfile = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 36) my $file = 0;
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 37) my $git = 0;
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 38) my %git_commits = ();
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 39) my $check = 0;
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 40) my $check_orig = 0;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 41) my $summary = 1;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 42) my $mailback = 0;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 43) my $summary_file = 0;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 44) my $show_types = 0;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 45) my $list_types = 0;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 46) my $fix = 0;
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 47) my $fix_inplace = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 48) my $root;
0f7f635b06483 (Joe Perches 2020-10-24 16:59:04 -0700 49) my $gitroot = $ENV{'GIT_DIR'};
0f7f635b06483 (Joe Perches 2020-10-24 16:59:04 -0700 50) $gitroot = ".git" if !defined($gitroot);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 51) my %debug;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 52) my %camelcase = ();
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 53) my %use_type = ();
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 54) my @use = ();
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 55) my %ignore_type = ();
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 56) my @ignore = ();
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 57) my $help = 0;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 58) my $configuration_file = ".checkpatch.conf";
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 59) my $max_line_length = 100;
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 60) my $ignore_perl_version = 0;
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 61) my $minimum_perl_version = 5.10.0;
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 62) my $min_conf_desc_length = 4;
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 63) my $spelling_file = "$D/spelling.txt";
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 64) my $codespell = 0;
f1a63678554f8 (Maxim Uvarov 2015-06-25 15:03:08 -0700 65) my $codespellfile = "/usr/share/codespell/dictionary.txt";
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 66) my $conststructsfile = "$D/const_structs.checkpatch";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 67) my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 68) my $typedefsfile;
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 69) my $color = "auto";
98005e8c743f9 (Vadim Bendebury 2019-03-07 16:28:38 -0800 70) my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
dbbf869da3ade (Joe Perches 2019-09-25 16:46:52 -0700 71) # git output parsing needs US English output, so first set backtick child process LANGUAGE
dbbf869da3ade (Joe Perches 2019-09-25 16:46:52 -0700 72) my $git_command ='export LANGUAGE=en_US.UTF-8; git';
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 73) my $tabsize = 8;
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 74) my ${CONFIG_} = "CONFIG_";
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 75)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 76) sub help {
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 77) my ($exitcode) = @_;
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 78)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 79) print << "EOM";
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 80) Usage: $P [OPTION]... [FILE]...
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 81) Version: $V
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 82)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 83) Options:
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 84) -q, --quiet quiet
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 85) -v, --verbose verbose mode
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 86) --no-tree run without a kernel tree
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 87) --no-signoff do not check for 'Signed-off-by' line
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 88) --patch treat FILE as patchfile (default)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 89) --emacs emacs compile window format
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 90) --terse one line per report
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 91) --showfile emit diffed file position, not input file position
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 92) -g, --git treat FILE as a single commit or git revision range
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 93) single git commit with:
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 94) <rev>
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 95) <rev>^
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 96) <rev>~n
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 97) multiple git commits with:
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 98) <rev1>..<rev2>
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 99) <rev1>...<rev2>
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 100) <rev>-<count>
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 101) git merges are ignored
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 102) -f, --file treat FILE as regular source file
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 103) --subjective, --strict enable more subjective tests
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 104) --list-types list the possible message types
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 105) --types TYPE(,TYPE2...) show only these comma separated message types
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 106) --ignore TYPE(,TYPE2...) ignore various comma separated message types
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 107) --show-types show the specific message type in the output
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 108) --max-line-length=n set the maximum line length, (default $max_line_length)
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 109) if exceeded, warn on patches
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 110) requires --strict for use with --file
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 111) --min-conf-desc-length=n set the min description length, if shorter, warn
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 112) --tab-size=n set the number of spaces for tab (default $tabsize)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 113) --root=PATH PATH to the kernel tree root
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 114) --no-summary suppress the per-file summary
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 115) --mailback only produce a report in case of warnings/errors
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 116) --summary-file include the filename in summary
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 117) --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 118) 'values', 'possible', 'type', and 'attr' (default
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 119) is all off)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 120) --test-only=WORD report only warnings/errors containing WORD
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 121) literally
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 122) --fix EXPERIMENTAL - may create horrible results
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 123) If correctable single-line errors exist, create
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 124) "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 125) with potential errors corrected to the preferred
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 126) checkpatch style
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 127) --fix-inplace EXPERIMENTAL - may create horrible results
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 128) Is the same as --fix, but overwrites the input
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 129) file. It's your fault if there's no backup or git
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 130) --ignore-perl-version override checking of perl version. expect
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 131) runtime errors.
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 132) --codespell Use the codespell dictionary for spelling/typos
f1a63678554f8 (Maxim Uvarov 2015-06-25 15:03:08 -0700 133) (default:/usr/share/codespell/dictionary.txt)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 134) --codespellfile Use this codespell dictionary
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 135) --typedefsfile Read additional types from this file
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 136) --color[=WHEN] Use colors 'always', 'never', or only when output
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 137) is a terminal ('auto'). Default is 'auto'.
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 138) --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 139) ${CONFIG_})
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 140) -h, --help, --version display this help and exit
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 141)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 142) When FILE is - read standard input.
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 143) EOM
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 144)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 145) exit($exitcode);
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 146) }
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 147)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 148) sub uniq {
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 149) my %seen;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 150) return grep { !$seen{$_}++ } @_;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 151) }
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 152)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 153) sub list_types {
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 154) my ($exitcode) = @_;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 155)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 156) my $count = 0;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 157)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 158) local $/ = undef;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 159)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 160) open(my $script, '<', abs_path($P)) or
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 161) die "$P: Can't read '$P' $!\n";
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 162)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 163) my $text = <$script>;
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 164) close($script);
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 165)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 166) my %types = ();
0547fa5851c92 (Jean Delvare 2017-09-08 16:16:11 -0700 167) # Also catch when type or level is passed through a variable
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 168) while ($text =~ /(?:(\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 169) if (defined($1)) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 170) if (exists($types{$2})) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 171) $types{$2} .= ",$1" if ($types{$2} ne $1);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 172) } else {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 173) $types{$2} = $1;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 174) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 175) } else {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 176) $types{$2} = "UNDETERMINED";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 177) }
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 178) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 179)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 180) print("#\tMessage type\n\n");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 181) if ($color) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 182) print(" ( Color coding: ");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 183) print(RED . "ERROR" . RESET);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 184) print(" | ");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 185) print(YELLOW . "WARNING" . RESET);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 186) print(" | ");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 187) print(GREEN . "CHECK" . RESET);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 188) print(" | ");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 189) print("Multiple levels / Undetermined");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 190) print(" )\n\n");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 191) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 192)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 193) foreach my $type (sort keys %types) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 194) my $orig_type = $type;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 195) if ($color) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 196) my $level = $types{$type};
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 197) if ($level eq "ERROR") {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 198) $type = RED . $type . RESET;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 199) } elsif ($level eq "WARN") {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 200) $type = YELLOW . $type . RESET;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 201) } elsif ($level eq "CHK") {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 202) $type = GREEN . $type . RESET;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 203) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 204) }
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 205) print(++$count . "\t" . $type . "\n");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 206) if ($verbose && exists($verbose_messages{$orig_type})) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 207) my $message = $verbose_messages{$orig_type};
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 208) $message =~ s/\n/\n\t/g;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 209) print("\t" . $message . "\n\n");
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 210) }
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 211) }
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 212)
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 213) exit($exitcode);
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 214) }
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 215)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 216) my $conf = which_conf($configuration_file);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 217) if (-f $conf) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 218) my @conf_args;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 219) open(my $conffile, '<', "$conf")
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 220) or warn "$P: Can't find a readable $configuration_file file $!\n";
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 221)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 222) while (<$conffile>) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 223) my $line = $_;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 224)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 225) $line =~ s/\s*\n?$//g;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 226) $line =~ s/^\s*//g;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 227) $line =~ s/\s+/ /g;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 228)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 229) next if ($line =~ m/^\s*#/);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 230) next if ($line =~ m/^\s*$/);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 231)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 232) my @words = split(" ", $line);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 233) foreach my $word (@words) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 234) last if ($word =~ m/^#/);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 235) push (@conf_args, $word);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 236) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 237) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 238) close($conffile);
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 239) unshift(@ARGV, @conf_args) if @conf_args;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 240) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 241)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 242) sub load_docs {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 243) open(my $docs, '<', "$docsfile")
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 244) or warn "$P: Can't read the documentation file $docsfile $!\n";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 245)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 246) my $type = '';
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 247) my $desc = '';
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 248) my $in_desc = 0;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 249)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 250) while (<$docs>) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 251) chomp;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 252) my $line = $_;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 253) $line =~ s/\s+$//;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 254)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 255) if ($line =~ /^\s*\*\*(.+)\*\*$/) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 256) if ($desc ne '') {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 257) $verbose_messages{$type} = trim($desc);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 258) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 259) $type = $1;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 260) $desc = '';
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 261) $in_desc = 1;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 262) } elsif ($in_desc) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 263) if ($line =~ /^(?:\s{4,}|$)/) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 264) $line =~ s/^\s{4}//;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 265) $desc .= $line;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 266) $desc .= "\n";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 267) } else {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 268) $verbose_messages{$type} = trim($desc);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 269) $type = '';
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 270) $desc = '';
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 271) $in_desc = 0;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 272) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 273) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 274) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 275)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 276) if ($desc ne '') {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 277) $verbose_messages{$type} = trim($desc);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 278) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 279) close($docs);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 280) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 281)
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 282) # Perl's Getopt::Long allows options to take optional arguments after a space.
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 283) # Prevent --color by itself from consuming other arguments
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 284) foreach (@ARGV) {
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 285) if ($_ eq "--color" || $_ eq "-color") {
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 286) $_ = "--color=$color";
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 287) }
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 288) }
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 289)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 290) GetOptions(
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 291) 'q|quiet+' => \$quiet,
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 292) 'v|verbose!' => \$verbose,
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 293) 'tree!' => \$tree,
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 294) 'signoff!' => \$chk_signoff,
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 295) 'patch!' => \$chk_patch,
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 296) 'emacs!' => \$emacs,
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 297) 'terse!' => \$terse,
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 298) 'showfile!' => \$showfile,
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 299) 'f|file!' => \$file,
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 300) 'g|git!' => \$git,
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 301) 'subjective!' => \$check,
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 302) 'strict!' => \$check,
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 303) 'ignore=s' => \@ignore,
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 304) 'types=s' => \@use,
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 305) 'show-types!' => \$show_types,
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 306) 'list-types!' => \$list_types,
6cd7f3869c925 (Joe Perches 2012-12-17 16:01:54 -0800 307) 'max-line-length=i' => \$max_line_length,
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 308) 'min-conf-desc-length=i' => \$min_conf_desc_length,
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 309) 'tab-size=i' => \$tabsize,
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 310) 'root=s' => \$root,
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 311) 'summary!' => \$summary,
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 312) 'mailback!' => \$mailback,
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 313) 'summary-file!' => \$summary_file,
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 314) 'fix!' => \$fix,
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 315) 'fix-inplace!' => \$fix_inplace,
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 316) 'ignore-perl-version!' => \$ignore_perl_version,
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 317) 'debug=s' => \%debug,
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 318) 'test-only=s' => \$tst_only,
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 319) 'codespell!' => \$codespell,
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 320) 'codespellfile=s' => \$codespellfile,
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 321) 'typedefsfile=s' => \$typedefsfile,
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 322) 'color=s' => \$color,
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 323) 'no-color' => \$color, #keep old behaviors of -nocolor
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 324) 'nocolor' => \$color, #keep old behaviors of -nocolor
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 325) 'kconfig-prefix=s' => \${CONFIG_},
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 326) 'h|help' => \$help,
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 327) 'version' => \$help
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 328) ) or help(1);
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 329)
77f5b10a82bbd (Hannes Eder 2009-09-21 17:04:37 -0700 330) help(0) if ($help);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 331)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 332) die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 333) die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 334)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 335) if ($color =~ /^[01]$/) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 336) $color = !$color;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 337) } elsif ($color =~ /^always$/i) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 338) $color = 1;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 339) } elsif ($color =~ /^never$/i) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 340) $color = 0;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 341) } elsif ($color =~ /^auto$/i) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 342) $color = (-t STDOUT);
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 343) } else {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 344) die "$P: Invalid color mode: $color\n";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 345) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 346)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 347) load_docs() if ($verbose);
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 348) list_types(0) if ($list_types);
3beb42eced39c (Joe Perches 2016-05-20 17:04:14 -0700 349)
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 350) $fix = 1 if ($fix_inplace);
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 351) $check_orig = $check;
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 352)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 353) my $exit = 0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 354)
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 355) my $perl_version_ok = 1;
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 356) if ($^V && $^V lt $minimum_perl_version) {
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 357) $perl_version_ok = 0;
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 358) printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 359) exit(1) if (!$ignore_perl_version);
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 360) }
d62a201f24cba (Dave Hansen 2013-09-11 14:23:56 -0700 361)
45107ff6d5265 (Allen Hubbe 2016-08-02 14:04:47 -0700 362) #if no filenames are given, push '-' to read patch from stdin
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 363) if ($#ARGV < 0) {
45107ff6d5265 (Allen Hubbe 2016-08-02 14:04:47 -0700 364) push(@ARGV, '-');
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 365) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 366)
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 367) # skip TAB size 1 to avoid additional checks on $tabsize - 1
32f30ca9f19df (Joe Perches 2020-06-04 16:50:40 -0700 368) die "$P: Invalid TAB size: $tabsize\n" if ($tabsize < 2);
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 369)
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 370) sub hash_save_array_words {
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 371) my ($hashRef, $arrayRef) = @_;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 372)
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 373) my @array = split(/,/, join(',', @$arrayRef));
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 374) foreach my $word (@array) {
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 375) $word =~ s/\s*\n?$//g;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 376) $word =~ s/^\s*//g;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 377) $word =~ s/\s+/ /g;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 378) $word =~ tr/[a-z]/[A-Z]/;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 379)
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 380) next if ($word =~ m/^\s*#/);
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 381) next if ($word =~ m/^\s*$/);
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 382)
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 383) $hashRef->{$word}++;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 384) }
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 385) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 386)
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 387) sub hash_show_words {
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 388) my ($hashRef, $prefix) = @_;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 389)
3c816e490ca48 (Joe Perches 2015-06-25 15:03:29 -0700 390) if (keys %$hashRef) {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 391) print "\nNOTE: $prefix message types:";
58cb3cf66cc63 (Joe Perches 2013-09-11 14:24:04 -0700 392) foreach my $word (sort keys %$hashRef) {
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 393) print " $word";
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 394) }
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 395) print "\n";
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 396) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 397) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 398)
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 399) hash_save_array_words(\%ignore_type, \@ignore);
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 400) hash_save_array_words(\%use_type, \@use);
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 401)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 402) my $dbg_values = 0;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 403) my $dbg_possible = 0;
7429c6903e362 (Andy Whitcroft 2008-07-23 21:29:06 -0700 404) my $dbg_type = 0;
a1ef277e2c88c (Andy Whitcroft 2008-10-15 22:02:17 -0700 405) my $dbg_attr = 0;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 406) for my $key (keys %debug) {
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 407) ## no critic
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 408) eval "\${dbg_$key} = '$debug{$key}';";
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 409) die "$@" if ($@);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 410) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 411)
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 412) my $rpt_cleaners = 0;
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 413)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 414) if ($terse) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 415) $emacs = 1;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 416) $quiet++;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 417) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 418)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 419) if ($tree) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 420) if (defined $root) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 421) if (!top_of_kernel_tree($root)) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 422) die "$P: $root: --root does not point at a valid tree\n";
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 423) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 424) } else {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 425) if (top_of_kernel_tree('.')) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 426) $root = '.';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 427) } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 428) top_of_kernel_tree($1)) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 429) $root = $1;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 430) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 431) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 432)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 433) if (!defined $root) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 434) print "Must be run from the top-level dir. of a kernel tree\n";
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 435) exit(2);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 436) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 437) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 438)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 439) my $emitted_corrupt = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 440)
2ceb532b04b7a (Andy Whitcroft 2009-10-26 16:50:14 -0700 441) our $Ident = qr{
2ceb532b04b7a (Andy Whitcroft 2009-10-26 16:50:14 -0700 442) [A-Za-z_][A-Za-z\d_]*
2ceb532b04b7a (Andy Whitcroft 2009-10-26 16:50:14 -0700 443) (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
2ceb532b04b7a (Andy Whitcroft 2009-10-26 16:50:14 -0700 444) }x;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 445) our $Storage = qr{extern|static|asmlinkage};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 446) our $Sparse = qr{
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 447) __user|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 448) __kernel|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 449) __force|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 450) __iomem|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 451) __must_check|
417495eda3ce5 (Andy Whitcroft 2009-02-27 14:03:08 -0800 452) __kprobes|
165e72a6c374e (Sven Eckelmann 2011-07-25 17:13:23 -0700 453) __ref|
33aa4597dda21 (Geert Uytterhoeven 2018-08-21 21:57:36 -0700 454) __refconst|
33aa4597dda21 (Geert Uytterhoeven 2018-08-21 21:57:36 -0700 455) __refdata|
ad315455d396a (Boqun Feng 2015-12-29 12:18:46 +0800 456) __rcu|
ad315455d396a (Boqun Feng 2015-12-29 12:18:46 +0800 457) __private
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 458) }x;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 459) our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 460) our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 461) our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 462) our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 463) our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 464)
52131292c069b (Wolfram Sang 2010-03-05 13:43:51 -0800 465) # Notes to $Attribute:
52131292c069b (Wolfram Sang 2010-03-05 13:43:51 -0800 466) # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 467) our $Attribute = qr{
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 468) const|
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 469) volatile|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 470) __percpu|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 471) __nocast|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 472) __safe|
46d832f5e2102 (Michael S. Tsirkin 2016-12-11 06:29:58 +0200 473) __bitwise|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 474) __packed__|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 475) __packed2__|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 476) __naked|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 477) __maybe_unused|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 478) __always_unused|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 479) __noreturn|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 480) __used|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 481) __cold|
e23ef1f3340c2 (Joe Perches 2015-02-13 14:38:24 -0800 482) __pure|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 483) __noclone|
03f1df7da5696 (Joe Perches 2010-10-26 14:23:16 -0700 484) __deprecated|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 485) __read_mostly|
c5967e989f1fe (Joe Perches 2018-09-04 15:46:20 -0700 486) __ro_after_init|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 487) __kprobes|
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 488) $InitAttribute|
24e1d81acd447 (Andy Whitcroft 2008-10-15 22:02:18 -0700 489) ____cacheline_aligned|
24e1d81acd447 (Andy Whitcroft 2008-10-15 22:02:18 -0700 490) ____cacheline_aligned_in_smp|
5fe3af119bed5 (Andy Whitcroft 2009-01-06 14:41:18 -0800 491) ____cacheline_internodealigned_in_smp|
5fe3af119bed5 (Andy Whitcroft 2009-01-06 14:41:18 -0800 492) __weak
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 493) }x;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 494) our $Modifier;
91cb5195ff224 (Joe Perches 2014-04-03 14:49:32 -0700 495) our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 496) our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 497) our $Lval = qr{$Ident(?:$Member)*};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 498)
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 499) our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 500) our $Binary = qr{(?i)0b[01]+$Int_type?};
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 501) our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 502) our $Int = qr{[0-9]+$Int_type?};
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 503) our $Octal = qr{0[0-7]+$Int_type?};
d2af5aa6c036d (Joe Perches 2021-09-07 19:59:51 -0700 504) our $String = qr{(?:\b[Lu])?"[X\t]*"};
326b1ffc136d9 (Joe Perches 2013-02-04 14:28:51 -0800 505) our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
326b1ffc136d9 (Joe Perches 2013-02-04 14:28:51 -0800 506) our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
326b1ffc136d9 (Joe Perches 2013-02-04 14:28:51 -0800 507) our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
74349bccedb3e (Joe Perches 2012-12-17 16:02:05 -0800 508) our $Float = qr{$Float_hex|$Float_dec|$Float_int};
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 509) our $Constant = qr{$Float|$Binary|$Octal|$Hex|$Int};
326b1ffc136d9 (Joe Perches 2013-02-04 14:28:51 -0800 510) our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
447432f32328d (Joe Perches 2014-04-03 14:49:17 -0700 511) our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
23f780c90496e (Joe Perches 2013-07-03 15:05:31 -0700 512) our $Arithmetic = qr{\+|-|\*|\/|%};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 513) our $Operators = qr{
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 514) <=|>=|==|!=|
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 515) =>|->|<<|>>|<|>|!|~|
23f780c90496e (Joe Perches 2013-07-03 15:05:31 -0700 516) &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 517) }x;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 518)
91cb5195ff224 (Joe Perches 2014-04-03 14:49:32 -0700 519) our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
91cb5195ff224 (Joe Perches 2014-04-03 14:49:32 -0700 520)
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 521) our $BasicType;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 522) our $NonptrType;
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 523) our $NonptrTypeMisordered;
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 524) our $NonptrTypeWithAttr;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 525) our $Type;
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 526) our $TypeMisordered;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 527) our $Declare;
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 528) our $DeclareMisordered;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 529)
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 530) our $NON_ASCII_UTF8 = qr{
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 531) [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 532) | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 533) | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 534) | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 535) | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 536) | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 537) | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 538) }x;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 539)
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 540) our $UTF8 = qr{
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 541) [\x09\x0A\x0D\x20-\x7E] # ASCII
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 542) | $NON_ASCII_UTF8
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 543) }x;
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 544)
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 545) our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t};
021158b4c7bd8 (Joe Perches 2015-02-13 14:38:43 -0800 546) our $typeOtherOSTypedefs = qr{(?x:
021158b4c7bd8 (Joe Perches 2015-02-13 14:38:43 -0800 547) u_(?:char|short|int|long) | # bsd
021158b4c7bd8 (Joe Perches 2015-02-13 14:38:43 -0800 548) u(?:nchar|short|int|long) # sysv
021158b4c7bd8 (Joe Perches 2015-02-13 14:38:43 -0800 549) )};
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 550) our $typeKernelTypedefs = qr{(?x:
fb9e9096ba943 (Andy Whitcroft 2009-09-21 17:04:38 -0700 551) (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
8ed22cad9ce16 (Andy Whitcroft 2008-10-15 22:02:32 -0700 552) atomic_t
8ed22cad9ce16 (Andy Whitcroft 2008-10-15 22:02:32 -0700 553) )};
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 554) our $typeTypedefs = qr{(?x:
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 555) $typeC99Typedefs\b|
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 556) $typeOtherOSTypedefs\b|
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 557) $typeKernelTypedefs\b
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 558) )};
8ed22cad9ce16 (Andy Whitcroft 2008-10-15 22:02:32 -0700 559)
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 560) our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 561)
691e669ba8c64 (Joe Perches 2010-03-05 13:43:51 -0800 562) our $logFunctions = qr{(?x:
758d7aada73e6 (Miles Chen 2017-02-24 15:01:34 -0800 563) printk(?:_ratelimited|_once|_deferred_once|_deferred|)|
7d0b6594e1055 (Jacob Keller 2013-07-03 15:05:35 -0700 564) (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
87bd499af5cd6 (Joe Perches 2017-11-17 15:28:48 -0800 565) TP_printk|
6e60c02e9d942 (Joe Perches 2011-07-25 17:13:27 -0700 566) WARN(?:_RATELIMIT|_ONCE|)|
b05317221b760 (Joe Perches 2011-05-24 17:13:40 -0700 567) panic|
066687279ccf5 (Joe Perches 2013-11-12 15:10:07 -0800 568) MODULE_[A-Z_]+|
066687279ccf5 (Joe Perches 2013-11-12 15:10:07 -0800 569) seq_vprintf|seq_printf|seq_puts
691e669ba8c64 (Joe Perches 2010-03-05 13:43:51 -0800 570) )};
691e669ba8c64 (Joe Perches 2010-03-05 13:43:51 -0800 571)
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 572) our $allocFunctions = qr{(?x:
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 573) (?:(?:devm_)?
58f02267f04a7 (Joe Perches 2021-02-25 17:22:01 -0800 574) (?:kv|k|v)[czm]alloc(?:_array)?(?:_node)? |
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 575) kstrdup(?:_const)? |
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 576) kmemdup(?:_nul)?) |
461e1565366e8 (Christophe JAILLET 2020-04-20 18:13:58 -0700 577) (?:\w+)?alloc_skb(?:_ip_align)? |
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 578) # dev_alloc_skb/netdev_alloc_skb, et al
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 579) dma_alloc_coherent
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 580) )};
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 581)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 582) our $signature_tags = qr{(?xi:
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 583) Signed-off-by:|
d499480cc435f (Jorge Ramirez-Ortiz 2019-01-03 15:29:12 -0800 584) Co-developed-by:|
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 585) Acked-by:|
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 586) Tested-by:|
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 587) Reviewed-by:|
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 588) Reported-by:|
8543ae1296f6e (Mugunthan V N 2013-04-29 16:18:17 -0700 589) Suggested-by:|
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 590) To:|
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 591) Cc:
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 592) )};
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 593)
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 594) our $tracing_logging_tags = qr{(?xi:
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 595) [=-]*> |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 596) <[=-]* |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 597) \[ |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 598) \] |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 599) start |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 600) called |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 601) entered |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 602) entry |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 603) enter |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 604) in |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 605) inside |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 606) here |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 607) begin |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 608) exit |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 609) end |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 610) done |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 611) leave |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 612) completed |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 613) out |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 614) return |
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 615) [\.\!:\s]*
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 616) )};
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 617)
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 618) sub edit_distance_min {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 619) my (@arr) = @_;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 620) my $len = scalar @arr;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 621) if ((scalar @arr) < 1) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 622) # if underflow, return
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 623) return;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 624) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 625) my $min = $arr[0];
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 626) for my $i (0 .. ($len-1)) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 627) if ($arr[$i] < $min) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 628) $min = $arr[$i];
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 629) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 630) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 631) return $min;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 632) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 633)
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 634) sub get_edit_distance {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 635) my ($str1, $str2) = @_;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 636) $str1 = lc($str1);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 637) $str2 = lc($str2);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 638) $str1 =~ s/-//g;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 639) $str2 =~ s/-//g;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 640) my $len1 = length($str1);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 641) my $len2 = length($str2);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 642) # two dimensional array storing minimum edit distance
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 643) my @distance;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 644) for my $i (0 .. $len1) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 645) for my $j (0 .. $len2) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 646) if ($i == 0) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 647) $distance[$i][$j] = $j;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 648) } elsif ($j == 0) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 649) $distance[$i][$j] = $i;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 650) } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 651) $distance[$i][$j] = $distance[$i - 1][$j - 1];
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 652) } else {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 653) my $dist1 = $distance[$i][$j - 1]; #insert distance
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 654) my $dist2 = $distance[$i - 1][$j]; # remove
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 655) my $dist3 = $distance[$i - 1][$j - 1]; #replace
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 656) $distance[$i][$j] = 1 + edit_distance_min($dist1, $dist2, $dist3);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 657) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 658) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 659) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 660) return $distance[$len1][$len2];
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 661) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 662)
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 663) sub find_standard_signature {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 664) my ($sign_off) = @_;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 665) my @standard_signature_tags = (
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 666) 'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:',
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 667) 'Reviewed-by:', 'Reported-by:', 'Suggested-by:'
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 668) );
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 669) foreach my $signature (@standard_signature_tags) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 670) return $signature if (get_edit_distance($sign_off, $signature) <= 2);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 671) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 672)
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 673) return "";
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 674) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 675)
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 676) our @typeListMisordered = (
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 677) qr{char\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 678) qr{int\s+(?:(?:un)?signed\s+)?short\s},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 679) qr{int\s+short(?:\s+(?:un)?signed)},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 680) qr{short\s+int(?:\s+(?:un)?signed)},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 681) qr{(?:un)?signed\s+int\s+short},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 682) qr{short\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 683) qr{long\s+int\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 684) qr{int\s+long\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 685) qr{long\s+(?:un)?signed\s+int},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 686) qr{int\s+(?:un)?signed\s+long},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 687) qr{int\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 688) qr{int\s+long\s+long\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 689) qr{long\s+long\s+int\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 690) qr{long\s+long\s+(?:un)?signed\s+int},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 691) qr{long\s+long\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 692) qr{long\s+(?:un)?signed},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 693) );
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 694)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 695) our @typeList = (
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 696) qr{void},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 697) qr{(?:(?:un)?signed\s+)?char},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 698) qr{(?:(?:un)?signed\s+)?short\s+int},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 699) qr{(?:(?:un)?signed\s+)?short},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 700) qr{(?:(?:un)?signed\s+)?int},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 701) qr{(?:(?:un)?signed\s+)?long\s+int},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 702) qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 703) qr{(?:(?:un)?signed\s+)?long\s+long},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 704) qr{(?:(?:un)?signed\s+)?long},
0c773d9d66684 (Joe Perches 2014-08-06 16:11:20 -0700 705) qr{(?:un)?signed},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 706) qr{float},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 707) qr{double},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 708) qr{bool},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 709) qr{struct\s+$Ident},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 710) qr{union\s+$Ident},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 711) qr{enum\s+$Ident},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 712) qr{${Ident}_t},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 713) qr{${Ident}_handler},
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 714) qr{${Ident}_handler_fn},
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 715) @typeListMisordered,
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 716) );
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 717)
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 718) our $C90_int_types = qr{(?x:
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 719) long\s+long\s+int\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 720) long\s+long\s+(?:un)?signed\s+int|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 721) long\s+long\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 722) (?:(?:un)?signed\s+)?long\s+long\s+int|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 723) (?:(?:un)?signed\s+)?long\s+long|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 724) int\s+long\s+long\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 725) int\s+(?:(?:un)?signed\s+)?long\s+long|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 726)
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 727) long\s+int\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 728) long\s+(?:un)?signed\s+int|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 729) long\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 730) (?:(?:un)?signed\s+)?long\s+int|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 731) (?:(?:un)?signed\s+)?long|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 732) int\s+long\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 733) int\s+(?:(?:un)?signed\s+)?long|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 734)
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 735) int\s+(?:un)?signed|
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 736) (?:(?:un)?signed\s+)?int
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 737) )};
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 738)
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 739) our @typeListFile = ();
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 740) our @typeListWithAttr = (
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 741) @typeList,
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 742) qr{struct\s+$InitAttribute\s+$Ident},
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 743) qr{union\s+$InitAttribute\s+$Ident},
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 744) );
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 745)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 746) our @modifierList = (
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 747) qr{fastcall},
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 748) );
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 749) our @modifierListFile = ();
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 750)
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 751) our @mode_permission_funcs = (
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 752) ["module_param", 3],
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 753) ["module_param_(?:array|named|string)", 4],
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 754) ["module_param_array_named", 5],
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 755) ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2],
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 756) ["proc_create(?:_data|)", 2],
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 757) ["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2],
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 758) ["IIO_DEV_ATTR_[A-Z_]+", 1],
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 759) ["SENSOR_(?:DEVICE_|)ATTR_2", 2],
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 760) ["SENSOR_TEMPLATE(?:_2|)", 3],
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 761) ["__ATTR", 2],
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 762) );
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 763)
1a3dcf2e6b35f (Joe Perches 2020-08-11 18:35:16 -0700 764) my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
1a3dcf2e6b35f (Joe Perches 2020-08-11 18:35:16 -0700 765)
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 766) #Create a search pattern for all these functions to speed up a loop below
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 767) our $mode_perms_search = "";
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 768) foreach my $entry (@mode_permission_funcs) {
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 769) $mode_perms_search .= '|' if ($mode_perms_search ne "");
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 770) $mode_perms_search .= $entry->[0];
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 771) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 772) $mode_perms_search = "(?:${mode_perms_search})";
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 773)
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 774) our %deprecated_apis = (
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 775) "synchronize_rcu_bh" => "synchronize_rcu",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 776) "synchronize_rcu_bh_expedited" => "synchronize_rcu_expedited",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 777) "call_rcu_bh" => "call_rcu",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 778) "rcu_barrier_bh" => "rcu_barrier",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 779) "synchronize_sched" => "synchronize_rcu",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 780) "synchronize_sched_expedited" => "synchronize_rcu_expedited",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 781) "call_rcu_sched" => "call_rcu",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 782) "rcu_barrier_sched" => "rcu_barrier",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 783) "get_state_synchronize_sched" => "get_state_synchronize_rcu",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 784) "cond_synchronize_sched" => "cond_synchronize_rcu",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 785) );
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 786)
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 787) #Create a search pattern for all these strings to speed up a loop below
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 788) our $deprecated_apis_search = "";
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 789) foreach my $entry (keys %deprecated_apis) {
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 790) $deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 791) $deprecated_apis_search .= $entry;
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 792) }
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 793) $deprecated_apis_search = "(?:${deprecated_apis_search})";
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 794)
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 795) our $mode_perms_world_writable = qr{
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 796) S_IWUGO |
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 797) S_IWOTH |
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 798) S_IRWXUGO |
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 799) S_IALLUGO |
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 800) 0[0-7][0-7][2367]
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 801) }x;
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 802)
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 803) our %mode_permission_string_types = (
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 804) "S_IRWXU" => 0700,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 805) "S_IRUSR" => 0400,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 806) "S_IWUSR" => 0200,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 807) "S_IXUSR" => 0100,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 808) "S_IRWXG" => 0070,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 809) "S_IRGRP" => 0040,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 810) "S_IWGRP" => 0020,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 811) "S_IXGRP" => 0010,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 812) "S_IRWXO" => 0007,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 813) "S_IROTH" => 0004,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 814) "S_IWOTH" => 0002,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 815) "S_IXOTH" => 0001,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 816) "S_IRWXUGO" => 0777,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 817) "S_IRUGO" => 0444,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 818) "S_IWUGO" => 0222,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 819) "S_IXUGO" => 0111,
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 820) );
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 821)
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 822) #Create a search pattern for all these strings to speed up a loop below
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 823) our $mode_perms_string_search = "";
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 824) foreach my $entry (keys %mode_permission_string_types) {
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 825) $mode_perms_string_search .= '|' if ($mode_perms_string_search ne "");
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 826) $mode_perms_string_search .= $entry;
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 827) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 828) our $single_mode_perms_string_search = "(?:${mode_perms_string_search})";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 829) our $multi_mode_perms_string_search = qr{
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 830) ${single_mode_perms_string_search}
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 831) (?:\s*\|\s*${single_mode_perms_string_search})*
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 832) }x;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 833)
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 834) sub perms_to_octal {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 835) my ($string) = @_;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 836)
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 837) return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 838)
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 839) my $val = "";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 840) my $oval = "";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 841) my $to = 0;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 842) my $curpos = 0;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 843) my $lastpos = 0;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 844) while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 845) $curpos = pos($string);
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 846) my $match = $2;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 847) my $omatch = $1;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 848) last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 849) $lastpos = $curpos;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 850) $to |= $mode_permission_string_types{$match};
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 851) $val .= '\s*\|\s*' if ($val ne "");
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 852) $val .= $match;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 853) $oval .= $omatch;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 854) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 855) $oval =~ s/^\s*\|\s*//;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 856) $oval =~ s/\s*\|\s*$//;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 857) return sprintf("%04o", $to);
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 858) }
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 859)
7840a94cd1255 (Wolfram Sang 2010-08-09 17:20:57 -0700 860) our $allowed_asm_includes = qr{(?x:
7840a94cd1255 (Wolfram Sang 2010-08-09 17:20:57 -0700 861) irq|
cdcee686ee904 (Sergey Ryazanov 2014-10-13 15:51:44 -0700 862) memory|
cdcee686ee904 (Sergey Ryazanov 2014-10-13 15:51:44 -0700 863) time|
cdcee686ee904 (Sergey Ryazanov 2014-10-13 15:51:44 -0700 864) reboot
7840a94cd1255 (Wolfram Sang 2010-08-09 17:20:57 -0700 865) )};
7840a94cd1255 (Wolfram Sang 2010-08-09 17:20:57 -0700 866) # memory.h: ARM has a custom one
7840a94cd1255 (Wolfram Sang 2010-08-09 17:20:57 -0700 867)
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 868) # Load common spelling mistakes and build regular expression list.
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 869) my $misspellings;
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 870) my %spelling_fix;
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 871)
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 872) if (open(my $spelling, '<', $spelling_file)) {
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 873) while (<$spelling>) {
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 874) my $line = $_;
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 875)
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 876) $line =~ s/\s*\n?$//g;
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 877) $line =~ s/^\s*//g;
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 878)
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 879) next if ($line =~ m/^\s*#/);
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 880) next if ($line =~ m/^\s*$/);
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 881)
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 882) my ($suspect, $fix) = split(/\|\|/, $line);
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 883)
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 884) $spelling_fix{$suspect} = $fix;
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 885) }
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 886) close($spelling);
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 887) } else {
36061e3806182 (Joe Perches 2014-12-10 15:51:43 -0800 888) warn "No typos will be found - file '$spelling_file': $!\n";
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 889) }
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 890)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 891) if ($codespell) {
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 892) if (open(my $spelling, '<', $codespellfile)) {
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 893) while (<$spelling>) {
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 894) my $line = $_;
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 895)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 896) $line =~ s/\s*\n?$//g;
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 897) $line =~ s/^\s*//g;
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 898)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 899) next if ($line =~ m/^\s*#/);
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 900) next if ($line =~ m/^\s*$/);
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 901) next if ($line =~ m/, disabled/i);
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 902)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 903) $line =~ s/,.*$//;
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 904)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 905) my ($suspect, $fix) = split(/->/, $line);
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 906)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 907) $spelling_fix{$suspect} = $fix;
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 908) }
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 909) close($spelling);
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 910) } else {
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 911) warn "No codespell typos will be found - file '$codespellfile': $!\n";
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 912) }
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 913) }
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 914)
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 915) $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
ebfd7d6237531 (Joe Perches 2015-04-16 12:44:14 -0700 916)
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 917) sub read_words {
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 918) my ($wordsRef, $file) = @_;
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 919)
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 920) if (open(my $words, '<', $file)) {
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 921) while (<$words>) {
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 922) my $line = $_;
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 923)
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 924) $line =~ s/\s*\n?$//g;
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 925) $line =~ s/^\s*//g;
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 926)
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 927) next if ($line =~ m/^\s*#/);
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 928) next if ($line =~ m/^\s*$/);
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 929) if ($line =~ /\s/) {
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 930) print("$file: '$line' invalid - ignored\n");
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 931) next;
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 932) }
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 933)
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 934) $$wordsRef .= '|' if (defined $$wordsRef);
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 935) $$wordsRef .= $line;
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 936) }
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 937) close($file);
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 938) return 1;
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 939) }
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 940)
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 941) return 0;
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 942) }
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 943)
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 944) my $const_structs;
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 945) if (show_type("CONST_STRUCT")) {
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 946) read_words(\$const_structs, $conststructsfile)
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 947) or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 948) }
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 949)
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 950) if (defined($typedefsfile)) {
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 951) my $typeOtherTypedefs;
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 952) read_words(\$typeOtherTypedefs, $typedefsfile)
75ad8c575a5ad (Jerome Forissier 2017-05-08 15:56:00 -0700 953) or warn "No additional types will be considered - file '$typedefsfile': $!\n";
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 954) $typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs);
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 955) }
bf1fa1dae68e1 (Joe Perches 2016-10-11 13:51:56 -0700 956)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 957) sub build_types {
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 958) my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 959) my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 960) my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 961) my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
c8cb2ca37ed51 (Andy Whitcroft 2008-07-23 21:28:57 -0700 962) $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 963) $BasicType = qr{
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 964) (?:$typeTypedefs\b)|
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 965) (?:${all}\b)
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 966) }x;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 967) $NonptrType = qr{
d2172eb5bd4b7 (Andy Whitcroft 2008-07-23 21:29:07 -0700 968) (?:$Modifier\s+|const\s+)*
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 969) (?:
6b48db24e30d3 (Andy Whitcroft 2012-01-10 15:10:13 -0800 970) (?:typeof|__typeof__)\s*\([^\)]*\)|
8ed22cad9ce16 (Andy Whitcroft 2008-10-15 22:02:32 -0700 971) (?:$typeTypedefs\b)|
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 972) (?:${all}\b)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 973) )
c8cb2ca37ed51 (Andy Whitcroft 2008-07-23 21:28:57 -0700 974) (?:\s+$Modifier|\s+const)*
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 975) }x;
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 976) $NonptrTypeMisordered = qr{
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 977) (?:$Modifier\s+|const\s+)*
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 978) (?:
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 979) (?:${Misordered}\b)
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 980) )
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 981) (?:\s+$Modifier|\s+const)*
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 982) }x;
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 983) $NonptrTypeWithAttr = qr{
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 984) (?:$Modifier\s+|const\s+)*
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 985) (?:
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 986) (?:typeof|__typeof__)\s*\([^\)]*\)|
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 987) (?:$typeTypedefs\b)|
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 988) (?:${allWithAttr}\b)
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 989) )
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 990) (?:\s+$Modifier|\s+const)*
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 991) }x;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 992) $Type = qr{
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 993) $NonptrType
7b18496cbc9af (Antonio Borneo 2020-04-06 20:11:04 -0700 994) (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
c8cb2ca37ed51 (Andy Whitcroft 2008-07-23 21:28:57 -0700 995) (?:\s+$Inline|\s+$Modifier)*
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 996) }x;
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 997) $TypeMisordered = qr{
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 998) $NonptrTypeMisordered
7b18496cbc9af (Antonio Borneo 2020-04-06 20:11:04 -0700 999) (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 1000) (?:\s+$Inline|\s+$Modifier)*
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 1001) }x;
91cb5195ff224 (Joe Perches 2014-04-03 14:49:32 -0700 1002) $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 1003) $DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1004) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1005) build_types();
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1006)
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1007) our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 1008)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 1009) # Using $balanced_parens, $LvalOrFunc, or $FuncArg
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 1010) # requires at least perl version v5.10.0
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 1011) # Any use must be runtime checked with $^V
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 1012)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 1013) our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 1014) our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
c0a5c89858337 (Joe Perches 2015-02-13 14:38:21 -0800 1015) our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1016)
f84223087402c (Joe Perches 2014-08-06 16:11:31 -0700 1017) our $declaration_macros = qr{(?x:
3e838b6c41e8a (Joe Perches 2015-09-09 15:37:33 -0700 1018) (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
fe658f94b2c91 (Steffen Maier 2017-07-10 15:52:10 -0700 1019) (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
3d102fc0e7b02 (Gilad Ben-Yossef 2018-04-10 16:33:17 -0700 1020) (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
f84223087402c (Joe Perches 2014-08-06 16:11:31 -0700 1021) )};
f84223087402c (Joe Perches 2014-08-06 16:11:31 -0700 1022)
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1023) our %allow_repeated_words = (
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1024) add => '',
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1025) added => '',
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1026) bad => '',
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1027) be => '',
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1028) );
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 1029)
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1030) sub deparenthesize {
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1031) my ($string) = @_;
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1032) return "" if (!defined($string));
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1033)
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1034) while ($string =~ /^\s*\(.*\)\s*$/) {
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1035) $string =~ s@^\s*\(\s*@@;
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1036) $string =~ s@\s*\)\s*$@@;
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1037) }
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1038)
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1039) $string =~ s@\s+@ @g;
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 1040)
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1041) return $string;
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1042) }
7d2367af0b09f (Joe Perches 2011-07-25 17:13:22 -0700 1043)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1044) sub seed_camelcase_file {
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1045) my ($file) = @_;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1046)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1047) return if (!(-f $file));
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1048)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1049) local $/;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1050)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1051) open(my $include_file, '<', "$file")
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1052) or warn "$P: Can't read '$file' $!\n";
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1053) my $text = <$include_file>;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1054) close($include_file);
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1055)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1056) my @lines = split('\n', $text);
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1057)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1058) foreach my $line (@lines) {
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1059) next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1060) if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1061) $camelcase{$1} = 1;
11ea516a6c578 (Joe Perches 2013-11-12 15:10:08 -0800 1062) } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
11ea516a6c578 (Joe Perches 2013-11-12 15:10:08 -0800 1063) $camelcase{$1} = 1;
11ea516a6c578 (Joe Perches 2013-11-12 15:10:08 -0800 1064) } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1065) $camelcase{$1} = 1;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1066) }
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1067) }
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1068) }
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1069)
cd28b119047b9 (Joe Perches 2019-12-04 16:52:09 -0800 1070) our %maintained_status = ();
cd28b119047b9 (Joe Perches 2019-12-04 16:52:09 -0800 1071)
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1072) sub is_maintained_obsolete {
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1073) my ($filename) = @_;
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1074)
f2c19c2f380fc (Jerome Forissier 2016-12-12 16:46:23 -0800 1075) return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1076)
cd28b119047b9 (Joe Perches 2019-12-04 16:52:09 -0800 1077) if (!exists($maintained_status{$filename})) {
cd28b119047b9 (Joe Perches 2019-12-04 16:52:09 -0800 1078) $maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`;
cd28b119047b9 (Joe Perches 2019-12-04 16:52:09 -0800 1079) }
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1080)
cd28b119047b9 (Joe Perches 2019-12-04 16:52:09 -0800 1081) return $maintained_status{$filename} =~ /obsolete/i;
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1082) }
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 1083)
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1084) sub is_SPDX_License_valid {
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1085) my ($license) = @_;
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1086)
f9363b31d7692 (Guenter Roeck 2021-06-30 18:56:19 -0700 1087) return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1088)
56294112791ac (Joe Perches 2018-08-21 21:58:04 -0700 1089) my $root_path = abs_path($root);
f9363b31d7692 (Guenter Roeck 2021-06-30 18:56:19 -0700 1090) my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1091) return 0 if ($status ne "");
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1092) return 1;
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1093) }
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 1094)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1095) my $camelcase_seeded = 0;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1096) sub seed_camelcase_includes {
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1097) return if ($camelcase_seeded);
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1098)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1099) my $files;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1100) my $camelcase_cache = "";
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1101) my @include_files = ();
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1102)
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1103) $camelcase_seeded = 1;
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1104)
0f7f635b06483 (Joe Perches 2020-10-24 16:59:04 -0700 1105) if (-e "$gitroot") {
dbbf869da3ade (Joe Perches 2019-09-25 16:46:52 -0700 1106) my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`;
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1107) chomp $git_last_include_commit;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1108) $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1109) } else {
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1110) my $last_mod_date = 0;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1111) $files = `find $root/include -name "*.h"`;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1112) @include_files = split('\n', $files);
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1113) foreach my $file (@include_files) {
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1114) my $date = POSIX::strftime("%Y%m%d%H%M",
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1115) localtime((stat $file)[9]));
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1116) $last_mod_date = $date if ($last_mod_date < $date);
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1117) }
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1118) $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1119) }
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1120)
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1121) if ($camelcase_cache ne "" && -f $camelcase_cache) {
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1122) open(my $camelcase_file, '<', "$camelcase_cache")
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1123) or warn "$P: Can't read '$camelcase_cache' $!\n";
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1124) while (<$camelcase_file>) {
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1125) chomp;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1126) $camelcase{$_} = 1;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1127) }
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1128) close($camelcase_file);
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1129)
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1130) return;
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1131) }
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1132)
0f7f635b06483 (Joe Perches 2020-10-24 16:59:04 -0700 1133) if (-e "$gitroot") {
dbbf869da3ade (Joe Perches 2019-09-25 16:46:52 -0700 1134) $files = `${git_command} ls-files "include/*.h"`;
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1135) @include_files = split('\n', $files);
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1136) }
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1137)
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1138) foreach my $file (@include_files) {
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1139) seed_camelcase_file($file);
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1140) }
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1141)
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1142) if ($camelcase_cache ne "") {
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1143) unlink glob ".checkpatch-camelcase.*";
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1144) open(my $camelcase_file, '>', "$camelcase_cache")
c707a81de71a2 (Joe Perches 2013-07-08 16:00:43 -0700 1145) or warn "$P: Can't write '$camelcase_cache' $!\n";
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1146) foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1147) print $camelcase_file ("$_\n");
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1148) }
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1149) close($camelcase_file);
351b2a1fe2d06 (Joe Perches 2013-07-03 15:05:36 -0700 1150) }
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1151) }
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 1152)
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1153) sub git_is_single_file {
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1154) my ($filename) = @_;
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1155)
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1156) return 0 if ((which("git") eq "") || !(-e "$gitroot"));
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1157)
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1158) my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1159) my $count = $output =~ tr/\n//;
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1160) return $count eq 1 && $output =~ m{^${filename}$};
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1161) }
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1162)
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1163) sub git_commit_info {
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1164) my ($commit, $id, $desc) = @_;
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1165)
0f7f635b06483 (Joe Perches 2020-10-24 16:59:04 -0700 1166) return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1167)
dbbf869da3ade (Joe Perches 2019-09-25 16:46:52 -0700 1168) my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1169) $output =~ s/^\s*//gm;
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1170) my @lines = split("\n", $output);
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1171)
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 1172) return ($id, $desc) if ($#lines < 0);
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 1173)
5a7f4455ad321 (Sean Christopherson 2019-09-25 16:46:49 -0700 1174) if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous/) {
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1175) # Maybe one day convert this block of bash into something that returns
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1176) # all matching commit ids, but it's very slow...
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1177) #
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1178) # echo "checking commits $1..."
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1179) # git rev-list --remotes | grep -i "^$1" |
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1180) # while read line ; do
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1181) # git log --format='%H %s' -1 $line |
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1182) # echo "commit $(cut -c 1-12,41-)"
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1183) # done
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 1184) } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./ ||
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 1185) $lines[0] =~ /^fatal: bad object $commit/) {
948b133a1b624 (Heinrich Schuchardt 2017-07-10 15:52:16 -0700 1186) $id = undef;
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1187) } else {
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1188) $id = substr($lines[0], 0, 12);
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1189) $desc = substr($lines[0], 41);
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1190) }
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1191)
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1192) return ($id, $desc);
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1193) }
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1194)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1195) $chk_signoff = 0 if ($file);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1196)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1197) my @rawlines = ();
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1198) my @lines = ();
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 1199) my @fixed = ();
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 1200) my @fixed_inserted = ();
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 1201) my @fixed_deleted = ();
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 1202) my $fixlinenr = -1;
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 1203)
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1204) # If input is git commits, extract all commits from the commit expressions.
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1205) # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
0f7f635b06483 (Joe Perches 2020-10-24 16:59:04 -0700 1206) die "$P: No git repository found\n" if ($git && !-e "$gitroot");
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1207)
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1208) if ($git) {
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1209) my @commits = ();
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1210) foreach my $commit_expr (@ARGV) {
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1211) my $git_range;
28898fd1a85fa (Joe Perches 2016-05-20 17:04:22 -0700 1212) if ($commit_expr =~ m/^(.*)-(\d+)$/) {
28898fd1a85fa (Joe Perches 2016-05-20 17:04:22 -0700 1213) $git_range = "-$2 $1";
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1214) } elsif ($commit_expr =~ m/\.\./) {
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1215) $git_range = "$commit_expr";
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1216) } else {
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1217) $git_range = "-1 $commit_expr";
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1218) }
dbbf869da3ade (Joe Perches 2019-09-25 16:46:52 -0700 1219) my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1220) foreach my $line (split(/\n/, $lines)) {
28898fd1a85fa (Joe Perches 2016-05-20 17:04:22 -0700 1221) $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
28898fd1a85fa (Joe Perches 2016-05-20 17:04:22 -0700 1222) next if (!defined($1) || !defined($2));
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1223) my $sha1 = $1;
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1224) my $subject = $2;
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1225) unshift(@commits, $sha1);
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1226) $git_commits{$sha1} = $subject;
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1227) }
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1228) }
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1229) die "$P: no git commits after extraction!\n" if (@commits == 0);
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1230) @ARGV = @commits;
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1231) }
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1232)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1233) my $vname;
98005e8c743f9 (Vadim Bendebury 2019-03-07 16:28:38 -0800 1234) $allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1235) for my $filename (@ARGV) {
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1236) my $FILE;
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1237) my $is_git_file = git_is_single_file($filename);
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1238) my $oldfile = $file;
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1239) $file = 1 if ($is_git_file);
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1240) if ($git) {
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1241) open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1242) die "$P: $filename: git format-patch failed - $!\n";
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1243) } elsif ($file) {
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1244) open($FILE, '-|', "diff -u /dev/null $filename") ||
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1245) die "$P: $filename: diff failed - $!\n";
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1246) } elsif ($filename eq '-') {
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1247) open($FILE, '<&STDIN');
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1248) } else {
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1249) open($FILE, '<', "$filename") ||
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1250) die "$P: $filename: open failed - $!\n";
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1251) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1252) if ($filename eq '-') {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1253) $vname = 'Your patch';
4a593c3448312 (Changbin Du 2016-05-20 17:04:16 -0700 1254) } elsif ($git) {
0dea9f1eef86b (Joe Perches 2016-05-20 17:04:19 -0700 1255) $vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1256) } else {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1257) $vname = $filename;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1258) }
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1259) while (<$FILE>) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1260) chomp;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1261) push(@rawlines, $_);
c7f574d0e9f9e (Geert Uytterhoeven 2020-06-04 16:50:43 -0700 1262) $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1263) }
21caa13c02d67 (Andy Whitcroft 2009-01-06 14:41:30 -0800 1264) close($FILE);
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1265)
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1266) if ($#ARGV > 0 && $quiet == 0) {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1267) print '-' x length($vname) . "\n";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1268) print "$vname\n";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1269) print '-' x length($vname) . "\n";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1270) }
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1271)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1272) if (!process($filename)) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1273) $exit = 1;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1274) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1275) @rawlines = ();
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1276) @lines = ();
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 1277) @fixed = ();
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 1278) @fixed_inserted = ();
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 1279) @fixed_deleted = ();
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 1280) $fixlinenr = -1;
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 1281) @modifierListFile = ();
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 1282) @typeListFile = ();
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 1283) build_types();
f5f613259f3fe (Joe Perches 2020-10-15 20:12:12 -0700 1284) $file = $oldfile if ($is_git_file);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1285) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1286)
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1287) if (!$quiet) {
3c816e490ca48 (Joe Perches 2015-06-25 15:03:29 -0700 1288) hash_show_words(\%use_type, "Used");
3c816e490ca48 (Joe Perches 2015-06-25 15:03:29 -0700 1289) hash_show_words(\%ignore_type, "Ignored");
3c816e490ca48 (Joe Perches 2015-06-25 15:03:29 -0700 1290)
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 1291) if (!$perl_version_ok) {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1292) print << "EOM"
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1293)
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1294) NOTE: perl $^V is not modern enough to detect all possible issues.
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 1295) An upgrade to at least perl $minimum_perl_version is suggested.
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1296) EOM
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1297) }
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1298) if ($exit) {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1299) print << "EOM"
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1300)
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1301) NOTE: If any of the errors are false positives, please report
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1302) them to the maintainer, see CHECKPATCH in MAINTAINERS.
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1303) EOM
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1304) }
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1305) }
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 1306)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1307) exit($exit);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1308)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1309) sub top_of_kernel_tree {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1310) my ($root) = @_;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1311)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1312) my @tree_check = (
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1313) "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1314) "README", "Documentation", "arch", "include", "drivers",
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1315) "fs", "init", "ipc", "kernel", "lib", "scripts",
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1316) );
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1317)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1318) foreach my $check (@tree_check) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1319) if (! -e $root . '/' . $check) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1320) return 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1321) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1322) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1323) return 1;
8f26b8376faad (Joe Perches 2012-10-04 17:13:32 -0700 1324) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1325)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1326) sub parse_email {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1327) my ($formatted_email) = @_;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1328)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1329) my $name = "";
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1330) my $quoted = "";
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1331) my $name_comment = "";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1332) my $address = "";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1333) my $comment = "";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1334)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1335) if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1336) $name = $1;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1337) $address = $2;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1338) $comment = $3 if defined $3;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1339) } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1340) $address = $1;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1341) $comment = $2 if defined $2;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1342) } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1343) $address = $1;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1344) $comment = $2 if defined $2;
85e12066ea09b (Joe Perches 2018-04-10 16:33:09 -0700 1345) $formatted_email =~ s/\Q$address\E.*$//;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1346) $name = $formatted_email;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 1347) $name = trim($name);
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1348) $name =~ s/^\"|\"$//g;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1349) # If there's a name left after stripping spaces and
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1350) # leading quotes, and the address doesn't have both
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1351) # leading and trailing angle brackets, the address
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1352) # is invalid. ie:
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1353) # "joe smith joe@smith.com" bad
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1354) # "joe smith <joe@smith.com" bad
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1355) if ($name ne "" && $address !~ /^<[^>]+>$/) {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1356) $name = "";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1357) $address = "";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1358) $comment = "";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1359) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1360) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1361)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1362) # Extract comments from names excluding quoted parts
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1363) # "John D. (Doe)" - Do not extract
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1364) if ($name =~ s/\"(.+)\"//) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1365) $quoted = $1;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1366) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1367) while ($name =~ s/\s*($balanced_parens)\s*/ /) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1368) $name_comment .= trim($1);
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1369) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1370) $name =~ s/^[ \"]+|[ \"]+$//g;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1371) $name = trim("$quoted $name");
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1372)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 1373) $address = trim($address);
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1374) $address =~ s/^\<|\>$//g;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1375) $comment = trim($comment);
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1376)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1377) if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1378) $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1379) $name = "\"$name\"";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1380) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1381)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1382) return ($name, $name_comment, $address, $comment);
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1383) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1384)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1385) sub format_email {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1386) my ($name, $name_comment, $address, $comment) = @_;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1387)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1388) my $formatted_email;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1389)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1390) $name =~ s/^[ \"]+|[ \"]+$//g;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 1391) $address = trim($address);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1392) $address =~ s/(?:\.|\,|\")+$//; ##trailing commas, dots or quotes
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1393)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1394) if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1395) $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1396) $name = "\"$name\"";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1397) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1398)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1399) $name_comment = trim($name_comment);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1400) $name_comment = " $name_comment" if ($name_comment ne "");
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1401) $comment = trim($comment);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1402) $comment = " $comment" if ($comment ne "");
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1403)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1404) if ("$name" eq "") {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1405) $formatted_email = "$address";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1406) } else {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1407) $formatted_email = "$name$name_comment <$address>";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1408) }
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1409) $formatted_email .= "$comment";
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1410) return $formatted_email;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1411) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 1412)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1413) sub reformat_email {
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1414) my ($email) = @_;
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1415)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1416) my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1417) return format_email($email_name, $name_comment, $email_address, $comment);
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1418) }
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1419)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1420) sub same_email_addresses {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 1421) my ($email1, $email2) = @_;
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1422)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1423) my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1424) my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2);
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1425)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1426) return $email1_name eq $email2_name &&
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1427) $email1_address eq $email2_address &&
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1428) $name1_comment eq $name2_comment &&
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 1429) $comment1 eq $comment2;
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1430) }
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 1431)
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1432) sub which {
bd474ca076af8 (Joe Perches 2014-08-06 16:11:10 -0700 1433) my ($bin) = @_;
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1434)
bd474ca076af8 (Joe Perches 2014-08-06 16:11:10 -0700 1435) foreach my $path (split(/:/, $ENV{PATH})) {
bd474ca076af8 (Joe Perches 2014-08-06 16:11:10 -0700 1436) if (-e "$path/$bin") {
bd474ca076af8 (Joe Perches 2014-08-06 16:11:10 -0700 1437) return "$path/$bin";
bd474ca076af8 (Joe Perches 2014-08-06 16:11:10 -0700 1438) }
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1439) }
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1440)
bd474ca076af8 (Joe Perches 2014-08-06 16:11:10 -0700 1441) return "";
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1442) }
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 1443)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1444) sub which_conf {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1445) my ($conf) = @_;
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1446)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1447) foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1448) if (-e "$path/$conf") {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1449) return "$path/$conf";
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1450) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1451) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1452)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1453) return "";
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1454) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 1455)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1456) sub expand_tabs {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1457) my ($str) = @_;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1458)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1459) my $res = '';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1460) my $n = 0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1461) for my $c (split(//, $str)) {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1462) if ($c eq "\t") {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1463) $res .= ' ';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1464) $n++;
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 1465) for (; ($n % $tabsize) != 0; $n++) {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1466) $res .= ' ';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1467) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1468) next;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1469) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1470) $res .= $c;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1471) $n++;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1472) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1473)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1474) return $res;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1475) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1476) sub copy_spacing {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1477) (my $res = shift) =~ tr/\t/ /c;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1478) return $res;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1479) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 1480)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1481) sub line_stats {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1482) my ($line) = @_;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1483)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1484) # Drop the diff line leader and expand tabs
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1485) $line =~ s/^.//;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1486) $line = expand_tabs($line);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1487)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1488) # Pick the indent from the front of the line.
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1489) my ($white) = ($line =~ /^(\s*)/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1490)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1491) return (length($line), length($white));
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1492) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1493)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1494) my $sanitise_quote = '';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1495)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1496) sub sanitise_line_reset {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1497) my ($in_comment) = @_;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1498)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1499) if ($in_comment) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1500) $sanitise_quote = '*/';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1501) } else {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1502) $sanitise_quote = '';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1503) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1504) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1505) sub sanitise_line {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1506) my ($line) = @_;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1507)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1508) my $res = '';
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1509) my $l = '';
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1510)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1511) my $qlen = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1512) my $off = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1513) my $c;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1514)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1515) # Always copy over the diff marker.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1516) $res = substr($line, 0, 1);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1517)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1518) for ($off = 1; $off < length($line); $off++) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1519) $c = substr($line, $off, 1);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1520)
8d2e11b22d790 (Claudio Fontana 2018-04-10 16:33:42 -0700 1521) # Comments we are whacking completely including the begin
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1522) # and end, all to $;.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1523) if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1524) $sanitise_quote = '*/';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1525)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1526) substr($res, $off, 2, "$;$;");
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1527) $off++;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1528) next;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1529) }
81bc0e020232a (Andy Whitcroft 2008-10-15 22:02:26 -0700 1530) if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1531) $sanitise_quote = '';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1532) substr($res, $off, 2, "$;$;");
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1533) $off++;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1534) next;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1535) }
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1536) if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1537) $sanitise_quote = '//';
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1538)
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1539) substr($res, $off, 2, $sanitise_quote);
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1540) $off++;
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1541) next;
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1542) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1543)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1544) # A \ in a string means ignore the next character.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1545) if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1546) $c eq "\\") {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1547) substr($res, $off, 2, 'XX');
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1548) $off++;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1549) next;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1550) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1551) # Regular quotes.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1552) if ($c eq "'" || $c eq '"') {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1553) if ($sanitise_quote eq '') {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1554) $sanitise_quote = $c;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1555)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1556) substr($res, $off, 1, $c);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1557) next;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1558) } elsif ($sanitise_quote eq $c) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1559) $sanitise_quote = '';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1560) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1561) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1562)
fae17daed7312 (Andy Whitcroft 2009-01-06 14:41:20 -0800 1563) #print "c<$c> SQ<$sanitise_quote>\n";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1564) if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1565) substr($res, $off, 1, $;);
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1566) } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1567) substr($res, $off, 1, $;);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1568) } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1569) substr($res, $off, 1, 'X');
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1570) } else {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1571) substr($res, $off, 1, $c);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1572) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1573) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1574)
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1575) if ($sanitise_quote eq '//') {
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1576) $sanitise_quote = '';
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1577) }
113f04a836481 (Daniel Walker 2009-09-21 17:04:35 -0700 1578)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1579) # The pathname on a #include may be surrounded by '<' and '>'.
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 1580) if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1581) my $clean = 'X' x length($1);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1582) $res =~ s@\<.*\>@<$clean>@;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1583)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1584) # The whole of a #error is a string.
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 1585) } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1586) my $clean = 'X' x length($1);
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 1587) $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1588) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1589)
dadf680de3c2e (Joe Perches 2016-08-02 14:04:33 -0700 1590) if ($allow_c99_comments && $res =~ m@(//.*$)@) {
dadf680de3c2e (Joe Perches 2016-08-02 14:04:33 -0700 1591) my $match = $1;
dadf680de3c2e (Joe Perches 2016-08-02 14:04:33 -0700 1592) $res =~ s/\Q$match\E/"$;" x length($match)/e;
dadf680de3c2e (Joe Perches 2016-08-02 14:04:33 -0700 1593) }
dadf680de3c2e (Joe Perches 2016-08-02 14:04:33 -0700 1594)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1595) return $res;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1596) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1597)
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 1598) sub get_quoted_string {
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 1599) my ($line, $rawline) = @_;
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 1600)
478b17998066a (Joe Perches 2018-04-10 16:33:34 -0700 1601) return "" if (!defined($line) || !defined($rawline));
33acb54a4379c (Joe Perches 2015-06-25 15:02:54 -0700 1602) return "" if ($line !~ m/($String)/g);
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 1603) return substr($rawline, $-[0], $+[0] - $-[0]);
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 1604) }
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 1605)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1606) sub ctx_statement_block {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1607) my ($linenr, $remain, $off) = @_;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1608) my $line = $linenr - 1;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1609) my $blk = '';
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1610) my $soff = $off;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1611) my $coff = $off - 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1612) my $coff_set = 0;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1613)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1614) my $loff = 0;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1615)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1616) my $type = '';
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1617) my $level = 0;
a27506459c5e6 (Andy Whitcroft 2009-01-15 13:51:04 -0800 1618) my @stack = ();
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1619) my $p;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1620) my $c;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1621) my $len = 0;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1622)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1623) my $remainder;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1624) while (1) {
a27506459c5e6 (Andy Whitcroft 2009-01-15 13:51:04 -0800 1625) @stack = (['', 0]) if ($#stack == -1);
a27506459c5e6 (Andy Whitcroft 2009-01-15 13:51:04 -0800 1626)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1627) #warn "CSB: blk<$blk> remain<$remain>\n";
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1628) # If we are about to drop off the end, pull in more
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1629) # context.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1630) if ($off >= $len) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1631) for (; $remain > 0; $line++) {
dea33496ddc2b (Andy Whitcroft 2008-10-15 22:02:25 -0700 1632) last if (!defined $lines[$line]);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1633) next if ($lines[$line] =~ /^-/);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1634) $remain--;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1635) $loff = $len;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1636) $blk .= $lines[$line] . "\n";
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1637) $len = length($blk);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1638) $line++;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1639) last;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1640) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1641) # Bail if there is no further context.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1642) #warn "CSB: blk<$blk> off<$off> len<$len>\n";
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1643) if ($off >= $len) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1644) last;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1645) }
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1646) if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1647) $level++;
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1648) $type = '#';
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1649) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1650) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1651) $p = $c;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1652) $c = substr($blk, $off, 1);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1653) $remainder = substr($blk, $off);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1654)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1655) #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1656)
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1657) # Handle nested #if/#else.
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1658) if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1659) push(@stack, [ $type, $level ]);
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1660) } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1661) ($type, $level) = @{$stack[$#stack - 1]};
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1662) } elsif ($remainder =~ /^#\s*endif\b/) {
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1663) ($type, $level) = @{pop(@stack)};
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1664) }
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1665)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1666) # Statement ends at the ';' or a close '}' at the
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1667) # outermost level.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1668) if ($level == 0 && $c eq ';') {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1669) last;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1670) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1671)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1672) # An else is really a conditional as long as its not else if
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1673) if ($level == 0 && $coff_set == 0 &&
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1674) (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1675) $remainder =~ /^(else)(?:\s|{)/ &&
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1676) $remainder !~ /^else\s+if\b/) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1677) $coff = $off + length($1) - 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1678) $coff_set = 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1679) #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1680) #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1681) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1682)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1683) if (($type eq '' || $type eq '(') && $c eq '(') {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1684) $level++;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1685) $type = '(';
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1686) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1687) if ($type eq '(' && $c eq ')') {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1688) $level--;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1689) $type = ($level != 0)? '(' : '';
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1690)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1691) if ($level == 0 && $coff < $soff) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1692) $coff = $off;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1693) $coff_set = 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1694) #warn "CSB: mark coff<$coff>\n";
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1695) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1696) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1697) if (($type eq '' || $type eq '{') && $c eq '{') {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1698) $level++;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1699) $type = '{';
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1700) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1701) if ($type eq '{' && $c eq '}') {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1702) $level--;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1703) $type = ($level != 0)? '{' : '';
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1704)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1705) if ($level == 0) {
b998e001e6ce6 (Patrick Pannuto 2010-08-09 17:21:03 -0700 1706) if (substr($blk, $off + 1, 1) eq ';') {
b998e001e6ce6 (Patrick Pannuto 2010-08-09 17:21:03 -0700 1707) $off++;
b998e001e6ce6 (Patrick Pannuto 2010-08-09 17:21:03 -0700 1708) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1709) last;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1710) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1711) }
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1712) # Preprocessor commands end at the newline unless escaped.
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1713) if ($type eq '#' && $c eq "\n" && $p ne "\\") {
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1714) $level--;
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1715) $type = '';
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1716) $off++;
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1717) last;
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 1718) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1719) $off++;
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1720) }
a3bb97a7aba36 (Andy Whitcroft 2008-07-23 21:29:00 -0700 1721) # We are truly at the end, so shuffle to the next line.
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1722) if ($off == $len) {
a3bb97a7aba36 (Andy Whitcroft 2008-07-23 21:29:00 -0700 1723) $loff = $len + 1;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1724) $line++;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1725) $remain--;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1726) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1727)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1728) my $statement = substr($blk, $soff, $off - $soff + 1);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1729) my $condition = substr($blk, $soff, $coff - $soff + 1);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1730)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1731) #warn "STATEMENT<$statement>\n";
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1732) #warn "CONDITION<$condition>\n";
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1733)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1734) #print "coff<$coff> soff<$off> loff<$loff>\n";
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1735)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1736) return ($statement, $condition,
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1737) $line, $remain + 1, $off - $loff + 1, $level);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1738) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1739)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1740) sub statement_lines {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1741) my ($stmt) = @_;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1742)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1743) # Strip the diff line prefixes and rip blank lines at start and end.
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1744) $stmt =~ s/(^|\n)./$1/g;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1745) $stmt =~ s/^\s*//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1746) $stmt =~ s/\s*$//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1747)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1748) my @stmt_lines = ($stmt =~ /\n/g);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1749)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1750) return $#stmt_lines + 2;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1751) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1752)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1753) sub statement_rawlines {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1754) my ($stmt) = @_;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1755)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1756) my @stmt_lines = ($stmt =~ /\n/g);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1757)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1758) return $#stmt_lines + 2;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1759) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1760)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1761) sub statement_block_size {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1762) my ($stmt) = @_;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1763)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1764) $stmt =~ s/(^|\n)./$1/g;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1765) $stmt =~ s/^\s*{//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1766) $stmt =~ s/}\s*$//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1767) $stmt =~ s/^\s*//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1768) $stmt =~ s/\s*$//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1769)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1770) my @stmt_lines = ($stmt =~ /\n/g);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1771) my @stmt_statements = ($stmt =~ /;/g);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1772)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1773) my $stmt_lines = $#stmt_lines + 2;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1774) my $stmt_statements = $#stmt_statements + 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1775)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1776) if ($stmt_lines > $stmt_statements) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1777) return $stmt_lines;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1778) } else {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1779) return $stmt_statements;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1780) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1781) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1782)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1783) sub ctx_statement_full {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1784) my ($linenr, $remain, $off) = @_;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1785) my ($statement, $condition, $level);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1786)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1787) my (@chunks);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1788)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1789) # Grab the first conditional/block pair.
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1790) ($statement, $condition, $linenr, $remain, $off, $level) =
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1791) ctx_statement_block($linenr, $remain, $off);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1792) #print "F: c<$condition> s<$statement> remain<$remain>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1793) push(@chunks, [ $condition, $statement ]);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1794) if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1795) return ($level, $linenr, @chunks);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1796) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1797)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1798) # Pull in the following conditional/block pairs and see if they
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1799) # could continue the statement.
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1800) for (;;) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1801) ($statement, $condition, $linenr, $remain, $off, $level) =
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1802) ctx_statement_block($linenr, $remain, $off);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1803) #print "C: c<$condition> s<$statement> remain<$remain>\n";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 1804) last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1805) #print "C: push\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1806) push(@chunks, [ $condition, $statement ]);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1807) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1808)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 1809) return ($level, $linenr, @chunks);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1810) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 1811)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1812) sub ctx_block_get {
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1813) my ($linenr, $remain, $outer, $open, $close, $off) = @_;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1814) my $line;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1815) my $start = $linenr - 1;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1816) my $blk = '';
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1817) my @o;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1818) my @c;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1819) my @res = ();
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1820)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1821) my $level = 0;
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1822) my @stack = ($level);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1823) for ($line = $start; $remain > 0; $line++) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1824) next if ($rawlines[$line] =~ /^-/);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1825) $remain--;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1826)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1827) $blk .= $rawlines[$line];
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1828)
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1829) # Handle nested #if/#else.
01464f30a97c5 (Andy Whitcroft 2010-10-26 14:23:19 -0700 1830) if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1831) push(@stack, $level);
01464f30a97c5 (Andy Whitcroft 2010-10-26 14:23:19 -0700 1832) } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1833) $level = $stack[$#stack - 1];
01464f30a97c5 (Andy Whitcroft 2010-10-26 14:23:19 -0700 1834) } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1835) $level = pop(@stack);
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1836) }
4635f4fbaf515 (Andy Whitcroft 2009-01-06 14:41:27 -0800 1837)
01464f30a97c5 (Andy Whitcroft 2010-10-26 14:23:19 -0700 1838) foreach my $c (split(//, $lines[$line])) {
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1839) ##print "C<$c>L<$level><$open$close>O<$off>\n";
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1840) if ($off > 0) {
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1841) $off--;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1842) next;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1843) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1844)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1845) if ($c eq $close && $level > 0) {
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1846) $level--;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1847) last if ($level == 0);
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1848) } elsif ($c eq $open) {
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1849) $level++;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1850) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1851) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1852)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1853) if (!$outer || $level <= 1) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1854) push(@res, $rawlines[$line]);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1855) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1856)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1857) last if ($level == 0);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1858) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1859)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1860) return ($level, @res);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1861) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1862) sub ctx_block_outer {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1863) my ($linenr, $remain) = @_;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1864)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1865) my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1866) return @r;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1867) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1868) sub ctx_block {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1869) my ($linenr, $remain) = @_;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1870)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1871) my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1872) return @r;
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 1873) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 1874) sub ctx_statement {
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1875) my ($linenr, $remain, $off) = @_;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1876)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1877) my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1878) return @r;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1879) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1880) sub ctx_block_level {
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 1881) my ($linenr, $remain) = @_;
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 1882)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 1883) return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1884) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1885) sub ctx_statement_level {
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1886) my ($linenr, $remain, $off) = @_;
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1887)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1888) return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1889) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1890)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1891) sub ctx_locate_comment {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1892) my ($first_line, $end_line) = @_;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1893)
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1894) # If c99 comment on the current line, or the line before or after
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1895) my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1896) return $current_comment if (defined $current_comment);
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1897) ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1898) return $current_comment if (defined $current_comment);
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1899) ($current_comment) = ($rawlines[$end_line] =~ m@^[\+ ].*(//.*$)@);
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1900) return $current_comment if (defined $current_comment);
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1901)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1902) # Catch a comment on the end of the line itself.
a55ee0cc09a4e (Joe Perches 2020-06-04 16:50:36 -0700 1903) ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1904) return $current_comment if (defined $current_comment);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1905)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1906) # Look through the context and try and figure out if there is a
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1907) # comment.
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1908) my $in_comment = 0;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1909) $current_comment = '';
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1910) for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1911) my $line = $rawlines[$linenr - 1];
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1912) #warn " $line\n";
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1913) if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1914) $in_comment = 1;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1915) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1916) if ($line =~ m@/\*@) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1917) $in_comment = 1;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1918) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1919) if (!$in_comment && $current_comment ne '') {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1920) $current_comment = '';
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1921) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1922) $current_comment .= $line . "\n" if ($in_comment);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1923) if ($line =~ m@\*/@) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1924) $in_comment = 0;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1925) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1926) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1927)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1928) chomp($current_comment);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1929) return($current_comment);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1930) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1931) sub ctx_has_comment {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1932) my ($first_line, $end_line) = @_;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1933) my $cmt = ctx_locate_comment($first_line, $end_line);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1934)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 1935) ##print "LINE: $rawlines[$end_line - 1 ]\n";
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1936) ##print "CMMT: $cmt\n";
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1937)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1938) return ($cmt ne '');
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1939) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 1940)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1941) sub raw_line {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1942) my ($linenr, $cnt) = @_;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1943)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1944) my $offset = $linenr - 1;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1945) $cnt++;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1946)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1947) my $line;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1948) while ($cnt) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1949) $line = $rawlines[$offset++];
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1950) next if (defined($line) && $line =~ /^-/);
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1951) $cnt--;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1952) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1953)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1954) return $line;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1955) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 1956)
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1957) sub get_stat_real {
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1958) my ($linenr, $lc) = @_;
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1959)
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1960) my $stat_real = raw_line($linenr, 0);
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1961) for (my $count = $linenr + 1; $count <= $lc; $count++) {
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1962) $stat_real = $stat_real . "\n" . raw_line($count, 0);
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1963) }
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1964)
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1965) return $stat_real;
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1966) }
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 1967)
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1968) sub get_stat_here {
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1969) my ($linenr, $cnt, $here) = @_;
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1970)
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1971) my $herectx = $here . "\n";
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1972) for (my $n = 0; $n < $cnt; $n++) {
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1973) $herectx .= raw_line($linenr, $n) . "\n";
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1974) }
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1975)
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1976) return $herectx;
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1977) }
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 1978)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1979) sub cat_vet {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1980) my ($vet) = @_;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1981) my ($res, $coded);
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1982)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1983) $res = '';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1984) while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1985) $res .= $1;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1986) if ($2 ne '') {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1987) $coded = sprintf("^%c", unpack('C', $2) + 64);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1988) $res .= $coded;
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1989) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1990) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1991) $res =~ s/$/\$/;
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1992)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 1993) return $res;
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1994) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 1995)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1996) my $av_preprocessor = 0;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 1997) my $av_pending;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 1998) my @av_paren_type;
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 1999) my $av_pend_colon;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2000)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2001) sub annotate_reset {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2002) $av_preprocessor = 0;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2003) $av_pending = '_';
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2004) @av_paren_type = ('E');
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2005) $av_pend_colon = 'O';
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2006) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2007)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2008) sub annotate_values {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2009) my ($stream, $type) = @_;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2010)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2011) my $res;
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2012) my $var = '_' x length($stream);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2013) my $cur = $stream;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2014)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2015) print "$stream\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2016)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2017) while (length($cur)) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2018) @av_paren_type = ('E') if ($#av_paren_type < 0);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2019) print " <" . join('', @av_paren_type) .
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2020) "> <$type> <$av_pending>" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2021) if ($cur =~ /^(\s+)/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2022) print "WS($1)\n" if ($dbg_values > 1);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2023) if ($1 =~ /\n/ && $av_preprocessor) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2024) $type = pop(@av_paren_type);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2025) $av_preprocessor = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2026) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2027)
c023e4734c3e8 (Florian Mickler 2011-01-12 16:59:58 -0800 2028) } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
9446ef569c288 (Andy Whitcroft 2010-10-26 14:23:13 -0700 2029) print "CAST($1)\n" if ($dbg_values > 1);
9446ef569c288 (Andy Whitcroft 2010-10-26 14:23:13 -0700 2030) push(@av_paren_type, $type);
addcdcea99514 (Andy Whitcroft 2012-01-10 15:10:11 -0800 2031) $type = 'c';
9446ef569c288 (Andy Whitcroft 2010-10-26 14:23:13 -0700 2032)
e91b6e263ed67 (Andy Whitcroft 2010-10-26 14:23:11 -0700 2033) } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2034) print "DECLARE($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2035) $type = 'T';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2036)
389a2fe57ffc5 (Andy Whitcroft 2008-07-23 21:29:05 -0700 2037) } elsif ($cur =~ /^($Modifier)\s*/) {
389a2fe57ffc5 (Andy Whitcroft 2008-07-23 21:29:05 -0700 2038) print "MODIFIER($1)\n" if ($dbg_values > 1);
389a2fe57ffc5 (Andy Whitcroft 2008-07-23 21:29:05 -0700 2039) $type = 'T';
389a2fe57ffc5 (Andy Whitcroft 2008-07-23 21:29:05 -0700 2040)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2041) } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2042) print "DEFINE($1,$2)\n" if ($dbg_values > 1);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2043) $av_preprocessor = 1;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2044) push(@av_paren_type, $type);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2045) if ($2 ne '') {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2046) $av_pending = 'N';
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2047) }
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2048) $type = 'E';
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2049)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2050) } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2051) print "UNDEF($1)\n" if ($dbg_values > 1);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2052) $av_preprocessor = 1;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2053) push(@av_paren_type, $type);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2054)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2055) } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2056) print "PRE_START($1)\n" if ($dbg_values > 1);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2057) $av_preprocessor = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2058)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2059) push(@av_paren_type, $type);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2060) push(@av_paren_type, $type);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2061) $type = 'E';
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2062)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2063) } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2064) print "PRE_RESTART($1)\n" if ($dbg_values > 1);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2065) $av_preprocessor = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2066)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2067) push(@av_paren_type, $av_paren_type[$#av_paren_type]);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2068)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2069) $type = 'E';
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2070)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2071) } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2072) print "PRE_END($1)\n" if ($dbg_values > 1);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2073)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2074) $av_preprocessor = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2075)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2076) # Assume all arms of the conditional end as this
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2077) # one does, and continue as if the #endif was not here.
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2078) pop(@av_paren_type);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2079) push(@av_paren_type, $type);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2080) $type = 'E';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2081)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2082) } elsif ($cur =~ /^(\\\n)/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2083) print "PRECONT($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2084)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2085) } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2086) print "ATTR($1)\n" if ($dbg_values > 1);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2087) $av_pending = $type;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2088) $type = 'N';
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2089)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2090) } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2091) print "SIZEOF($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2092) if (defined $2) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2093) $av_pending = 'V';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2094) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2095) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2096)
14b111c158116 (Andy Whitcroft 2008-10-15 22:02:16 -0700 2097) } elsif ($cur =~ /^(if|while|for)\b/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2098) print "COND($1)\n" if ($dbg_values > 1);
14b111c158116 (Andy Whitcroft 2008-10-15 22:02:16 -0700 2099) $av_pending = 'E';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2100) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2101)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2102) } elsif ($cur =~/^(case)/o) {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2103) print "CASE($1)\n" if ($dbg_values > 1);
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2104) $av_pend_colon = 'C';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2105) $type = 'N';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2106)
14b111c158116 (Andy Whitcroft 2008-10-15 22:02:16 -0700 2107) } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2108) print "KEYWORD($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2109) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2110)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2111) } elsif ($cur =~ /^(\()/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2112) print "PAREN('$1')\n" if ($dbg_values > 1);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2113) push(@av_paren_type, $av_pending);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2114) $av_pending = '_';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2115) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2116)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2117) } elsif ($cur =~ /^(\))/o) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2118) my $new_type = pop(@av_paren_type);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2119) if ($new_type ne '_') {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2120) $type = $new_type;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2121) print "PAREN('$1') -> $type\n"
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2122) if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2123) } else {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2124) print "PAREN('$1')\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2125) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2126)
c8cb2ca37ed51 (Andy Whitcroft 2008-07-23 21:28:57 -0700 2127) } elsif ($cur =~ /^($Ident)\s*\(/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2128) print "FUNC($1)\n" if ($dbg_values > 1);
c8cb2ca37ed51 (Andy Whitcroft 2008-07-23 21:28:57 -0700 2129) $type = 'V';
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2130) $av_pending = 'V';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2131)
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2132) } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2133) if (defined $2 && $type eq 'C' || $type eq 'T') {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2134) $av_pend_colon = 'B';
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2135) } elsif ($type eq 'E') {
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2136) $av_pend_colon = 'L';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2137) }
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2138) print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2139) $type = 'V';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2140)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2141) } elsif ($cur =~ /^($Ident|$Constant)/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2142) print "IDENT($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2143) $type = 'V';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2144)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2145) } elsif ($cur =~ /^($Assignment)/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2146) print "ASSIGN($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2147) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2148)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 2149) } elsif ($cur =~/^(;|{|})/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2150) print "END($1)\n" if ($dbg_values > 1);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2151) $type = 'E';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2152) $av_pend_colon = 'O';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2153)
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2154) } elsif ($cur =~/^(,)/) {
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2155) print "COMMA($1)\n" if ($dbg_values > 1);
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2156) $type = 'C';
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2157)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2158) } elsif ($cur =~ /^(\?)/o) {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2159) print "QUESTION($1)\n" if ($dbg_values > 1);
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2160) $type = 'N';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2161)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2162) } elsif ($cur =~ /^(:)/o) {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2163) print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2164)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2165) substr($var, length($res), 1, $av_pend_colon);
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2166) if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2167) $type = 'E';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2168) } else {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2169) $type = 'N';
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2170) }
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2171) $av_pend_colon = 'O';
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2172)
8e761b04a3428 (Andy Whitcroft 2009-01-06 14:41:19 -0800 2173) } elsif ($cur =~ /^(\[)/o) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2174) print "CLOSE($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2175) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2176)
0d413866c7df6 (Andy Whitcroft 2008-10-15 22:02:16 -0700 2177) } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2178) my $variant;
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2179)
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2180) print "OPV($1)\n" if ($dbg_values > 1);
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2181) if ($type eq 'V') {
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2182) $variant = 'B';
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2183) } else {
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2184) $variant = 'U';
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2185) }
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2186)
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2187) substr($var, length($res), 1, $variant);
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2188) $type = 'N';
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2189)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2190) } elsif ($cur =~ /^($Operators)/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2191) print "OP($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2192) if ($1 ne '++' && $1 ne '--') {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2193) $type = 'N';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2194) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2195)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2196) } elsif ($cur =~ /(^.)/o) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2197) print "C($1)\n" if ($dbg_values > 1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2198) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2199) if (defined $1) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2200) $cur = substr($cur, length($1));
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2201) $res .= $type x length($1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2202) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 2203) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2204)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 2205) return ($res, $var);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2206) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2207)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 2208) sub possible {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2209) my ($possible, $line) = @_;
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2210) my $notPermitted = qr{(?:
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2211) ^(?:
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2212) $Modifier|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2213) $Storage|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2214) $Type|
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2215) DEFINE_\S+
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2216) )$|
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2217) ^(?:
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2218) goto|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2219) return|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2220) case|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2221) else|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2222) asm|__asm__|
89a883530fe79 (Andy Whitcroft 2012-01-10 15:10:00 -0800 2223) do|
89a883530fe79 (Andy Whitcroft 2012-01-10 15:10:00 -0800 2224) \#|
89a883530fe79 (Andy Whitcroft 2012-01-10 15:10:00 -0800 2225) \#\#|
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2226) )(?:\s|$)|
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2227) ^(?:typedef|struct|enum)\b
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2228) )}x;
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2229) warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2230) if ($possible !~ $notPermitted) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2231) # Check for modifiers.
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2232) $possible =~ s/\s*$Storage\s*//g;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2233) $possible =~ s/\s*$Sparse\s*//g;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2234) if ($possible =~ /^\s*$/) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2235)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2236) } elsif ($possible =~ /\s/) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2237) $possible =~ s/\s*$Type\s*//g;
d2506586586c5 (Andy Whitcroft 2008-07-23 21:29:09 -0700 2238) for my $modifier (split(' ', $possible)) {
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2239) if ($modifier !~ $notPermitted) {
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2240) warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 2241) push(@modifierListFile, $modifier);
9a974fdbe3fbb (Andy Whitcroft 2009-10-26 16:50:12 -0700 2242) }
d2506586586c5 (Andy Whitcroft 2008-07-23 21:29:09 -0700 2243) }
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2244)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2245) } else {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2246) warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
485ff23ed2575 (Alex Dowad 2015-06-25 15:02:52 -0700 2247) push(@typeListFile, $possible);
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2248) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 2249) build_types();
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2250) } else {
0776e594606e3 (Andy Whitcroft 2008-10-15 22:02:29 -0700 2251) warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 2252) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 2253) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 2254)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2255) my $prefix = '';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2256)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2257) sub show_type {
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2258) my ($type) = @_;
91bfe4843dff4 (Joe Perches 2013-09-11 14:23:59 -0700 2259)
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 2260) $type =~ tr/[a-z]/[A-Z]/;
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 2261)
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2262) return defined $use_type{$type} if (scalar keys %use_type > 0);
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2263)
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2264) return !defined $ignore_type{$type};
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2265) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2266)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 2267) sub report {
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2268) my ($level, $type, $msg) = @_;
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2269)
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2270) if (!show_type($type) ||
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2271) (defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2272) return 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2273) }
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2274) my $output = '';
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 2275) if ($color) {
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2276) if ($level eq 'ERROR') {
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2277) $output .= RED;
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2278) } elsif ($level eq 'WARNING') {
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2279) $output .= YELLOW;
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2280) } else {
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2281) $output .= GREEN;
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2282) }
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2283) }
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2284) $output .= $prefix . $level . ':';
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2285) if ($show_types) {
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 2286) $output .= BLUE if ($color);
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2287) $output .= "$type:";
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2288) }
737c0767758bb (John Brooks 2017-07-10 15:52:24 -0700 2289) $output .= RESET if ($color);
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2290) $output .= ' ' . $msg . "\n";
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2291)
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2292) if ($showfile) {
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2293) my @lines = split("\n", $output, -1);
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2294) splice(@lines, 1, 1);
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2295) $output = join("\n", @lines);
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2296) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2297)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2298) if ($terse) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2299) $output = (split('\n', $output))[0] . "\n";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2300) }
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2301)
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2302) if ($verbose && exists($verbose_messages{$type}) &&
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2303) !exists($verbose_emitted{$type})) {
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2304) $output .= $verbose_messages{$type} . "\n\n";
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2305) $verbose_emitted{$type} = 1;
52178ce01335d (Dwaipayan Ray 2021-02-26 15:08:26 +0530 2306) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 2307)
57230297116fa (Joe Perches 2015-06-25 15:03:03 -0700 2308) push(our @report, $output);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2309)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2310) return 1;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 2311) }
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2312)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 2313) sub report_dump {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2314) our @report;
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 2315) }
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2316)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2317) sub fixup_current_range {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2318) my ($lineRef, $offset, $length) = @_;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2319)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2320) if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2321) my $o = $1;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2322) my $l = $2;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2323) my $no = $o + $offset;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2324) my $nl = $l + $length;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2325) $$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2326) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2327) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2328)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2329) sub fix_inserted_deleted_lines {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2330) my ($linesRef, $insertedRef, $deletedRef) = @_;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2331)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2332) my $range_last_linenr = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2333) my $delta_offset = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2334)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2335) my $old_linenr = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2336) my $new_linenr = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2337)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2338) my $next_insert = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2339) my $next_delete = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2340)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2341) my @lines = ();
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2342)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2343) my $inserted = @{$insertedRef}[$next_insert++];
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2344) my $deleted = @{$deletedRef}[$next_delete++];
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2345)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2346) foreach my $old_line (@{$linesRef}) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2347) my $save_line = 1;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2348) my $line = $old_line; #don't modify the array
323b267faff4d (Joe Perches 2015-04-16 12:44:50 -0700 2349) if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2350) $delta_offset = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2351) } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2352) $range_last_linenr = $new_linenr;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2353) fixup_current_range(\$line, $delta_offset, 0);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2354) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2355)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2356) while (defined($deleted) && ${$deleted}{'LINENR'} == $old_linenr) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2357) $deleted = @{$deletedRef}[$next_delete++];
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2358) $save_line = 0;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2359) fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2360) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2361)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2362) while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2363) push(@lines, ${$inserted}{'LINE'});
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2364) $inserted = @{$insertedRef}[$next_insert++];
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2365) $new_linenr++;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2366) fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2367) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2368)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2369) if ($save_line) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2370) push(@lines, $line);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2371) $new_linenr++;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2372) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2373)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2374) $old_linenr++;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2375) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2376)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2377) return @lines;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2378) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 2379)
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2380) sub fix_insert_line {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2381) my ($linenr, $line) = @_;
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2382)
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2383) my $inserted = {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2384) LINENR => $linenr,
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2385) LINE => $line,
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2386) };
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2387) push(@fixed_inserted, $inserted);
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2388) }
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2389)
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2390) sub fix_delete_line {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2391) my ($linenr, $line) = @_;
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2392)
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2393) my $deleted = {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2394) LINENR => $linenr,
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2395) LINE => $line,
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2396) };
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2397)
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2398) push(@fixed_deleted, $deleted);
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2399) }
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 2400)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2401) sub ERROR {
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2402) my ($type, $msg) = @_;
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2403)
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2404) if (report("ERROR", $type, $msg)) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2405) our $clean = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2406) our $cnt_error++;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2407) return 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2408) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2409) return 0;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2410) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2411) sub WARN {
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2412) my ($type, $msg) = @_;
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2413)
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2414) if (report("WARNING", $type, $msg)) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2415) our $clean = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2416) our $cnt_warn++;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2417) return 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2418) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2419) return 0;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2420) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2421) sub CHK {
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2422) my ($type, $msg) = @_;
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2423)
cbec18afcc82a (Joe Perches 2014-04-03 14:49:19 -0700 2424) if ($check && report("CHECK", $type, $msg)) {
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2425) our $clean = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2426) our $cnt_chk++;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2427) return 1;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2428) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2429) return 0;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2430) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2431)
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2432) sub check_absolute_file {
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2433) my ($absolute, $herecurr) = @_;
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2434) my $file = $absolute;
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2435)
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2436) ##print "absolute<$absolute>\n";
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2437)
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2438) # See if any suffix of this path is a path within the tree.
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2439) while ($file =~ s@^[^/]*/@@) {
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2440) if (-f "$root/$file") {
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2441) ##print "file<$file>\n";
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2442) last;
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2443) }
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2444) }
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2445) if (! -f _) {
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2446) return 0;
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2447) }
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2448)
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2449) # It is, so see if the prefix is acceptable.
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2450) my $prefix = $absolute;
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2451) substr($prefix, -length($file)) = '';
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2452)
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2453) ##print "prefix<$prefix>\n";
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2454) if ($prefix ne ".../") {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2455) WARN("USE_RELATIVE_PATH",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2456) "use relative pathname instead of absolute in changelog text\n" . $herecurr);
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2457) }
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2458) }
6ecd967444223 (Andy Whitcroft 2008-10-15 22:02:21 -0700 2459)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2460) sub trim {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2461) my ($string) = @_;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2462)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2463) $string =~ s/^\s+|\s+$//g;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2464)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2465) return $string;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2466) }
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2467)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2468) sub ltrim {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2469) my ($string) = @_;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2470)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2471) $string =~ s/^\s+//;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2472)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2473) return $string;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2474) }
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2475)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2476) sub rtrim {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2477) my ($string) = @_;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2478)
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 2479) $string =~ s/\s+$//;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2480)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2481) return $string;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2482) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2483)
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2484) sub string_find_replace {
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2485) my ($string, $find, $replace) = @_;
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2486)
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2487) $string =~ s/$find/$replace/g;
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2488)
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2489) return $string;
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2490) }
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 2491)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2492) sub tabify {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2493) my ($leading) = @_;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2494)
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 2495) my $source_indent = $tabsize;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2496) my $max_spaces_before_tab = $source_indent - 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2497) my $spaces_to_tab = " " x $source_indent;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2498)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2499) #convert leading spaces to tabs
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2500) 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2501) #Remove spaces before a tab
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2502) 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2503)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2504) return "$leading";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2505) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2506)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2507) sub pos_last_openparen {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2508) my ($line) = @_;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2509)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2510) my $pos = 0;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2511)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2512) my $opens = $line =~ tr/\(/\(/;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2513) my $closes = $line =~ tr/\)/\)/;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2514)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2515) my $last_openparen = 0;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2516)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2517) if (($opens == 0) || ($closes >= $opens)) {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2518) return -1;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2519) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2520)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2521) my $len = length($line);
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2522)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2523) for ($pos = 0; $pos < $len; $pos++) {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2524) my $string = substr($line, $pos);
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2525) if ($string =~ /^($FuncArg|$balanced_parens)/) {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2526) $pos += length($1) - 1;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2527) } elsif (substr($line, $pos, 1) eq '(') {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2528) $last_openparen = $pos;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2529) } elsif (index($string, '(') == -1) {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2530) last;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2531) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2532) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2533)
91cb5195ff224 (Joe Perches 2014-04-03 14:49:32 -0700 2534) return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2535) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 2536)
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2537) sub get_raw_comment {
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2538) my ($line, $rawline) = @_;
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2539) my $comment = '';
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2540)
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2541) for my $i (0 .. (length($line) - 1)) {
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2542) if (substr($line, $i, 1) eq "$;") {
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2543) $comment .= substr($rawline, $i, 1);
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2544) }
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2545) }
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2546)
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2547) return $comment;
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2548) }
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2549)
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2550) sub exclude_global_initialisers {
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2551) my ($realfile) = @_;
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2552)
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2553) # Do not check for BPF programs (tools/testing/selftests/bpf/progs/*.c, samples/bpf/*_kern.c, *.bpf.c).
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2554) return $realfile =~ m@^tools/testing/selftests/bpf/progs/.*\.c$@ ||
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2555) $realfile =~ m@^samples/bpf/.*_kern\.c$@ ||
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2556) $realfile =~ m@/bpf/.*\.bpf\.c$@;
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2557) }
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 2558)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2559) sub process {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2560) my $filename = shift;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2561)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2562) my $linenr=0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2563) my $prevline="";
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2564) my $prevrawline="";
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2565) my $stashline="";
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2566) my $stashrawline="";
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2567)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2568) my $length;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2569) my $indent;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2570) my $previndent=0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2571) my $stashindent=0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2572)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2573) our $clean = 1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2574) my $signoff = 0;
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2575) my $author = '';
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2576) my $authorsignoff = 0;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2577) my $author_sob = '';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2578) my $is_patch = 0;
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2579) my $is_binding_patch = -1;
29ee1b0c67e0d (Joe Perches 2014-08-06 16:10:35 -0700 2580) my $in_header_lines = $file ? 0 : 1;
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 2581) my $in_commit_log = 0; #Scanning lines before patch
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2582) my $has_patch_separator = 0; #Found a --- line
ed43c4e58a6d3 (Allen Hubbe 2016-08-02 14:04:45 -0700 2583) my $has_commit_log = 0; #Encountered lines before patch
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2584) my $commit_log_lines = 0; #Number of commit log lines
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 2585) my $commit_log_possible_stack_dump = 0;
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 2586) my $commit_log_long_line = 0;
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2587) my $commit_log_has_diff = 0;
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 2588) my $reported_maintainer_file = 0;
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 2589) my $non_utf8_charset = 0;
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 2590)
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 2591) my $last_git_commit_id_linenr = -1;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 2592)
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 2593) my $last_blank_line = 0;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 2594) my $last_coalesced_string_linenr = -1;
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 2595)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2596) our @report = ();
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2597) our $cnt_lines = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2598) our $cnt_error = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2599) our $cnt_warn = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2600) our $cnt_chk = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2601)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2602) # Trace the real file/line as we go.
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2603) my $realfile = '';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2604) my $realline = 0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2605) my $realcnt = 0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2606) my $here = '';
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 2607) my $context_function; #undef'd unless there's a known function
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2608) my $in_comment = 0;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2609) my $comment_edge = 0;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2610) my $first_line = 0;
1e85572697b34 (Wolfram Sang 2009-01-06 14:41:24 -0800 2611) my $p1_prefix = '';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2612)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2613) my $prev_values = 'E';
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2614)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2615) # suppression flags
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2616) my %suppress_ifbraces;
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 2617) my %suppress_whiletrailers;
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 2618) my %suppress_export;
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 2619) my $suppress_statement = 0;
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 2620)
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 2621) my %signatures = ();
323c1260ba2c4 (Joe Perches 2012-12-17 16:02:07 -0800 2622)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2623) # Pre-scan the patch sanitizing the lines.
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2624) # Pre-scan the patch looking for any __setup documentation.
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2625) #
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2626) my @setup_docs = ();
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2627) my $setup_docs = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2628)
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 2629) my $camelcase_file_seeded = 0;
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 2630)
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 2631) my $checklicenseline = 1;
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 2632)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2633) sanitise_line_reset();
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2634) my $line;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2635) foreach my $rawline (@rawlines) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2636) $linenr++;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2637) $line = $rawline;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2638)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2639) push(@fixed, $rawline) if ($fix);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2640)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2641) if ($rawline=~/^\+\+\+\s+(\S+)/) {
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2642) $setup_docs = 0;
2581ac7c2f6b0 (Tim Froidcoeur 2020-06-10 18:41:38 -0700 2643) if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2644) $setup_docs = 1;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2645) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2646) #next;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2647) }
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2648) if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2649) $realline=$1-1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2650) if (defined $2) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2651) $realcnt=$3+1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2652) } else {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2653) $realcnt=1+1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2654) }
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 2655) $in_comment = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2656)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2657) # Guestimate if this is a continuing comment. Run
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2658) # the context looking for a comment "edge". If this
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2659) # edge is a close comment then we must be in a comment
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2660) # at context start.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2661) my $edge;
01fa91471e955 (Andy Whitcroft 2008-10-15 22:02:19 -0700 2662) my $cnt = $realcnt;
01fa91471e955 (Andy Whitcroft 2008-10-15 22:02:19 -0700 2663) for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
01fa91471e955 (Andy Whitcroft 2008-10-15 22:02:19 -0700 2664) next if (defined $rawlines[$ln - 1] &&
01fa91471e955 (Andy Whitcroft 2008-10-15 22:02:19 -0700 2665) $rawlines[$ln - 1] =~ /^-/);
01fa91471e955 (Andy Whitcroft 2008-10-15 22:02:19 -0700 2666) $cnt--;
01fa91471e955 (Andy Whitcroft 2008-10-15 22:02:19 -0700 2667) #print "RAW<$rawlines[$ln - 1]>\n";
721c1cb60e054 (Andy Whitcroft 2009-01-06 14:41:16 -0800 2668) last if (!defined $rawlines[$ln - 1]);
fae17daed7312 (Andy Whitcroft 2009-01-06 14:41:20 -0800 2669) if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
fae17daed7312 (Andy Whitcroft 2009-01-06 14:41:20 -0800 2670) $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
fae17daed7312 (Andy Whitcroft 2009-01-06 14:41:20 -0800 2671) ($edge) = $1;
fae17daed7312 (Andy Whitcroft 2009-01-06 14:41:20 -0800 2672) last;
fae17daed7312 (Andy Whitcroft 2009-01-06 14:41:20 -0800 2673) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2674) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2675) if (defined $edge && $edge eq '*/') {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2676) $in_comment = 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2677) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2678)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2679) # Guestimate if this is a continuing comment. If this
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2680) # is the start of a diff block and this line starts
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2681) # ' *' then it is very likely a comment.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2682) if (!defined $edge &&
83242e0c239aa (Andy Whitcroft 2009-01-06 14:41:17 -0800 2683) $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2684) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2685) $in_comment = 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2686) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2687)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2688) ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2689) sanitise_line_reset($in_comment);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2690)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2691) } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2692) # Standardise the strings and chars within the input to
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 2693) # simplify matching -- only bother with positive lines.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2694) $line = sanitise_line($rawline);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2695) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2696) push(@lines, $line);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2697)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2698) if ($realcnt > 1) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2699) $realcnt-- if ($line =~ /^(?:\+| |$)/);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2700) } else {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2701) $realcnt = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2702) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2703)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2704) #print "==>$rawline\n";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2705) #print "-->$line\n";
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2706)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2707) if ($setup_docs && $line =~ /^\+/) {
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2708) push(@setup_docs, $line);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2709) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2710) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 2711)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2712) $prefix = '';
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2713)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2714) $realcnt = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2715) $linenr = 0;
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 2716) $fixlinenr = -1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2717) foreach my $line (@lines) {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2718) $linenr++;
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 2719) $fixlinenr++;
1b5539b1ffbdc (Joe Perches 2013-09-11 14:24:03 -0700 2720) my $sline = $line; #copy of $line
1b5539b1ffbdc (Joe Perches 2013-09-11 14:24:03 -0700 2721) $sline =~ s/$;/ /g; #with comments as spaces
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2722)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2723) my $rawline = $rawlines[$linenr - 1];
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 2724) my $raw_comment = get_raw_comment($line, $rawline);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2725)
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2726) # check if it's a mode change, rename or start of a patch
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2727) if (!$in_commit_log &&
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2728) ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2729) ($line =~ /^rename (?:from|to) \S+\s*$/ ||
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2730) $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2731) $is_patch = 1;
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2732) }
12c253abb9c9d (Joe Perches 2018-06-07 17:10:58 -0700 2733)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2734) #extract the line range in the file after the patch is applied
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2735) if (!$in_commit_log &&
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2736) $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2737) my $context = $4;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2738) $is_patch = 1;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2739) $first_line = $linenr + 1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2740) $realline=$1-1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2741) if (defined $2) {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2742) $realcnt=$3+1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2743) } else {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2744) $realcnt=1+1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2745) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2746) annotate_reset();
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2747) $prev_values = 'E';
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 2748)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2749) %suppress_ifbraces = ();
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 2750) %suppress_whiletrailers = ();
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 2751) %suppress_export = ();
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 2752) $suppress_statement = 0;
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2753) if ($context =~ /\b(\w+)\s*\(/) {
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2754) $context_function = $1;
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2755) } else {
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2756) undef $context_function;
74fd4f347bfc1 (Joe Perches 2017-05-08 15:56:02 -0700 2757) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2758) next;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2759)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2760) # track the line number as we move through the hunk, note that
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2761) # new versions of GNU diff omit the leading space on completely
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2762) # blank context lines so we need to count that too.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2763) } elsif ($line =~ /^( |\+|$)/) {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2764) $realline++;
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 2765) $realcnt-- if ($realcnt != 0);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2766)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2767) # Measure the line length and indent.
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2768) ($length, $indent) = line_stats($rawline);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2769)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2770) # Track the previous line.
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2771) ($prevline, $stashline) = ($stashline, $line);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2772) ($previndent, $stashindent) = ($stashindent, $indent);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2773) ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2774)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2775) #warn "line<$line>\n";
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2776)
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 2777) } elsif ($realcnt == 1) {
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 2778) $realcnt--;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2779) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2780)
cc77cdca5209c (Andy Whitcroft 2009-10-26 16:50:13 -0700 2781) my $hunk_line = ($realcnt != 0);
cc77cdca5209c (Andy Whitcroft 2009-10-26 16:50:13 -0700 2782)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2783) $here = "#$linenr: " if (!$file);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2784) $here = "#$realline: " if ($file);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2785)
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2786) my $found_file = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2787) # extract the filename as it passes
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2788) if ($line =~ /^diff --git.*?(\S+)$/) {
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2789) $realfile = $1;
2b7ab45395dc4 (Joe Perches 2013-11-12 15:10:14 -0800 2790) $realfile =~ s@^([^/]*)/@@ if (!$file);
270c49a088ae5 (Joe Perches 2012-01-10 15:09:50 -0800 2791) $in_commit_log = 0;
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2792) $found_file = 1;
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2793) } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2794) $realfile = $1;
2b7ab45395dc4 (Joe Perches 2013-11-12 15:10:14 -0800 2795) $realfile =~ s@^([^/]*)/@@ if (!$file);
270c49a088ae5 (Joe Perches 2012-01-10 15:09:50 -0800 2796) $in_commit_log = 0;
1e85572697b34 (Wolfram Sang 2009-01-06 14:41:24 -0800 2797)
1e85572697b34 (Wolfram Sang 2009-01-06 14:41:24 -0800 2798) $p1_prefix = $1;
e2f7aa4b8bc81 (Andy Whitcroft 2009-02-27 14:03:06 -0800 2799) if (!$file && $tree && $p1_prefix ne '' &&
e2f7aa4b8bc81 (Andy Whitcroft 2009-02-27 14:03:06 -0800 2800) -e "$root/$p1_prefix") {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2801) WARN("PATCH_PREFIX",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2802) "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
1e85572697b34 (Wolfram Sang 2009-01-06 14:41:24 -0800 2803) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2804)
c1ab33269a84d (Andy Whitcroft 2008-10-15 22:02:20 -0700 2805) if ($realfile =~ m@^include/asm/@) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2806) ERROR("MODIFIED_INCLUDE_ASM",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2807) "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2808) }
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2809) $found_file = 1;
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2810) }
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2811)
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2812) #make up the handle for any error we report on this line
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2813) if ($showfile) {
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2814) $prefix = "$realfile:$realline: "
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2815) } elsif ($emacs) {
7d3a9f673e1bd (Joe Perches 2015-09-09 15:37:39 -0700 2816) if ($file) {
7d3a9f673e1bd (Joe Perches 2015-09-09 15:37:39 -0700 2817) $prefix = "$filename:$realline: ";
7d3a9f673e1bd (Joe Perches 2015-09-09 15:37:39 -0700 2818) } else {
7d3a9f673e1bd (Joe Perches 2015-09-09 15:37:39 -0700 2819) $prefix = "$filename:$linenr: ";
7d3a9f673e1bd (Joe Perches 2015-09-09 15:37:39 -0700 2820) }
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2821) }
34d8815f9512b (Joe Perches 2015-06-25 15:03:05 -0700 2822)
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2823) if ($found_file) {
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 2824) if (is_maintained_obsolete($realfile)) {
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 2825) WARN("OBSOLETE",
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 2826) "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy. No unnecessary modifications please.\n");
85b0ee18bbf82 (Joe Perches 2016-10-11 13:51:44 -0700 2827) }
7bd7e483c27d8 (Joe Perches 2015-09-09 15:37:44 -0700 2828) if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) {
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2829) $check = 1;
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2830) } else {
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2831) $check = $check_orig;
2ac73b4f685e6 (Joe Perches 2014-06-04 16:12:05 -0700 2832) }
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 2833) $checklicenseline = 1;
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2834)
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2835) if ($realfile !~ /^MAINTAINERS/) {
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2836) my $last_binding_patch = $is_binding_patch;
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2837)
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2838) $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2839)
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2840) if (($last_binding_patch != -1) &&
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2841) ($last_binding_patch ^ $is_binding_patch)) {
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2842) WARN("DT_SPLIT_BINDING_PATCH",
858e6845654d9 (Mauro Carvalho Chehab 2020-04-15 16:45:25 +0200 2843) "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n");
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2844) }
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2845) }
133712a2ec849 (Rob Herring 2018-08-21 21:58:16 -0700 2846)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2847) next;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2848) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 2849)
389834b680c13 (Randy Dunlap 2007-06-08 13:47:03 -0700 2850) $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2851)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2852) my $hereline = "$here\n$rawline\n";
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2853) my $herecurr = "$here\n$rawline\n";
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 2854) my $hereprev = "$here\n$prevrawline\n$rawline\n";
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 2855)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2856) $cnt_lines++ if ($realcnt != 0);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 2857)
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2858) # Verify the existence of a commit log if appropriate
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2859) # 2 is used because a $signature is counted in $commit_log_lines
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2860) if ($in_commit_log) {
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2861) if ($line !~ /^\s*$/) {
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2862) $commit_log_lines++; #could be a $signature
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2863) }
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2864) } elsif ($has_commit_log && $commit_log_lines < 2) {
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2865) WARN("COMMIT_MESSAGE",
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2866) "Missing commit description - Add an appropriate one\n");
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2867) $commit_log_lines = 2; #warn only once
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2868) }
490b292c834c5 (Joe Perches 2018-08-21 21:58:01 -0700 2869)
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2870) # Check if the commit log has what seems like a diff which can confuse patch
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2871) if ($in_commit_log && !$commit_log_has_diff &&
13e45417cedbf (Mrinal Pandey 2020-09-04 16:35:52 -0700 2872) (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
13e45417cedbf (Mrinal Pandey 2020-09-04 16:35:52 -0700 2873) $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2874) $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2875) $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2876) ERROR("DIFF_IN_COMMIT_MSG",
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2877) "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2878) $commit_log_has_diff = 1;
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2879) }
e518e9a59ec37 (Joe Perches 2015-06-25 15:03:27 -0700 2880)
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2881) # Check for incorrect file permissions
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2882) if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2883) my $permhere = $here . "FILE: $realfile\n";
04db4d25d9eaa (Joe Perches 2013-04-29 16:18:14 -0700 2884) if ($realfile !~ m@scripts/@ &&
04db4d25d9eaa (Joe Perches 2013-04-29 16:18:14 -0700 2885) $realfile !~ /\.(py|pl|awk|sh)$/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2886) ERROR("EXECUTE_PERMISSIONS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 2887) "do not set execute permissions for source files\n" . $permhere);
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2888) }
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2889) }
3bf9a009fccea (Rabin Vincent 2010-10-26 14:23:16 -0700 2890)
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2891) # Check the patch for a From:
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2892) if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2893) $author = $1;
e7f929f3ca9ec (Dwaipayan Ray 2020-10-15 20:12:15 -0700 2894) my $curline = $linenr;
e7f929f3ca9ec (Dwaipayan Ray 2020-10-15 20:12:15 -0700 2895) while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) {
e7f929f3ca9ec (Dwaipayan Ray 2020-10-15 20:12:15 -0700 2896) $author .= $1;
e7f929f3ca9ec (Dwaipayan Ray 2020-10-15 20:12:15 -0700 2897) }
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2898) $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2899) $author =~ s/"//g;
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 2900) $author = reformat_email($author);
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2901) }
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2902)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2903) # Check the patch for a signoff:
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 2904) if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 2905) $signoff++;
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 2906) $in_commit_log = 0;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2907) if ($author ne '' && $authorsignoff != 1) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 2908) if (same_email_addresses($1, $author)) {
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 2909) $authorsignoff = 1;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2910) } else {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2911) my $ctx = $1;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2912) my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2913) my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2914)
046fc741e35e9 (Mimi Zohar 2021-09-07 19:59:54 -0700 2915) if (lc $email_address eq lc $author_address && $email_name eq $author_name) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2916) $author_sob = $ctx;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2917) $authorsignoff = 2;
046fc741e35e9 (Mimi Zohar 2021-09-07 19:59:54 -0700 2918) } elsif (lc $email_address eq lc $author_address) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2919) $author_sob = $ctx;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2920) $authorsignoff = 3;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2921) } elsif ($email_name eq $author_name) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2922) $author_sob = $ctx;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2923) $authorsignoff = 4;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2924)
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2925) my $address1 = $email_address;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2926) my $address2 = $author_address;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2927)
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2928) if ($address1 =~ /(\S+)\+\S+(\@.*)/) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2929) $address1 = "$1$2";
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2930) }
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2931) if ($address2 =~ /(\S+)\+\S+(\@.*)/) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2932) $address2 = "$1$2";
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2933) }
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2934) if ($address1 eq $address2) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2935) $authorsignoff = 5;
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2936) }
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 2937) }
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2938) }
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 2939) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2940) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2941)
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2942) # Check for patch separator
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2943) if ($line =~ /^---$/) {
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2944) $has_patch_separator = 1;
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2945) $in_commit_log = 0;
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2946) }
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 2947)
e0d975b1b439c (Joe Perches 2014-12-10 15:51:49 -0800 2948) # Check if MAINTAINERS is being updated. If so, there's probably no need to
e0d975b1b439c (Joe Perches 2014-12-10 15:51:49 -0800 2949) # emit the "does MAINTAINERS need updating?" message on file add/move/delete
e0d975b1b439c (Joe Perches 2014-12-10 15:51:49 -0800 2950) if ($line =~ /^\s*MAINTAINERS\s*\|/) {
e0d975b1b439c (Joe Perches 2014-12-10 15:51:49 -0800 2951) $reported_maintainer_file = 1;
e0d975b1b439c (Joe Perches 2014-12-10 15:51:49 -0800 2952) }
e0d975b1b439c (Joe Perches 2014-12-10 15:51:49 -0800 2953)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2954) # Check signature styles
270c49a088ae5 (Joe Perches 2012-01-10 15:09:50 -0800 2955) if (!$in_header_lines &&
ce0338df3c9a4 (Joe Perches 2012-07-30 14:41:18 -0700 2956) $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2957) my $space_before = $1;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2958) my $sign_off = $2;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2959) my $space_after = $3;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2960) my $email = $4;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2961) my $ucfirst_sign_off = ucfirst(lc($sign_off));
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2962)
ce0338df3c9a4 (Joe Perches 2012-07-30 14:41:18 -0700 2963) if ($sign_off !~ /$signature_tags/) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2964) my $suggested_signature = find_standard_signature($sign_off);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2965) if ($suggested_signature eq "") {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2966) WARN("BAD_SIGN_OFF",
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2967) "Non-standard signature: $sign_off\n" . $herecurr);
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2968) } else {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2969) if (WARN("BAD_SIGN_OFF",
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2970) "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) &&
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2971) $fix) {
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2972) $fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/;
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2973) }
831242ab8dffa (Aditya Srivastava 2020-12-15 20:45:12 -0800 2974) }
ce0338df3c9a4 (Joe Perches 2012-07-30 14:41:18 -0700 2975) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2976) if (defined $space_before && $space_before ne "") {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2977) if (WARN("BAD_SIGN_OFF",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2978) "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2979) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 2980) $fixed[$fixlinenr] =
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2981) "$ucfirst_sign_off $email";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2982) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2983) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2984) if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2985) if (WARN("BAD_SIGN_OFF",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2986) "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2987) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 2988) $fixed[$fixlinenr] =
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2989) "$ucfirst_sign_off $email";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2990) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2991)
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2992) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 2993) if (!defined $space_after || $space_after ne " ") {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2994) if (WARN("BAD_SIGN_OFF",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2995) "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2996) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 2997) $fixed[$fixlinenr] =
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2998) "$ucfirst_sign_off $email";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 2999) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3000) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3001)
dfa05c28ca7ff (Joe Perches 2020-04-06 20:10:48 -0700 3002) my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 3003) my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment));
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3004) if ($suggested_email eq "") {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 3005) ERROR("BAD_SIGN_OFF",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 3006) "Unrecognized email address: '$email'\n" . $herecurr);
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3007) } else {
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3008) my $dequoted = $suggested_email;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3009) $dequoted =~ s/^"//;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3010) $dequoted =~ s/" </ </;
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3011) # Don't force email to have quotes
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3012) # Allow just an angle bracketed address
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3013) if (!same_email_addresses($email, $suggested_email)) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3014) if (WARN("BAD_SIGN_OFF",
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3015) "email address '$email' might be better as '$suggested_email'\n" . $herecurr) &&
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3016) $fix) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3017) $fixed[$fixlinenr] =~ s/\Q$email\E/$suggested_email/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3018) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3019) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3020)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3021) # Address part shouldn't have comments
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3022) my $stripped_address = $email_address;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3023) $stripped_address =~ s/\([^\(\)]*\)//g;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3024) if ($email_address ne $stripped_address) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3025) if (WARN("BAD_SIGN_OFF",
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3026) "address part of email should not have comments: '$email_address'\n" . $herecurr) &&
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3027) $fix) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3028) $fixed[$fixlinenr] =~ s/\Q$email_address\E/$stripped_address/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3029) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3030) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3031)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3032) # Only one name comment should be allowed
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3033) my $comment_count = () = $name_comment =~ /\([^\)]+\)/g;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3034) if ($comment_count > 1) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 3035) WARN("BAD_SIGN_OFF",
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3036) "Use a single name comment in email: '$email'\n" . $herecurr);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3037) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3038)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3039)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3040) # stable@vger.kernel.org or stable@kernel.org shouldn't
e73d27159400f (Dwaipayan Ray 2020-12-15 20:44:56 -0800 3041) # have an email name. In addition comments should strictly
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3042) # begin with a #
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3043) if ($email =~ /^.*stable\@(?:vger\.)?kernel\.org/i) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3044) if (($comment ne "" && $comment !~ /^#.+/) ||
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3045) ($email_name ne "")) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3046) my $cur_name = $email_name;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3047) my $new_comment = $comment;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3048) $cur_name =~ s/[a-zA-Z\s\-\"]+//g;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3049)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3050) # Remove brackets enclosing comment text
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3051) # and # from start of comments to get comment text
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3052) $new_comment =~ s/^\((.*)\)$/$1/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3053) $new_comment =~ s/^\[(.*)\]$/$1/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3054) $new_comment =~ s/^[\s\#]+|\s+$//g;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3055)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3056) $new_comment = trim("$new_comment $cur_name") if ($cur_name ne $new_comment);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3057) $new_comment = " # $new_comment" if ($new_comment ne "");
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3058) my $new_email = "$email_address$new_comment";
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3059)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3060) if (WARN("BAD_STABLE_ADDRESS_STYLE",
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3061) "Invalid email format for stable: '$email', prefer '$new_email'\n" . $herecurr) &&
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3062) $fix) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3063) $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3064) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3065) }
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3066) } elsif ($comment ne "" && $comment !~ /^(?:#.+|\(.+\))$/) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3067) my $new_comment = $comment;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3068)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3069) # Extract comment text from within brackets or
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3070) # c89 style /*...*/ comments
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3071) $new_comment =~ s/^\[(.*)\]$/$1/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3072) $new_comment =~ s/^\/\*(.*)\*\/$/$1/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3073)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3074) $new_comment = trim($new_comment);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3075) $new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3076) $new_comment = "($new_comment)" if ($new_comment ne "");
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3077) my $new_email = format_email($email_name, $name_comment, $email_address, $new_comment);
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3078)
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3079) if (WARN("BAD_SIGN_OFF",
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3080) "Unexpected content after email: '$email', should be: '$new_email'\n" . $herecurr) &&
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3081) $fix) {
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3082) $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
fccaebf00e603 (Dwaipayan Ray 2020-12-15 20:44:53 -0800 3083) }
2011247550c1b (Joe Perches 2011-07-25 17:13:23 -0700 3084) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3085) }
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3086)
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3087) # Check for duplicate signatures
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3088) my $sig_nospace = $line;
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3089) $sig_nospace =~ s/\s//g;
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3090) $sig_nospace = lc($sig_nospace);
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3091) if (defined $signatures{$sig_nospace}) {
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3092) WARN("BAD_SIGN_OFF",
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3093) "Duplicate signature\n" . $herecurr);
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3094) } else {
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3095) $signatures{$sig_nospace} = 1;
7e51f1979237e (Joe Perches 2013-09-11 14:23:57 -0700 3096) }
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3097)
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3098) # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3099) if ($sign_off =~ /^co-developed-by:$/i) {
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3100) if ($email eq $author) {
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3101) WARN("BAD_SIGN_OFF",
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3102) "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline);
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3103) }
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3104) if (!defined $lines[$linenr]) {
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3105) WARN("BAD_SIGN_OFF",
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3106) "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3107) } elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3108) WARN("BAD_SIGN_OFF",
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3109) "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3110) } elsif ($1 ne $email) {
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3111) WARN("BAD_SIGN_OFF",
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3112) "Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3113) }
6c5d24eef7be7 (Sean Christopherson 2019-03-22 14:11:37 -0700 3114) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3115) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3116)
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3117) # Check email subject for common tools that don't need to be mentioned
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3118) if ($in_header_lines &&
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3119) $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3120) WARN("EMAIL_SUBJECT",
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3121) "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3122) }
a2fe16b9d878a (Joe Perches 2015-02-13 14:39:02 -0800 3123)
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 3124) # Check for Gerrit Change-Ids not in any patch context
44d303eb05ef1 (Joe Perches 2020-04-06 20:11:10 -0700 3125) if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
7580c5b9b464f (Aditya Srivastava 2020-12-15 20:44:47 -0800 3126) if (ERROR("GERRIT_CHANGE_ID",
7580c5b9b464f (Aditya Srivastava 2020-12-15 20:44:47 -0800 3127) "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
7580c5b9b464f (Aditya Srivastava 2020-12-15 20:44:47 -0800 3128) $fix) {
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3129) fix_delete_line($fixlinenr, $rawline);
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3130) }
7ebd05ef1646e (Christopher Covington 2014-04-03 14:49:31 -0700 3131) }
7ebd05ef1646e (Christopher Covington 2014-04-03 14:49:31 -0700 3132)
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3133) # Check if the commit log is in a possible stack dump
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3134) if ($in_commit_log && !$commit_log_possible_stack_dump &&
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3135) ($line =~ /^\s*(?:WARNING:|BUG:)/ ||
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3136) $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3137) # timestamp
634cffcc9478e (Joe Perches 2019-09-25 16:46:32 -0700 3138) $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
634cffcc9478e (Joe Perches 2019-09-25 16:46:32 -0700 3139) $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
634cffcc9478e (Joe Perches 2019-09-25 16:46:32 -0700 3140) $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
634cffcc9478e (Joe Perches 2019-09-25 16:46:32 -0700 3141) # stack dump address styles
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3142) $commit_log_possible_stack_dump = 1;
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3143) }
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3144)
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3145) # Check for line lengths > 75 in commit log, warn once
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3146) if ($in_commit_log && !$commit_log_long_line &&
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3147) length($line) > 75 &&
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3148) !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3149) # file delta changes
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3150) $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3151) # filename then :
27b379af61025 (Aditya Srivastava 2020-12-15 20:44:59 -0800 3152) $line =~ /^\s*(?:Fixes:|Link:|$signature_tags)/i ||
27b379af61025 (Aditya Srivastava 2020-12-15 20:44:59 -0800 3153) # A Fixes: or Link: line or signature tag line
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3154) $commit_log_possible_stack_dump)) {
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3155) WARN("COMMIT_LOG_LONG_LINE",
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3156) "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3157) $commit_log_long_line = 1;
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3158) }
2a076f40d8c9b (Joe Perches 2015-04-16 12:44:28 -0700 3159)
bf4daf12a9fbc (Joe Perches 2015-09-09 15:37:50 -0700 3160) # Reset possible stack dump if a blank line is found
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3161) if ($in_commit_log && $commit_log_possible_stack_dump &&
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3162) $line =~ /^\s*$/) {
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3163) $commit_log_possible_stack_dump = 0;
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3164) }
bf4daf12a9fbc (Joe Perches 2015-09-09 15:37:50 -0700 3165)
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3166) # Check for lines starting with a #
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3167) if ($in_commit_log && $line =~ /^#/) {
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3168) if (WARN("COMMIT_COMMENT_SYMBOL",
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3169) "Commit log lines starting with '#' are dropped by git as comments\n" . $herecurr) &&
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3170) $fix) {
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3171) $fixed[$fixlinenr] =~ s/^/ /;
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3172) }
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3173) }
084a617acfa08 (Dwaipayan Ray 2020-12-15 20:45:18 -0800 3174)
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3175) # Check for git id commit length and improperly formed commit descriptions
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3176) # A correctly formed commit description is:
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3177) # commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3178) # with the commit subject '("' prefix and '")' suffix
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3179) # This is a fairly compilicated block as it tests for what appears to be
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3180) # bare SHA-1 hash with minimum length of 5. It also avoids several types of
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3181) # possible SHA-1 matches.
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3182) # A commit match can span multiple lines so this block attempts to find a
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3183) # complete typical commit on a maximum of 3 lines
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3184) if ($perl_version_ok &&
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3185) $in_commit_log && !$commit_log_possible_stack_dump &&
a8972573eb5c7 (John Hubbard 2020-04-06 20:10:55 -0700 3186) $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
e882dbfc248cf (Wei Wang 2017-05-08 15:55:54 -0700 3187) $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3188) (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3189) ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
aab38f516aa99 (Joe Perches 2016-08-02 14:04:36 -0700 3190) ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3191) $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
369c8dd390baf (Joe Perches 2015-11-06 16:31:34 -0800 3192) $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3193) my $init_char = "c";
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3194) my $orig_commit = "";
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3195) my $short = 1;
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3196) my $long = 0;
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3197) my $case = 1;
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3198) my $space = 1;
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3199) my $id = '0123456789ab';
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3200) my $orig_desc = "commit description";
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3201) my $description = "";
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3202) my $herectx = $herecurr;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3203) my $has_parens = 0;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3204) my $has_quotes = 0;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3205)
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3206) my $input = $line;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3207) if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3208) for (my $n = 0; $n < 2; $n++) {
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3209) if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3210) $orig_desc = $1;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3211) $has_parens = 1;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3212) # Always strip leading/trailing parens then double quotes if existing
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3213) $orig_desc = substr($orig_desc, 1, -1);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3214) if ($orig_desc =~ /^".*"$/) {
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3215) $orig_desc = substr($orig_desc, 1, -1);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3216) $has_quotes = 1;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3217) }
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3218) last;
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3219) }
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3220) last if ($#lines < $linenr + $n);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3221) $input .= " " . trim($rawlines[$linenr + $n]);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3222) $herectx .= "$rawlines[$linenr + $n]\n";
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3223) }
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3224) $herectx = $herecurr if (!$has_parens);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3225) }
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3226)
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3227) if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3228) $init_char = $1;
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3229) $orig_commit = lc($2);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3230) $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3231) $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3232) $space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3233) $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3234) } elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3235) $orig_commit = lc($1);
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3236) }
fe043ea120569 (Joe Perches 2015-09-09 15:37:25 -0700 3237)
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3238) ($id, $description) = git_commit_info($orig_commit,
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3239) $id, $orig_desc);
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3240)
948b133a1b624 (Heinrich Schuchardt 2017-07-10 15:52:16 -0700 3241) if (defined($id) &&
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3242) ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3243) $last_git_commit_id_linenr != $linenr - 1) {
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3244) ERROR("GIT_COMMIT_ID",
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3245) "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
0d7835fcaa67b (Joe Perches 2015-02-13 14:38:35 -0800 3246) }
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3247) #don't report the next line if this line ends in commit and the sha1 hash is the next line
4ce9f97045789 (Joe Perches 2021-09-07 19:59:57 -0700 3248) $last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 3249) }
d311cd44545f2 (Joe Perches 2014-08-06 16:10:57 -0700 3250)
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3251) # Check for added, moved or deleted files
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3252) if (!$reported_maintainer_file && !$in_commit_log &&
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3253) ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3254) $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3255) ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3256) (defined($1) || defined($2))))) {
a82603a8325f8 (Andrew Jeffery 2016-12-12 16:46:37 -0800 3257) $is_patch = 1;
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3258) $reported_maintainer_file = 1;
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3259) WARN("FILE_PATH_CHANGES",
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3260) "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3261) }
13f1937ef3395 (Joe Perches 2014-08-06 16:10:59 -0700 3262)
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3263) # Check for adding new DT bindings not in schema format
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3264) if (!$in_commit_log &&
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3265) ($line =~ /^new file mode\s*\d+\s*$/) &&
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3266) ($realfile =~ m@^Documentation/devicetree/bindings/.*\.txt$@)) {
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3267) WARN("DT_SCHEMA_BINDING_PATCH",
56ddc4cd4c8f9 (Mauro Carvalho Chehab 2021-04-01 14:17:49 +0200 3268) "DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.rst\n");
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3269) }
e400edb141d74 (Rob Herring 2019-09-12 15:18:20 +0100 3270)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 3271) # Check for wrappage within a valid hunk of the file
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 3272) if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 3273) ERROR("CORRUPTED_PATCH",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 3274) "patch seems to be corrupt (line wrapped?)\n" .
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 3275) $herecurr) if (!$emitted_corrupt++);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 3276) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 3277)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 3278) # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 3279) if (($realfile =~ /^$/ || $line =~ /^\+/) &&
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3280) $rawline !~ m/^$UTF8*$/) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3281) my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3282)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3283) my $blank = copy_spacing($rawline);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3284) my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3285) my $hereptr = "$hereline$ptr\n";
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 3286)
34d99219726ff (Joe Perches 2011-07-25 17:13:26 -0700 3287) CHK("INVALID_UTF8",
34d99219726ff (Joe Perches 2011-07-25 17:13:26 -0700 3288) "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 3289) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 3290)
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3291) # Check if it's the start of a commit log
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3292) # (not a header line and we haven't seen the patch filename)
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3293) if ($in_header_lines && $realfile =~ /^$/ &&
eb3a58de3ec49 (Joe Perches 2017-05-08 15:55:42 -0700 3294) !($rawline =~ /^\s+(?:\S|$)/ ||
eb3a58de3ec49 (Joe Perches 2017-05-08 15:55:42 -0700 3295) $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3296) $in_header_lines = 0;
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3297) $in_commit_log = 1;
ed43c4e58a6d3 (Allen Hubbe 2016-08-02 14:04:45 -0700 3298) $has_commit_log = 1;
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3299) }
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3300)
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3301) # Check if there is UTF-8 in a commit log when a mail header has explicitly
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3302) # declined it, i.e defined some charset where it is missing.
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3303) if ($in_header_lines &&
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3304) $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3305) $1 !~ /utf-8/i) {
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3306) $non_utf8_charset = 1;
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3307) }
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3308)
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3309) if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3310) $rawline =~ /$NON_ASCII_UTF8/) {
fa64205df9dfd (Pasi Savanainen 2012-10-04 17:13:29 -0700 3311) WARN("UTF8_BEFORE_PATCH",
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3312) "8-bit UTF-8 used in possible commit log\n" . $herecurr);
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3313) }
15662b3e86449 (Joe Perches 2011-10-31 17:13:12 -0700 3314)
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3315) # Check for absolute kernel paths in commit message
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3316) if ($tree && $in_commit_log) {
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3317) while ($line =~ m{(?:^|\s)(/\S*)}g) {
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3318) my $file = $1;
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3319)
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3320) if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3321) check_absolute_file($1, $herecurr)) {
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3322) #
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3323) } else {
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3324) check_absolute_file($file, $herecurr);
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3325) }
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3326) }
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3327) }
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3328)
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3329) # Check for various typo / spelling mistakes
66d7a382cb5d2 (Joe Perches 2015-04-16 12:44:08 -0700 3330) if (defined($misspellings) &&
66d7a382cb5d2 (Joe Perches 2015-04-16 12:44:08 -0700 3331) ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
7da07c31b1df1 (Dwaipayan Ray 2020-12-15 20:45:21 -0800 3332) while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3333) my $typo = $1;
7da07c31b1df1 (Dwaipayan Ray 2020-12-15 20:45:21 -0800 3334) my $blank = copy_spacing($rawline);
7da07c31b1df1 (Dwaipayan Ray 2020-12-15 20:45:21 -0800 3335) my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
7da07c31b1df1 (Dwaipayan Ray 2020-12-15 20:45:21 -0800 3336) my $hereptr = "$hereline$ptr\n";
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3337) my $typo_fix = $spelling_fix{lc($typo)};
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3338) $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3339) $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3340) my $msg_level = \&WARN;
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3341) $msg_level = \&CHK if ($file);
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3342) if (&{$msg_level}("TYPO_SPELLING",
7da07c31b1df1 (Dwaipayan Ray 2020-12-15 20:45:21 -0800 3343) "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) &&
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3344) $fix) {
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3345) $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3346) }
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3347) }
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3348) }
66b47b4a9dad0 (Kees Cook 2014-10-13 15:51:57 -0700 3349)
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3350) # check for invalid commit id
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3351) if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3352) my $id;
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3353) my $description;
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3354) ($id, $description) = git_commit_info($2, undef, undef);
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3355) if (!defined($id)) {
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3356) WARN("UNKNOWN_COMMIT_ID",
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3357) "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr);
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3358) }
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3359) }
a8dd86bf74625 (Matteo Croce 2019-09-25 16:46:38 -0700 3360)
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3361) # check for repeated words separated by a single space
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 3362) # avoid false positive from list command eg, '-rw-r--r-- 1 root root'
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 3363) if (($rawline =~ /^\+/ || $in_commit_log) &&
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 3364) $rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) {
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3365) pos($rawline) = 1 if (!$in_commit_log);
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3366) while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3367)
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3368) my $first = $1;
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3369) my $second = $2;
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3370) my $start_pos = $-[1];
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3371) my $end_pos = $+[2];
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3372) if ($first =~ /(?:struct|union|enum)/) {
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3373) pos($rawline) += length($first) + length($second) + 1;
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3374) next;
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3375) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3376)
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3377) next if (lc($first) ne lc($second));
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3378) next if ($first eq 'long');
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3379)
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3380) # check for character before and after the word matches
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3381) my $start_char = '';
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3382) my $end_char = '';
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3383) $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1));
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3384) $end_char = substr($rawline, $end_pos, 1) if ($end_pos < length($rawline));
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3385)
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3386) next if ($start_char =~ /^\S$/);
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3387) next if (index(" \t.,;?!", $end_char) == -1);
1db81a682a2f2 (Dwaipayan Ray 2020-12-15 20:44:20 -0800 3388)
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3389) # avoid repeating hex occurrences like 'ff ff fe 09 ...'
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3390) if ($first =~ /\b[0-9a-f]{2,}\b/i) {
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3391) next if (!exists($allow_repeated_words{lc($first)}));
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 3392) }
8d0325cc74a31 (Aditya Srivastava 2020-12-15 20:44:24 -0800 3393)
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3394) if (WARN("REPEATED_WORD",
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3395) "Possible repeated word: '$first'\n" . $herecurr) &&
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3396) $fix) {
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3397) $fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3398) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3399) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3400)
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3401) # if it's a repeated word on consecutive lines in a comment block
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3402) if ($prevline =~ /$;+\s*$/ &&
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3403) $prevrawline =~ /($word_pattern)\s*$/) {
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3404) my $last_word = $1;
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3405) if ($rawline =~ /^\+\s*\*\s*$last_word /) {
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3406) if (WARN("REPEATED_WORD",
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3407) "Possible repeated word: '$last_word'\n" . $hereprev) &&
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3408) $fix) {
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3409) $fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3410) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3411) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3412) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3413) }
310cd06ba2496 (Joe Perches 2020-10-15 20:11:52 -0700 3414)
306708547b566 (Andy Whitcroft 2008-10-15 22:02:28 -0700 3415) # ignore non-hunk lines and lines being removed
306708547b566 (Andy Whitcroft 2008-10-15 22:02:28 -0700 3416) next if (!$hunk_line || $line =~ /^-/);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3417)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3418) #trailing whitespace
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 3419) if ($line =~ /^\+.*\015/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 3420) my $herevet = "$here\n" . cat_vet($rawline) . "\n";
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 3421) if (ERROR("DOS_LINE_ENDINGS",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 3422) "DOS line endings\n" . $herevet) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 3423) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3424) $fixed[$fixlinenr] =~ s/[\s\015]+$//;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 3425) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 3426) } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 3427) my $herevet = "$here\n" . cat_vet($rawline) . "\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3428) if (ERROR("TRAILING_WHITESPACE",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3429) "trailing whitespace\n" . $herevet) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3430) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3431) $fixed[$fixlinenr] =~ s/\s+$//;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3432) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3433)
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 3434) $rpt_cleaners = 1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3435) }
5368df20fb364 (Andy Whitcroft 2008-10-15 22:02:27 -0700 3436)
4783f894d0f3b (Josh Triplett 2013-11-12 15:10:12 -0800 3437) # Check for FSF mailing addresses.
109d8cb2002dc (Alexander Duyck 2014-01-23 15:54:50 -0800 3438) if ($rawline =~ /\bwrite to the Free/i ||
1bde561e471c9 (Matthew Wilcox 2017-02-24 15:01:38 -0800 3439) $rawline =~ /\b675\s+Mass\s+Ave/i ||
3e2232f2d03ff (Joe Perches 2014-01-23 15:54:48 -0800 3440) $rawline =~ /\b59\s+Temple\s+Pl/i ||
3e2232f2d03ff (Joe Perches 2014-01-23 15:54:48 -0800 3441) $rawline =~ /\b51\s+Franklin\s+St/i) {
4783f894d0f3b (Josh Triplett 2013-11-12 15:10:12 -0800 3442) my $herevet = "$here\n" . cat_vet($rawline) . "\n";
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3443) my $msg_level = \&ERROR;
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3444) $msg_level = \&CHK if ($file);
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3445) &{$msg_level}("FSF_MAILING_ADDRESS",
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 3446) "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
4783f894d0f3b (Josh Triplett 2013-11-12 15:10:12 -0800 3447) }
4783f894d0f3b (Josh Triplett 2013-11-12 15:10:12 -0800 3448)
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3449) # check for Kconfig help text having a real description
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3450) # Only applies when adding the entry originally, after that we do not have
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3451) # sufficient context to determine whether it is indeed long enough.
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3452) if ($realfile =~ /Kconfig/ &&
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3453) # 'choice' is usually the last thing on the line (though
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3454) # Kconfig supports named choices), so use a word boundary
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3455) # (\b) rather than a whitespace character (\s)
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3456) $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3457) my $length = 0;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3458) my $cnt = $realcnt;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3459) my $ln = $linenr + 1;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3460) my $f;
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3461) my $is_start = 0;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3462) my $is_end = 0;
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3463) for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3464) $f = $lines[$ln - 1];
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3465) $cnt-- if ($lines[$ln - 1] !~ /^-/);
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3466) $is_end = $lines[$ln - 1] =~ /^\+/;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3467)
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3468) next if ($f =~ /^-/);
8d73e0e7dc18a (Joe Perches 2014-08-06 16:10:46 -0700 3469) last if (!$file && $f =~ /^\@\@/);
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3470)
86adf1a07e896 (Ulf Magnusson 2018-02-16 21:22:53 +0100 3471) if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3472) $is_start = 1;
22a4ac026c15e (Masahiro Yamada 2020-06-17 12:02:20 +0900 3473) } elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3474) $length = -1;
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3475) }
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3476)
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3477) $f =~ s/^.//;
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3478) $f =~ s/#.*//;
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3479) $f =~ s/^\s+//;
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3480) next if ($f =~ /^$/);
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3481)
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3482) # This only checks context lines in the patch
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3483) # and so hopefully shouldn't trigger false
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3484) # positives, even though some of these are
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3485) # common words in help texts
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3486) if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice|
678ae162dd2fd (Ulf Magnusson 2018-02-16 21:22:54 +0100 3487) if|endif|menu|endmenu|source)\b/x) {
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3488) $is_end = 1;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3489) last;
9fe287d79b0af (Andy Whitcroft 2010-10-26 14:23:15 -0700 3490) }
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3491) $length++;
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3492) }
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 3493) if ($is_start && $is_end && $length < $min_conf_desc_length) {
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 3494) WARN("CONFIG_DESCRIPTION",
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 3495) "please write a paragraph that describes the config symbol fully\n" . $herecurr);
56193274ef542 (Vadim Bendebury 2014-10-13 15:51:48 -0700 3496) }
a13858033a3a9 (Andy Whitcroft 2012-01-10 15:10:03 -0800 3497) #print "is_start<$is_start> is_end<$is_end> length<$length>\n";
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3498) }
3354957a4f8b9 (Andi Kleen 2010-05-24 14:33:29 -0700 3499)
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3500) # check MAINTAINERS entries
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3501) if ($realfile =~ /^MAINTAINERS$/) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3502) # check MAINTAINERS entries for the right form
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3503) if ($rawline =~ /^\+[A-Z]:/ &&
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3504) $rawline !~ /^\+[A-Z]:\t\S/) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3505) if (WARN("MAINTAINERS_STYLE",
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3506) "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) &&
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3507) $fix) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3508) $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3509) }
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3510) }
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3511) # check MAINTAINERS entries for the right ordering too
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3512) my $preferred_order = 'MRLSWQBCPTFXNK';
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3513) if ($rawline =~ /^\+[A-Z]:/ &&
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3514) $prevrawline =~ /^[\+ ][A-Z]:/) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3515) $rawline =~ /^\+([A-Z]):\s*(.*)/;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3516) my $cur = $1;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3517) my $curval = $2;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3518) $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3519) my $prev = $1;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3520) my $prevval = $2;
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3521) my $curindex = index($preferred_order, $cur);
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3522) my $previndex = index($preferred_order, $prev);
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3523) if ($curindex < 0) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3524) WARN("MAINTAINERS_STYLE",
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3525) "Unknown MAINTAINERS entry type: '$cur'\n" . $herecurr);
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3526) } else {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3527) if ($previndex >= 0 && $curindex < $previndex) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3528) WARN("MAINTAINERS_STYLE",
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3529) "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3530) } elsif ((($prev eq 'F' && $cur eq 'F') ||
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3531) ($prev eq 'X' && $cur eq 'X')) &&
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3532) ($prevval cmp $curval) > 0) {
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3533) WARN("MAINTAINERS_STYLE",
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3534) "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3535) }
7ccf41a89cb0c (Joe Perches 2020-06-04 16:50:33 -0700 3536) }
628f91a28649d (Joe Perches 2017-07-10 15:52:07 -0700 3537) }
628f91a28649d (Joe Perches 2017-07-10 15:52:07 -0700 3538) }
628f91a28649d (Joe Perches 2017-07-10 15:52:07 -0700 3539)
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3540) if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3541) ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3542) my $flag = $1;
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3543) my $replacement = {
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3544) 'EXTRA_AFLAGS' => 'asflags-y',
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3545) 'EXTRA_CFLAGS' => 'ccflags-y',
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3546) 'EXTRA_CPPFLAGS' => 'cppflags-y',
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3547) 'EXTRA_LDFLAGS' => 'ldflags-y',
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3548) };
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3549)
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3550) WARN("DEPRECATED_VARIABLE",
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3551) "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3552) }
c68e58783f20d (Arnaud Lacombe 2011-08-15 01:07:14 -0400 3553)
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3554) # check for DT compatible documentation
7dd05b38e5b72 (Florian Vaussard 2014-04-03 14:49:26 -0700 3555) if (defined $root &&
7dd05b38e5b72 (Florian Vaussard 2014-04-03 14:49:26 -0700 3556) (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
7dd05b38e5b72 (Florian Vaussard 2014-04-03 14:49:26 -0700 3557) ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
7dd05b38e5b72 (Florian Vaussard 2014-04-03 14:49:26 -0700 3558)
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3559) my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3560)
cc93319b5f247 (Florian Vaussard 2014-04-03 14:49:27 -0700 3561) my $dt_path = $root . "/Documentation/devicetree/bindings/";
852d095d16a62 (Rob Herring 2019-05-22 09:55:34 -0500 3562) my $vp_file = $dt_path . "vendor-prefixes.yaml";
cc93319b5f247 (Florian Vaussard 2014-04-03 14:49:27 -0700 3563)
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3564) foreach my $compat (@compats) {
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3565) my $compat2 = $compat;
185d566bcd0a8 (Rob Herring 2014-06-04 16:12:03 -0700 3566) $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
185d566bcd0a8 (Rob Herring 2014-06-04 16:12:03 -0700 3567) my $compat3 = $compat;
185d566bcd0a8 (Rob Herring 2014-06-04 16:12:03 -0700 3568) $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
185d566bcd0a8 (Rob Herring 2014-06-04 16:12:03 -0700 3569) `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3570) if ( $? >> 8 ) {
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3571) WARN("UNDOCUMENTED_DT_STRING",
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3572) "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3573) }
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3574)
4fbf32a69346a (Florian Vaussard 2014-04-03 14:49:25 -0700 3575) next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
4fbf32a69346a (Florian Vaussard 2014-04-03 14:49:25 -0700 3576) my $vendor = $1;
852d095d16a62 (Rob Herring 2019-05-22 09:55:34 -0500 3577) `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3578) if ( $? >> 8 ) {
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3579) WARN("UNDOCUMENTED_DT_STRING",
cc93319b5f247 (Florian Vaussard 2014-04-03 14:49:27 -0700 3580) "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3581) }
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3582) }
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3583) }
bff5da4335256 (Rob Herring 2014-01-23 15:54:51 -0800 3584)
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3585) # check for using SPDX license tag at beginning of files
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3586) if ($realline == $checklicenseline) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3587) if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3588) $checklicenseline = 2;
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3589) } elsif ($rawline =~ /^\+/) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3590) my $comment = "";
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3591) if ($realfile =~ /\.(h|s|S)$/) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3592) $comment = '/*';
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3593) } elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3594) $comment = '//';
c8df0ab61454a (Lubomir Rintel 2020-04-06 20:10:51 -0700 3595) } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3596) $comment = '#';
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3597) } elsif ($realfile =~ /\.rst$/) {
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3598) $comment = '..';
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3599) }
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3600)
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3601) # check SPDX comment style for .[chsS] files
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3602) if ($realfile =~ /\.[chsS]$/ &&
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3603) $rawline =~ /SPDX-License-Identifier:/ &&
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3604) $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3605) WARN("SPDX_LICENSE_TAG",
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3606) "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3607) }
fdf13693d3706 (Joe Perches 2019-03-07 16:28:32 -0800 3608)
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3609) if ($comment !~ /^$/ &&
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3610) $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3611) WARN("SPDX_LICENSE_TAG",
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3612) "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
3b6e8ac9e740b (Joe Perches 2018-08-21 21:57:47 -0700 3613) } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3614) my $spdx_license = $1;
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3615) if (!is_SPDX_License_valid($spdx_license)) {
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3616) WARN("SPDX_LICENSE_TAG",
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3617) "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
ffbce8974d90e (Joe Perches 2019-09-25 16:46:35 -0700 3618) }
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3619) if ($realfile =~ m@^Documentation/devicetree/bindings/@ &&
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3620) not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) {
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3621) my $msg_level = \&WARN;
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3622) $msg_level = \&CHK if ($file);
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3623) if (&{$msg_level}("SPDX_LICENSE_TAG",
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3624)
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3625) "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3626) $fix) {
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3627) $fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/;
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3628) }
50c92900214dd (Lubomir Rintel 2020-04-06 20:11:13 -0700 3629) }
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3630) }
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3631) }
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3632) }
9f3a89926d6df (Rob Herring 2018-04-10 16:33:13 -0700 3633)
a0154cdbd3dcf (Joe Perches 2020-10-15 20:12:19 -0700 3634) # check for embedded filenames
a0154cdbd3dcf (Joe Perches 2020-10-15 20:12:19 -0700 3635) if ($rawline =~ /^\+.*\Q$realfile\E/) {
a0154cdbd3dcf (Joe Perches 2020-10-15 20:12:19 -0700 3636) WARN("EMBEDDED_FILENAME",
a0154cdbd3dcf (Joe Perches 2020-10-15 20:12:19 -0700 3637) "It's generally not useful to have the filename in the file\n" . $herecurr);
a0154cdbd3dcf (Joe Perches 2020-10-15 20:12:19 -0700 3638) }
a0154cdbd3dcf (Joe Perches 2020-10-15 20:12:19 -0700 3639)
5368df20fb364 (Andy Whitcroft 2008-10-15 22:02:27 -0700 3640) # check we are in a valid source file if not then ignore this hunk
d6430f71805aa (Joe Perches 2016-12-12 16:46:28 -0800 3641) next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
5368df20fb364 (Andy Whitcroft 2008-10-15 22:02:27 -0700 3642)
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3643) # check for using SPDX-License-Identifier on the wrong line number
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3644) if ($realline != $checklicenseline &&
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3645) $rawline =~ /\bSPDX-License-Identifier:/ &&
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3646) substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3647) WARN("SPDX_LICENSE_TAG",
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3648) "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3649) }
a8da38a9cf0e9 (Joe Perches 2019-03-07 16:28:42 -0800 3650)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3651) # line length limit (with some exclusions)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3652) #
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3653) # There are a few types of lines that may extend beyond $max_line_length:
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3654) # logging functions like pr_info that end in a string
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3655) # lines with a single string
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3656) # #defines that are a single string
2e4bbbc550be3 (Andreas Brauchli 2018-02-06 15:38:45 -0800 3657) # lines with an RFC3986 like URL
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3658) #
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3659) # There are 3 different line length message types:
ab1ecabf4fdbd (Jean Delvare 2017-09-08 16:16:04 -0700 3660) # LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3661) # LONG_LINE_STRING a string starts before but extends beyond $max_line_length
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3662) # LONG_LINE all other lines longer than $max_line_length
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3663) #
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3664) # if LONG_LINE is ignored, the other 2 types are also ignored
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3665) #
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3666)
b4749e96a4a87 (Joe Perches 2015-07-17 16:24:01 -0700 3667) if ($line =~ /^\+/ && $length > $max_line_length) {
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3668) my $msg_type = "LONG_LINE";
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3669)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3670) # Check the allowed long line types first
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3671)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3672) # logging functions that end in a string that starts
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3673) # before $max_line_length
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3674) if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3675) length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3676) $msg_type = "";
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3677)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3678) # lines with only strings (w/ possible termination)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3679) # #defines with only strings
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3680) } elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3681) $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3682) $msg_type = "";
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3683)
cc147506bef96 (Joe Perches 2017-11-17 15:28:44 -0800 3684) # More special cases
cc147506bef96 (Joe Perches 2017-11-17 15:28:44 -0800 3685) } elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ ||
cc147506bef96 (Joe Perches 2017-11-17 15:28:44 -0800 3686) $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) {
d560a5f8a46e9 (Joe Perches 2016-08-02 14:04:31 -0700 3687) $msg_type = "";
d560a5f8a46e9 (Joe Perches 2016-08-02 14:04:31 -0700 3688)
2e4bbbc550be3 (Andreas Brauchli 2018-02-06 15:38:45 -0800 3689) # URL ($rawline is used in case the URL is in a comment)
2e4bbbc550be3 (Andreas Brauchli 2018-02-06 15:38:45 -0800 3690) } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
2e4bbbc550be3 (Andreas Brauchli 2018-02-06 15:38:45 -0800 3691) $msg_type = "";
2e4bbbc550be3 (Andreas Brauchli 2018-02-06 15:38:45 -0800 3692)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3693) # Otherwise set the alternate message types
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3694)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3695) # a comment starts before $max_line_length
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3696) } elsif ($line =~ /($;[\s$;]*)$/ &&
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3697) length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3698) $msg_type = "LONG_LINE_COMMENT"
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3699)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3700) # a quoted string starts before $max_line_length
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3701) } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3702) length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3703) $msg_type = "LONG_LINE_STRING"
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3704) }
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3705)
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3706) if ($msg_type ne "" &&
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3707) (show_type("LONG_LINE") || show_type($msg_type))) {
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 3708) my $msg_level = \&WARN;
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 3709) $msg_level = \&CHK if ($file);
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 3710) &{$msg_level}($msg_type,
bdc48fa11e46f (Joe Perches 2020-05-29 16:12:21 -0700 3711) "line length of $length exceeds $max_line_length columns\n" . $herecurr);
47e0c88b37a5c (Joe Perches 2015-06-25 15:02:57 -0700 3712) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3713) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3714)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 3715) # check for adding lines without a newline.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 3716) if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
47ca69b85821e (Tom Rix 2020-12-15 20:44:40 -0800 3717) if (WARN("MISSING_EOF_NEWLINE",
47ca69b85821e (Tom Rix 2020-12-15 20:44:40 -0800 3718) "adding a line without newline at end of file\n" . $herecurr) &&
47ca69b85821e (Tom Rix 2020-12-15 20:44:40 -0800 3719) $fix) {
47ca69b85821e (Tom Rix 2020-12-15 20:44:40 -0800 3720) fix_delete_line($fixlinenr+1, "No newline at end of file");
47ca69b85821e (Tom Rix 2020-12-15 20:44:40 -0800 3721) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 3722) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 3723)
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3724) # check for .L prefix local symbols in .S files
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3725) if ($realfile =~ /\.S$/ &&
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3726) $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3727) WARN("AVOID_L_PREFIX",
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3728) "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3729) }
de93245c00a44 (Aditya Srivastava 2021-02-25 17:21:57 -0800 3730)
b9ea10d691ecb (Andy Whitcroft 2008-10-15 22:02:24 -0700 3731) # check we are in a valid source file C or perl if not then ignore this hunk
de4c924c26504 (Geert Uytterhoeven 2014-10-13 15:51:46 -0700 3732) next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3733)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3734) # at the beginning of a line any tabs must come first and anything
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 3735) # more than $tabsize must use tabs.
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 3736) if ($rawline =~ /^\+\s* \t\s*\S/ ||
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 3737) $rawline =~ /^\+\s* \s*/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 3738) my $herevet = "$here\n" . cat_vet($rawline) . "\n";
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 3739) $rpt_cleaners = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3740) if (ERROR("CODE_INDENT",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3741) "code indent should use tabs where possible\n" . $herevet) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3742) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3743) $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3744) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3745) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 3746)
08e4436566250 (Alberto Panizzo 2010-03-05 13:43:54 -0800 3747) # check for space before tabs.
08e4436566250 (Alberto Panizzo 2010-03-05 13:43:54 -0800 3748) if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
08e4436566250 (Alberto Panizzo 2010-03-05 13:43:54 -0800 3749) my $herevet = "$here\n" . cat_vet($rawline) . "\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3750) if (WARN("SPACE_BEFORE_TAB",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3751) "please, no space before tabs\n" . $herevet) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3752) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3753) while ($fixed[$fixlinenr] =~
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 3754) s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {}
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3755) while ($fixed[$fixlinenr] =~
c76f4cb3d25e5 (Joe Perches 2014-01-23 15:54:46 -0800 3756) s/(^\+.*) +\t/$1\t/) {}
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3757) }
08e4436566250 (Alberto Panizzo 2010-03-05 13:43:54 -0800 3758) }
6a487211ec720 (Joe Perches 2018-04-10 16:34:04 -0700 3759)
6a487211ec720 (Joe Perches 2018-04-10 16:34:04 -0700 3760) # check for assignments on the start of a line
6a487211ec720 (Joe Perches 2018-04-10 16:34:04 -0700 3761) if ($sline =~ /^\+\s+($Assignment)[^=]/) {
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3762) my $operator = $1;
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3763) if (CHK("ASSIGNMENT_CONTINUATIONS",
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3764) "Assignment operator '$1' should be on the previous line\n" . $hereprev) &&
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3765) $fix && $prevrawline =~ /^\+/) {
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3766) # add assignment operator to the previous line, remove from current line
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3767) $fixed[$fixlinenr - 1] .= " $operator";
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3768) $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
da7355ab4e4a0 (Aditya Srivastava 2020-12-15 20:45:06 -0800 3769) }
6a487211ec720 (Joe Perches 2018-04-10 16:34:04 -0700 3770) }
08e4436566250 (Alberto Panizzo 2010-03-05 13:43:54 -0800 3771)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3772) # check for && or || at the start of a line
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3773) if ($rawline =~ /^\+\s*(&&|\|\|)/) {
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3774) my $operator = $1;
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3775) if (CHK("LOGICAL_CONTINUATIONS",
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3776) "Logical continuations should be on the previous line\n" . $hereprev) &&
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3777) $fix && $prevrawline =~ /^\+/) {
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3778) # insert logical operator at last non-comment, non-whitepsace char on previous line
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3779) $prevline =~ /[\s$;]*$/;
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3780) my $line_end = substr($prevrawline, $-[0]);
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3781) $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/;
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3782) $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
8e08f0765f374 (Aditya Srivastava 2020-12-15 20:45:09 -0800 3783) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3784) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3785)
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3786) # check indentation starts on a tab stop
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 3787) if ($perl_version_ok &&
bd49111f7dd19 (Joe Perches 2018-02-06 15:39:06 -0800 3788) $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) {
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3789) my $indent = length($1);
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 3790) if ($indent % $tabsize) {
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3791) if (WARN("TABSTOP",
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3792) "Statements should start on a tabstop\n" . $herecurr) &&
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3793) $fix) {
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 3794) $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e;
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3795) }
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3796) }
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3797) }
a91e8994f242a (Joe Perches 2016-05-20 17:04:05 -0700 3798)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3799) # check multi-line statement indentation matches previous line
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 3800) if ($perl_version_ok &&
fd71f6326844e (Joe Perches 2017-07-10 15:52:30 -0700 3801) $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3802) $prevline =~ /^\+(\t*)(.*)$/;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3803) my $oldindent = $1;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3804) my $rest = $2;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3805)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3806) my $pos = pos_last_openparen($rest);
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3807) if ($pos >= 0) {
b34a26f3158cc (Joe Perches 2012-07-30 14:41:16 -0700 3808) $line =~ /^(\+| )([ \t]*)/;
b34a26f3158cc (Joe Perches 2012-07-30 14:41:16 -0700 3809) my $newindent = $2;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3810)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3811) my $goodtabindent = $oldindent .
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 3812) "\t" x ($pos / $tabsize) .
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 3813) " " x ($pos % $tabsize);
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3814) my $goodspaceindent = $oldindent . " " x $pos;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3815)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3816) if ($newindent ne $goodtabindent &&
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3817) $newindent ne $goodspaceindent) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3818)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3819) if (CHK("PARENTHESIS_ALIGNMENT",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3820) "Alignment should match open parenthesis\n" . $hereprev) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3821) $fix && $line =~ /^\+/) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3822) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3823) s/^\+[ \t]*/\+$goodtabindent/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3824) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3825) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3826) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3827) }
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 3828)
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3829) # check for space after cast like "(int) foo" or "(struct foo) bar"
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3830) # avoid checking a few false positives:
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3831) # "sizeof(<type>)" or "__alignof__(<type>)"
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3832) # function pointer declarations like "(*foo)(int) = bar;"
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3833) # structure definitions like "(struct foo) { 0 };"
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3834) # multiline macros that define functions
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3835) # known attributes or the __attribute__ keyword
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3836) if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
6ab3a9701e00c (Joe Perches 2015-04-16 12:44:05 -0700 3837) (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3838) if (CHK("SPACING",
f27c95db1176b (Joe Perches 2014-08-06 16:10:52 -0700 3839) "No space is necessary after a cast\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3840) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3841) $fixed[$fixlinenr] =~
f27c95db1176b (Joe Perches 2014-08-06 16:10:52 -0700 3842) s/(\(\s*$Type\s*\))[ \t]+/$1/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3843) }
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 3844) }
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 3845)
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3846) # Block comment styles
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3847) # Networking with an initial /*
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3848) if ($realfile =~ m@^(drivers/net/|net/)@ &&
fdb4bcd610860 (Joe Perches 2013-07-03 15:05:23 -0700 3849) $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
85ad978c626a4 (Joe Perches 2014-04-03 14:49:20 -0700 3850) $rawline =~ /^\+[ \t]*\*/ &&
c70735c23bf6c (Łukasz Stelmach 2020-10-15 20:12:25 -0700 3851) $realline > 3) { # Do not warn about the initial copyright comment block after SPDX-License-Identifier
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3852) WARN("NETWORKING_BLOCK_COMMENT_STYLE",
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3853) "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3854) }
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3855)
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3856) # Block comments use * on subsequent lines
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3857) if ($prevline =~ /$;[ \t]*$/ && #ends in comment
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3858) $prevrawline =~ /^\+.*?\/\*/ && #starting /*
a605e32ebde25 (Joe Perches 2013-07-03 15:05:24 -0700 3859) $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
61135e966367e (Joe Perches 2013-09-11 14:23:59 -0700 3860) $rawline =~ /^\+/ && #line is new
a605e32ebde25 (Joe Perches 2013-07-03 15:05:24 -0700 3861) $rawline !~ /^\+[ \t]*\*/) { #no leading *
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3862) WARN("BLOCK_COMMENT_STYLE",
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3863) "Block comments use * on subsequent lines\n" . $hereprev);
a605e32ebde25 (Joe Perches 2013-07-03 15:05:24 -0700 3864) }
a605e32ebde25 (Joe Perches 2013-07-03 15:05:24 -0700 3865)
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3866) # Block comments use */ on trailing lines
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3867) if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
c24f9f195edf8 (Joe Perches 2012-11-08 15:53:29 -0800 3868) $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
c24f9f195edf8 (Joe Perches 2012-11-08 15:53:29 -0800 3869) $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
c24f9f195edf8 (Joe Perches 2012-11-08 15:53:29 -0800 3870) $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3871) WARN("BLOCK_COMMENT_STYLE",
86406b1cb7ac4 (Joe Perches 2015-09-09 15:37:41 -0700 3872) "Block comments use a trailing */ on a separate line\n" . $herecurr);
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3873) }
0588060074504 (Joe Perches 2012-10-04 17:13:35 -0700 3874)
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3875) # Block comment * alignment
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3876) if ($prevline =~ /$;[ \t]*$/ && #ends in comment
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3877) $line =~ /^\+[ \t]*$;/ && #leading comment
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3878) $rawline =~ /^\+[ \t]*\*/ && #leading *
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3879) (($prevrawline =~ /^\+.*?\/\*/ && #leading /*
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3880) $prevrawline !~ /\*\/[ \t]*$/) || #no trailing */
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3881) $prevrawline =~ /^\+[ \t]*\*/)) { #leading *
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3882) my $oldindent;
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3883) $prevrawline =~ m@^\+([ \t]*/?)\*@;
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3884) if (defined($1)) {
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3885) $oldindent = expand_tabs($1);
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3886) } else {
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3887) $prevrawline =~ m@^\+(.*/?)\*@;
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3888) $oldindent = expand_tabs($1);
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3889) }
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3890) $rawline =~ m@^\+([ \t]*)\*@;
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3891) my $newindent = $1;
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3892) $newindent = expand_tabs($newindent);
af207524a49c3 (Joe Perches 2016-10-11 13:52:05 -0700 3893) if (length($oldindent) ne length($newindent)) {
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3894) WARN("BLOCK_COMMENT_STYLE",
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3895) "Block comments should align the * on each line\n" . $hereprev);
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3896) }
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3897) }
08eb9b8016b18 (Joe Perches 2016-10-11 13:51:50 -0700 3898)
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3899) # check for missing blank lines after struct/union declarations
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3900) # with exceptions for various attributes and macros
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3901) if ($prevline =~ /^[\+ ]};?\s*$/ &&
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3902) $line =~ /^\+/ &&
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3903) !($line =~ /^\+\s*$/ ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3904) $line =~ /^\+\s*EXPORT_SYMBOL/ ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3905) $line =~ /^\+\s*MODULE_/i ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3906) $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3907) $line =~ /^\+[a-z_]*init/ ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3908) $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3909) $line =~ /^\+\s*DECLARE/ ||
0bc989ffc8027 (Masahiro Yamada 2017-11-17 15:28:55 -0800 3910) $line =~ /^\+\s*builtin_[\w_]*driver/ ||
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3911) $line =~ /^\+\s*__setup/)) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3912) if (CHK("LINE_SPACING",
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3913) "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3914) $fix) {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 3915) fix_insert_line($fixlinenr, "\+");
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3916) }
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3917) }
7f61919144ca6 (Joe Perches 2014-08-06 16:10:39 -0700 3918)
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3919) # check for multiple consecutive blank lines
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3920) if ($prevline =~ /^[\+ ]\s*$/ &&
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3921) $line =~ /^\+\s*$/ &&
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3922) $last_blank_line != ($linenr - 1)) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3923) if (CHK("LINE_SPACING",
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3924) "Please don't use multiple blank lines\n" . $hereprev) &&
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3925) $fix) {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 3926) fix_delete_line($fixlinenr, $rawline);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3927) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3928)
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3929) $last_blank_line = $linenr;
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3930) }
365dd4eaafa22 (Joe Perches 2014-08-06 16:10:42 -0700 3931)
3b617e3b80548 (Joe Perches 2014-04-03 14:49:28 -0700 3932) # check for missing blank lines after declarations
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3933) # (declarations must have the same indentation and not be at the start of line)
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3934) if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) {
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3935) # use temporaries
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3936) my $sl = $sline;
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3937) my $pl = $prevline;
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3938) # remove $Attribute/$Sparse uses to simplify comparisons
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3939) $sl =~ s/\b(?:$Attribute|$Sparse)\b//g;
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3940) $pl =~ s/\b(?:$Attribute|$Sparse)\b//g;
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3941) if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
5a4e1fd37d067 (Joe Perches 2014-08-06 16:10:33 -0700 3942) # function pointer declarations
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3943) $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3944) # foo bar; where foo is some local typedef or #define
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3945) $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3946) # known declaration macros
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3947) $pl =~ /^\+\s+$declaration_macros/) &&
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3948) # for "else if" which can look like "$Ident $Ident"
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3949) !($pl =~ /^\+\s+$c90_Keywords\b/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3950) # other possible extensions of declaration lines
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3951) $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3952) # not starting a section or a macro "\" extended line
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3953) $pl =~ /(?:\{\s*|\\)$/) &&
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3954) # looks like a declaration
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3955) !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
5a4e1fd37d067 (Joe Perches 2014-08-06 16:10:33 -0700 3956) # function pointer declarations
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3957) $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3958) # foo bar; where foo is some local typedef or #define
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3959) $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3960) # known declaration macros
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3961) $sl =~ /^\+\s+$declaration_macros/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3962) # start of struct or union or enum
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3963) $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3964) # start or end of block or continuation of declaration
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3965) $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3966) # bitfield continuation
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3967) $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
3f7bac031c6ba (Joe Perches 2014-06-04 16:12:04 -0700 3968) # other possible extensions of declaration lines
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3969) $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3970) if (WARN("LINE_SPACING",
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3971) "Missing a blank line after declarations\n" . $hereprev) &&
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3972) $fix) {
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3973) fix_insert_line($fixlinenr, "\+");
b5e8736a954ae (Joe Perches 2021-02-25 17:21:40 -0800 3974) }
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 3975) }
3b617e3b80548 (Joe Perches 2014-04-03 14:49:28 -0700 3976) }
3b617e3b80548 (Joe Perches 2014-04-03 14:49:28 -0700 3977)
5f7ddae6104d8 (Raffaele Recalcati 2010-08-09 17:20:59 -0700 3978) # check for spaces at the beginning of a line.
6b4c5bebcebb0 (Andy Whitcroft 2010-10-26 14:23:11 -0700 3979) # Exceptions:
6b4c5bebcebb0 (Andy Whitcroft 2010-10-26 14:23:11 -0700 3980) # 1) within comments
6b4c5bebcebb0 (Andy Whitcroft 2010-10-26 14:23:11 -0700 3981) # 2) indented preprocessor commands
6b4c5bebcebb0 (Andy Whitcroft 2010-10-26 14:23:11 -0700 3982) # 3) hanging labels
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3983) if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) {
5f7ddae6104d8 (Raffaele Recalcati 2010-08-09 17:20:59 -0700 3984) my $herevet = "$here\n" . cat_vet($rawline) . "\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3985) if (WARN("LEADING_SPACE",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3986) "please, no spaces at the start of a line\n" . $herevet) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3987) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 3988) $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 3989) }
5f7ddae6104d8 (Raffaele Recalcati 2010-08-09 17:20:59 -0700 3990) }
5f7ddae6104d8 (Raffaele Recalcati 2010-08-09 17:20:59 -0700 3991)
b9ea10d691ecb (Andy Whitcroft 2008-10-15 22:02:24 -0700 3992) # check we are in a valid C source file if not then ignore this hunk
b9ea10d691ecb (Andy Whitcroft 2008-10-15 22:02:24 -0700 3993) next if ($realfile !~ /\.(h|c)$/);
b9ea10d691ecb (Andy Whitcroft 2008-10-15 22:02:24 -0700 3994)
5751a24edfd43 (Joe Perches 2017-11-17 15:28:52 -0800 3995) # check for unusual line ending [ or (
5751a24edfd43 (Joe Perches 2017-11-17 15:28:52 -0800 3996) if ($line =~ /^\+.*([\[\(])\s*$/) {
5751a24edfd43 (Joe Perches 2017-11-17 15:28:52 -0800 3997) CHK("OPEN_ENDED_LINE",
5751a24edfd43 (Joe Perches 2017-11-17 15:28:52 -0800 3998) "Lines should not end with a '$1'\n" . $herecurr);
5751a24edfd43 (Joe Perches 2017-11-17 15:28:52 -0800 3999) }
5751a24edfd43 (Joe Perches 2017-11-17 15:28:52 -0800 4000)
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4001) # check if this appears to be the start function declaration, save the name
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4002) if ($sline =~ /^\+\{\s*$/ &&
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4003) $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) {
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4004) $context_function = $1;
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4005) }
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4006)
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4007) # check if this appears to be the end of function declaration
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4008) if ($sline =~ /^\+\}\s*$/) {
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4009) undef $context_function;
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4010) }
4dbed76f24295 (Joe Perches 2017-05-08 15:55:39 -0700 4011)
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4012) # check indentation of any line with a bare else
840080a08492b (Joe Perches 2014-10-13 15:51:59 -0700 4013) # (but not if it is a multiple line "if (foo) return bar; else return baz;")
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4014) # if the previous line is a break or return and is indented 1 tab more...
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4015) if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4016) my $tabs = length($1) + 1;
840080a08492b (Joe Perches 2014-10-13 15:51:59 -0700 4017) if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ ||
840080a08492b (Joe Perches 2014-10-13 15:51:59 -0700 4018) ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ &&
840080a08492b (Joe Perches 2014-10-13 15:51:59 -0700 4019) defined $lines[$linenr] &&
840080a08492b (Joe Perches 2014-10-13 15:51:59 -0700 4020) $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) {
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4021) WARN("UNNECESSARY_ELSE",
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4022) "else is not generally useful after a break or return\n" . $hereprev);
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4023) }
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4024) }
032a4c0f9a77c (Joe Perches 2014-08-06 16:10:29 -0700 4025)
c00df19a5026f (Joe Perches 2014-08-06 16:11:01 -0700 4026) # check indentation of a line with a break;
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4027) # if the previous line is a goto, return or break
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4028) # and is indented the same # of tabs
c00df19a5026f (Joe Perches 2014-08-06 16:11:01 -0700 4029) if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
c00df19a5026f (Joe Perches 2014-08-06 16:11:01 -0700 4030) my $tabs = $1;
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4031) if ($prevline =~ /^\+$tabs(goto|return|break)\b/) {
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4032) if (WARN("UNNECESSARY_BREAK",
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4033) "break is not useful after a $1\n" . $hereprev) &&
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4034) $fix) {
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4035) fix_delete_line($fixlinenr, $rawline);
dc58bc553e7a8 (Joe Perches 2020-12-15 20:44:33 -0800 4036) }
c00df19a5026f (Joe Perches 2014-08-06 16:11:01 -0700 4037) }
c00df19a5026f (Joe Perches 2014-08-06 16:11:01 -0700 4038) }
c00df19a5026f (Joe Perches 2014-08-06 16:11:01 -0700 4039)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4040) # check for RCS/CVS revision markers
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4041) if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4042) WARN("CVS_KEYWORD",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4043) "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4044) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 4045)
56e77d709df72 (Joe Perches 2013-02-21 16:44:14 -0800 4046) # check for old HOTPLUG __dev<foo> section markings
56e77d709df72 (Joe Perches 2013-02-21 16:44:14 -0800 4047) if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) {
56e77d709df72 (Joe Perches 2013-02-21 16:44:14 -0800 4048) WARN("HOTPLUG_SECTION",
56e77d709df72 (Joe Perches 2013-02-21 16:44:14 -0800 4049) "Using $1 is unnecessary\n" . $herecurr);
56e77d709df72 (Joe Perches 2013-02-21 16:44:14 -0800 4050) }
56e77d709df72 (Joe Perches 2013-02-21 16:44:14 -0800 4051)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4052) # Check for potential 'bare' types
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4053) my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4054) $realline_next);
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4055) #print "LINE<$line>\n";
ca8198640fa9a (Joe Perches 2017-07-10 15:52:13 -0700 4056) if ($linenr > $suppress_statement &&
1b5539b1ffbdc (Joe Perches 2013-09-11 14:24:03 -0700 4057) $realcnt && $sline =~ /.\s*\S/) {
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 4058) ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
f5fe35dd95549 (Andy Whitcroft 2008-07-23 21:29:03 -0700 4059) ctx_statement_block($linenr, $realcnt, 0);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4060) $stat =~ s/\n./\n /g;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4061) $cond =~ s/\n./\n /g;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4062)
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4063) #print "linenr<$linenr> <$stat>\n";
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4064) # If this statement has no statement boundaries within
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4065) # it there is no point in retrying a statement scan
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4066) # until we hit end of it.
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4067) my $frag = $stat; $frag =~ s/;+\s*$//;
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4068) if ($frag !~ /(?:{|;)/) {
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4069) #print "skip<$line_nr_next>\n";
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4070) $suppress_statement = $line_nr_next;
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4071) }
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 4072)
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4073) # Find the real next line.
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4074) $realline_next = $line_nr_next;
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4075) if (defined $realline_next &&
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4076) (!defined $lines[$realline_next - 1] ||
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4077) substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4078) $realline_next++;
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4079) }
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4080)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4081) my $s = $stat;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4082) $s =~ s/{.*$//s;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4083)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4084) # Ignore goto labels.
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4085) if ($s =~ /$Ident:\*$/s) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4086)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4087) # Ignore functions being called
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4088) } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4089)
463f286485867 (Andy Whitcroft 2009-09-21 17:04:34 -0700 4090) } elsif ($s =~ /^.\s*else\b/s) {
463f286485867 (Andy Whitcroft 2009-09-21 17:04:34 -0700 4091)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4092) # declarations always start with types
d2506586586c5 (Andy Whitcroft 2008-07-23 21:29:09 -0700 4093) } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4094) my $type = $1;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4095) $type =~ s/\s+/ /g;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4096) possible($type, "A:" . $s);
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4097)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4098) # definitions in global scope can only start with types
a6a8406282173 (Andy Whitcroft 2008-10-15 22:02:30 -0700 4099) } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4100) possible($1, "B:" . $s);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4101) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4102)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4103) # any (foo ... *) is a pointer cast, and foo is a type
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4104) while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4105) possible($1, "C:" . $s);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4106) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4107)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4108) # Check for any sort of function declaration.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4109) # int foo(something bar, other baz);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4110) # void (*store_gdt)(x86_descr_ptr *);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 4111) if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4112) my ($name_len) = length($1);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4113)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4114) my $ctx = $s;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4115) substr($ctx, 0, $name_len + 1, '');
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4116) $ctx =~ s/\)[^\)]*$//;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4117)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4118) for my $arg (split(/\s*,\s*/, $ctx)) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4119) if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4120)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4121) possible($1, "D:" . $s);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4122) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4123) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4124) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4125)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4126) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4127)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4128) #
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4129) # Checks which may be anchored in the context.
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4130) #
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4131)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4132) # Check for switch () and associated case and default
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4133) # statements should be at the same indent.
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4134) if ($line=~/\bswitch\s*\(.*\)/) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4135) my $err = '';
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4136) my $sep = '';
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4137) my @ctx = ctx_block_outer($linenr, $realcnt);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4138) shift(@ctx);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4139) for my $ctx (@ctx) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4140) my ($clen, $cindent) = line_stats($ctx);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4141) if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4142) $indent != $cindent) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4143) $err .= "$sep$ctx\n";
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4144) $sep = '';
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4145) } else {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4146) $sep = "[...]\n";
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4147) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4148) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4149) if ($err ne '') {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4150) ERROR("SWITCH_CASE_INDENT_LEVEL",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4151) "switch and case should be at the same indent\n$hereline$err");
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4152) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4153) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4154)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4155) # if/while/etc brace do not go on next line, unless defining a do while loop,
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4156) # or if that brace on the next line is for something else
0fe3dc2bc554b (Joe Perches 2014-08-06 16:11:16 -0700 4157) if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4158) my $pre_ctx = "$1$2";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4159)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4160) my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
8eef05dd3e702 (Joe Perches 2012-02-03 15:20:39 -0800 4161)
8eef05dd3e702 (Joe Perches 2012-02-03 15:20:39 -0800 4162) if ($line =~ /^\+\t{6,}/) {
8eef05dd3e702 (Joe Perches 2012-02-03 15:20:39 -0800 4163) WARN("DEEP_INDENTATION",
8eef05dd3e702 (Joe Perches 2012-02-03 15:20:39 -0800 4164) "Too many leading tabs - consider code refactoring\n" . $herecurr);
8eef05dd3e702 (Joe Perches 2012-02-03 15:20:39 -0800 4165) }
8eef05dd3e702 (Joe Perches 2012-02-03 15:20:39 -0800 4166)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4167) my $ctx_cnt = $realcnt - $#ctx - 1;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4168) my $ctx = join("\n", @ctx);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4169)
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4170) my $ctx_ln = $linenr;
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4171) my $ctx_skip = $realcnt;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4172)
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4173) while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4174) defined $lines[$ctx_ln - 1] &&
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4175) $lines[$ctx_ln - 1] =~ /^-/)) {
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4176) ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4177) $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4178) $ctx_ln++;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4179) }
548596d523d83 (Andy Whitcroft 2008-07-23 21:29:01 -0700 4180)
53210168feeff (Andy Whitcroft 2008-07-23 21:29:03 -0700 4181) #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
53210168feeff (Andy Whitcroft 2008-07-23 21:29:03 -0700 4182) #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4183)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4184) if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4185) ERROR("OPEN_BRACE",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4186) "that open brace { should be on the previous line\n" .
01464f30a97c5 (Andy Whitcroft 2010-10-26 14:23:19 -0700 4187) "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4188) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4189) if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4190) $ctx =~ /\)\s*\;\s*$/ &&
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4191) defined $lines[$ctx_ln - 1])
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4192) {
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4193) my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4194) if ($nindent > $indent) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4195) WARN("TRAILING_SEMICOLON",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4196) "trailing semicolon indicates no statements, indent implies otherwise\n" .
01464f30a97c5 (Andy Whitcroft 2010-10-26 14:23:19 -0700 4197) "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4198) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4199) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4200) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4201)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4202) # Check relative indent for conditionals and blocks.
f6950a735f29e (Joe Perches 2017-05-08 15:56:05 -0700 4203) if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4204) ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4205) ctx_statement_block($linenr, $realcnt, 0)
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 4206) if (!defined $stat);
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4207) my ($s, $c) = ($stat, $cond);
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4208)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4209) substr($s, 0, length($c), '');
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4210)
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4211) # remove inline comments
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4212) $s =~ s/$;/ /g;
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4213) $c =~ s/$;/ /g;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4214)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4215) # Find out how long the conditional actually is.
6f779c18ca743 (Andy Whitcroft 2008-10-15 22:02:27 -0700 4216) my @newlines = ($c =~ /\n/gs);
6f779c18ca743 (Andy Whitcroft 2008-10-15 22:02:27 -0700 4217) my $cond_lines = 1 + $#newlines;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4218)
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4219) # Make sure we remove the line prefixes as we have
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4220) # none on the first line, and are going to readd them
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4221) # where necessary.
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4222) $s =~ s/\n./\n/gs;
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4223) while ($s =~ /\n\s+\\\n/) {
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4224) $cond_lines += $s =~ s/\n\s+\\\n/\n/g;
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4225) }
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4226)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4227) # We want to check the first line inside the block
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4228) # starting at the end of the conditional, so remove:
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4229) # 1) any blank line termination
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4230) # 2) any opening brace { on end of the line
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4231) # 3) any do (...) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4232) my $continuation = 0;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4233) my $check = 0;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4234) $s =~ s/^.*\bdo\b//;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4235) $s =~ s/^\s*{//;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4236) if ($s =~ s/^\s*\\//) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4237) $continuation = 1;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4238) }
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4239) if ($s =~ s/^\s*?\n//) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4240) $check = 1;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4241) $cond_lines++;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4242) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4243)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4244) # Also ignore a loop construct at the end of a
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4245) # preprocessor statement.
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4246) if (($prevline =~ /^.\s*#\s*define\s/ ||
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4247) $prevline =~ /\\\s*$/) && $continuation == 0) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4248) $check = 0;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4249) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4250)
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4251) my $cond_ptr = -1;
740504c61f79a (Andy Whitcroft 2008-10-15 22:02:35 -0700 4252) $continuation = 0;
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4253) while ($cond_ptr != $cond_lines) {
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4254) $cond_ptr = $cond_lines;
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4255)
f16fa28f7b3d9 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4256) # If we see an #else/#elif then the code
f16fa28f7b3d9 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4257) # is not linear.
f16fa28f7b3d9 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4258) if ($s =~ /^\s*\#\s*(?:else|elif)/) {
f16fa28f7b3d9 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4259) $check = 0;
f16fa28f7b3d9 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4260) }
f16fa28f7b3d9 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4261)
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4262) # Ignore:
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4263) # 1) blank lines, they should be at 0,
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4264) # 2) preprocessor lines, and
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4265) # 3) labels.
740504c61f79a (Andy Whitcroft 2008-10-15 22:02:35 -0700 4266) if ($continuation ||
740504c61f79a (Andy Whitcroft 2008-10-15 22:02:35 -0700 4267) $s =~ /^\s*?\n/ ||
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4268) $s =~ /^\s*#\s*?/ ||
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4269) $s =~ /^\s*$Ident\s*:/) {
740504c61f79a (Andy Whitcroft 2008-10-15 22:02:35 -0700 4270) $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
30dad6ebecffe (Andy Whitcroft 2009-09-21 17:04:36 -0700 4271) if ($s =~ s/^.*?\n//) {
30dad6ebecffe (Andy Whitcroft 2009-09-21 17:04:36 -0700 4272) $cond_lines++;
30dad6ebecffe (Andy Whitcroft 2009-09-21 17:04:36 -0700 4273) }
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4274) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4275) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4276)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4277) my (undef, $sindent) = line_stats("+" . $s);
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4278) my $stat_real = raw_line($linenr, $cond_lines);
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4279)
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4280) # Check if either of these lines are modified, else
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4281) # this is not this patch's fault.
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4282) if (!defined($stat_real) ||
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4283) $stat !~ /^\+/ && $stat_real !~ /^\+/) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4284) $check = 0;
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4285) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4286) if (defined($stat_real) && $cond_lines > 1) {
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4287) $stat_real = "[...]\n$stat_real";
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4288) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4289)
9bd49efe4e4bf (Andy Whitcroft 2008-10-15 22:02:22 -0700 4290) #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4291)
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4292) if ($check && $s ne '' &&
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 4293) (($sindent % $tabsize) != 0 ||
9f5af480f4554 (Joe Perches 2015-09-09 15:37:30 -0700 4294) ($sindent < $indent) ||
f6950a735f29e (Joe Perches 2017-05-08 15:56:05 -0700 4295) ($sindent == $indent &&
f6950a735f29e (Joe Perches 2017-05-08 15:56:05 -0700 4296) ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
713a09de9ca9a (Antonio Borneo 2020-04-06 20:11:07 -0700 4297) ($sindent > $indent + $tabsize))) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4298) WARN("SUSPECT_CODE_INDENT",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4299) "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4300) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4301) }
4d001e4d88a57 (Andy Whitcroft 2008-10-15 22:02:21 -0700 4302)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4303) # Track the 'values' across context and added lines.
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4304) my $opline = $line; $opline =~ s/^./ /;
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 4305) my ($curr_values, $curr_vars) =
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 4306) annotate_values($opline . "\n", $prev_values);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4307) $curr_values = $prev_values . $curr_values;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4308) if ($dbg_values) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4309) my $outline = $opline; $outline =~ s/\t/ /g;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4310) print "$linenr > .$outline\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4311) print "$linenr > $curr_values\n";
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 4312) print "$linenr > $curr_vars\n";
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4313) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4314) $prev_values = substr($curr_values, -1);
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4315)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4316) #ignore lines not being added
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4317) next if ($line =~ /^[^\+]/);
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4318)
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4319) # check for self assignments used to avoid compiler warnings
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4320) # e.g.: int foo = foo, *bar = NULL;
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4321) # struct foo bar = *(&(bar));
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4322) if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4323) my $var = $1;
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4324) if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) {
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4325) WARN("SELF_ASSIGNMENT",
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4326) "Do not use self-assignments to avoid compiler warnings\n" . $herecurr);
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4327) }
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4328) }
99ca38c2aa7da (Joe Perches 2020-10-15 20:12:09 -0700 4329)
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4330) # check for dereferences that span multiple lines
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4331) if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4332) $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4333) $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4334) my $ref = $1;
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4335) $line =~ /^.\s*($Lval)/;
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4336) $ref .= $1;
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4337) $ref =~ s/\s//g;
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4338) WARN("MULTILINE_DEREFERENCE",
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4339) "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4340) }
11ca40a0f8e3a (Joe Perches 2016-12-12 16:46:31 -0800 4341)
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4342) # check for declarations of signed or unsigned without int
c844711575086 (Joe Perches 2016-08-02 14:04:42 -0700 4343) while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4344) my $type = $1;
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4345) my $var = $2;
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4346) $var = "" if (!defined $var);
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4347) if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4348) my $sign = $1;
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4349) my $pointer = $2;
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4350)
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4351) $pointer = "" if (!defined $pointer);
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4352)
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4353) if (WARN("UNSPECIFIED_INT",
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4354) "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) &&
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4355) $fix) {
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4356) my $decl = trim($sign) . " int ";
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4357) my $comp_pointer = $pointer;
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4358) $comp_pointer =~ s/\s//g;
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4359) $decl .= $comp_pointer;
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4360) $decl = rtrim($decl) if ($var eq "");
207a8e8465f91 (Joe Perches 2016-03-15 14:58:06 -0700 4361) $fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4362) }
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4363) }
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4364) }
a1ce18e4f941d (Joe Perches 2016-03-15 14:58:03 -0700 4365)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4366) # TEST: allow direct testing of the type matcher.
7429c6903e362 (Andy Whitcroft 2008-07-23 21:29:06 -0700 4367) if ($dbg_type) {
7429c6903e362 (Andy Whitcroft 2008-07-23 21:29:06 -0700 4368) if ($line =~ /^.\s*$Declare\s*$/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4369) ERROR("TEST_TYPE",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4370) "TEST: is type\n" . $herecurr);
7429c6903e362 (Andy Whitcroft 2008-07-23 21:29:06 -0700 4371) } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4372) ERROR("TEST_NOT_TYPE",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4373) "TEST: is not type ($1 is)\n". $herecurr);
7429c6903e362 (Andy Whitcroft 2008-07-23 21:29:06 -0700 4374) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4375) next;
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4376) }
a1ef277e2c88c (Andy Whitcroft 2008-10-15 22:02:17 -0700 4377) # TEST: allow direct testing of the attribute matcher.
a1ef277e2c88c (Andy Whitcroft 2008-10-15 22:02:17 -0700 4378) if ($dbg_attr) {
9360b0e50e9f3 (Andy Whitcroft 2009-02-27 14:03:08 -0800 4379) if ($line =~ /^.\s*$Modifier\s*$/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4380) ERROR("TEST_ATTR",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4381) "TEST: is attr\n" . $herecurr);
9360b0e50e9f3 (Andy Whitcroft 2009-02-27 14:03:08 -0800 4382) } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4383) ERROR("TEST_NOT_ATTR",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4384) "TEST: is not attr ($1 is)\n". $herecurr);
a1ef277e2c88c (Andy Whitcroft 2008-10-15 22:02:17 -0700 4385) }
a1ef277e2c88c (Andy Whitcroft 2008-10-15 22:02:17 -0700 4386) next;
a1ef277e2c88c (Andy Whitcroft 2008-10-15 22:02:17 -0700 4387) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4388)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 4389) # check for initialisation to aggregates open brace on the next line
99423c2065b62 (Andy Whitcroft 2009-10-26 16:50:15 -0700 4390) if ($line =~ /^.\s*{/ &&
99423c2065b62 (Andy Whitcroft 2009-10-26 16:50:15 -0700 4391) $prevline =~ /(?:^|[^=])=\s*$/) {
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4392) if (ERROR("OPEN_BRACE",
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4393) "that open brace { should be on the previous line\n" . $hereprev) &&
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 4394) $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 4395) fix_delete_line($fixlinenr - 1, $prevrawline);
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 4396) fix_delete_line($fixlinenr, $rawline);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4397) my $fixedline = $prevrawline;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4398) $fixedline =~ s/\s*=\s*$/ = {/;
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 4399) fix_insert_line($fixlinenr, $fixedline);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4400) $fixedline = $line;
8d81ae05d0176 (Cyril Bur 2017-07-10 15:52:21 -0700 4401) $fixedline =~ s/^(.\s*)\{\s*/$1/;
f2d7e4d439809 (Joe Perches 2014-08-06 16:11:07 -0700 4402) fix_insert_line($fixlinenr, $fixedline);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 4403) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 4404) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 4405)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4406) #
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4407) # Checks which are anchored on the added line.
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4408) #
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4409)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4410) # check for malformed paths in #include statements (uses RAW line)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4411) if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4412) my $path = $1;
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4413) if ($path =~ m{//}) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4414) ERROR("MALFORMED_INCLUDE",
495e9d84607cd (Joe Perches 2012-12-20 15:05:37 -0800 4415) "malformed #include filename\n" . $herecurr);
495e9d84607cd (Joe Perches 2012-12-20 15:05:37 -0800 4416) }
495e9d84607cd (Joe Perches 2012-12-20 15:05:37 -0800 4417) if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
495e9d84607cd (Joe Perches 2012-12-20 15:05:37 -0800 4418) ERROR("UAPI_INCLUDE",
495e9d84607cd (Joe Perches 2012-12-20 15:05:37 -0800 4419) "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4420) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4421) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4422)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4423) # no C99 // comments
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4424) if ($line =~ m{//}) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4425) if (ERROR("C99_COMMENTS",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4426) "do not use C99 // comments\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4427) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4428) my $line = $fixed[$fixlinenr];
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4429) if ($line =~ /\/\/(.*)$/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4430) my $comment = trim($1);
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4431) $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4432) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4433) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4434) }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4435) # Remove C99 comments.
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4436) $line =~ s@//.*@@;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4437) $opline =~ s@//.*@@;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4438)
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4439) # EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4440) # the whole statement.
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4441) #print "APW <$lines[$realline_next - 1]>\n";
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4442) if (defined $realline_next &&
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4443) exists $lines[$realline_next - 1] &&
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4444) !defined $suppress_export{$realline_next} &&
367948220fcef (Christoph Hellwig 2021-02-02 13:13:34 +0100 4445) ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4446) # Handle definitions which produce identifiers with
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4447) # a prefix:
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4448) # XXX(foo);
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4449) # EXPORT_SYMBOL(something_foo);
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4450) my $name = $1;
87a5387718562 (Andy Whitcroft 2012-01-10 15:10:04 -0800 4451) if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4452) $name =~ /^${Ident}_$2/) {
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4453) #print "FOO C name<$name>\n";
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4454) $suppress_export{$realline_next} = 1;
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4455)
3cbf62df3a8ce (Andy Whitcroft 2010-10-26 14:23:18 -0700 4456) } elsif ($stat !~ /(?:
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4457) \n.}\s*$|
480120586464e (Andy Whitcroft 2008-10-15 22:02:34 -0700 4458) ^.DEFINE_$Ident\(\Q$name\E\)|
480120586464e (Andy Whitcroft 2008-10-15 22:02:34 -0700 4459) ^.DECLARE_$Ident\(\Q$name\E\)|
480120586464e (Andy Whitcroft 2008-10-15 22:02:34 -0700 4460) ^.LIST_HEAD\(\Q$name\E\)|
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4461) ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4462) \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
480120586464e (Andy Whitcroft 2008-10-15 22:02:34 -0700 4463) )/x) {
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4464) #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4465) $suppress_export{$realline_next} = 2;
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4466) } else {
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4467) $suppress_export{$realline_next} = 1;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4468) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4469) }
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4470) if (!defined $suppress_export{$linenr} &&
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4471) $prevline =~ /^.\s*$/ &&
367948220fcef (Christoph Hellwig 2021-02-02 13:13:34 +0100 4472) ($line =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4473) #print "FOO B <$lines[$linenr - 1]>\n";
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4474) $suppress_export{$linenr} = 2;
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4475) }
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4476) if (defined $suppress_export{$linenr} &&
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4477) $suppress_export{$linenr} == 2) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4478) WARN("EXPORT_SYMBOL",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4479) "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
2b474a1a56606 (Andy Whitcroft 2009-10-26 16:50:16 -0700 4480) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4481)
5150bda43c58c (Joe Eloff 2010-08-09 17:21:00 -0700 4482) # check for global initialisers.
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 4483) if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ &&
5b8f82e1a1769 (Song Liu 2021-02-25 17:22:08 -0800 4484) !exclude_global_initialisers($realfile)) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4485) if (ERROR("GLOBAL_INITIALISERS",
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 4486) "do not initialise globals to $1\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4487) $fix) {
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 4488) $fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4489) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 4490) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4491) # check for static initialisers.
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 4492) if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4493) if (ERROR("INITIALISED_STATIC",
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 4494) "do not initialise statics to $1\n" .
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4495) $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4496) $fix) {
6d32f7a391466 (Joe Perches 2015-11-06 16:31:37 -0800 4497) $fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 4498) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4499) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4500)
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4501) # check for misordered declarations of char/short/int/long with signed/unsigned
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4502) while ($sline =~ m{(\b$TypeMisordered\b)}g) {
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4503) my $tmp = trim($1);
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4504) WARN("MISORDERED_TYPE",
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4505) "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4506) }
1813087dbc54f (Joe Perches 2014-08-06 16:11:22 -0700 4507)
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4508) # check for unnecessary <signed> int declarations of short/long/long long
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4509) while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4510) my $type = trim($1);
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4511) next if ($type !~ /\bint\b/);
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4512) next if ($type !~ /\b(?:short|long\s+long|long)\b/);
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4513) my $new_type = $type;
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4514) $new_type =~ s/\b\s*int\s*\b/ /;
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4515) $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4516) $new_type =~ s/^const\s+//;
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4517) $new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/);
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4518) $new_type = "const $new_type" if ($type =~ /^const\b/);
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4519) $new_type =~ s/\s+/ /g;
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4520) $new_type = trim($new_type);
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4521) if (WARN("UNNECESSARY_INT",
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4522) "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) &&
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4523) $fix) {
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4524) $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4525) }
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4526) }
809e082e973da (Joe Perches 2018-08-21 21:58:12 -0700 4527)
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4528) # check for static const char * arrays.
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4529) if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4530) WARN("STATIC_CONST_CHAR_ARRAY",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4531) "static const char * array should probably be static const char * const\n" .
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4532) $herecurr);
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4533) }
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4534)
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4535) # check for initialized const char arrays that should be static const
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4536) if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4537) if (WARN("STATIC_CONST_CHAR_ARRAY",
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4538) "const array should probably be static const\n" . $herecurr) &&
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4539) $fix) {
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4540) $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4541) }
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4542) }
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4543)
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4544) # check for static char foo[] = "bar" declarations.
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4545) if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4546) WARN("STATIC_CONST_CHAR_ARRAY",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4547) "static char array declaration should probably be static const char\n" .
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4548) $herecurr);
77b8c0a8e4748 (Joe Perches 2019-01-03 15:26:59 -0800 4549) }
cb710eca68204 (Joe Perches 2010-10-26 14:23:20 -0700 4550)
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4551) # check for const <foo> const where <foo> is not a pointer or array type
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4552) if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4553) my $found = $1;
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4554) if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4555) WARN("CONST_CONST",
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4556) "'const $found const *' should probably be 'const $found * const'\n" . $herecurr);
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4557) } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4558) WARN("CONST_CONST",
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4559) "'const $found const' should probably be 'const $found'\n" . $herecurr);
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4560) }
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4561) }
ab7e23f3448e5 (Joe Perches 2015-04-16 12:44:22 -0700 4562)
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4563) # check for const static or static <non ptr type> const declarations
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4564) # prefer 'static const <foo>' over 'const static <foo>' and 'static <foo> const'
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4565) if ($sline =~ /^\+\s*const\s+static\s+($Type)\b/ ||
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4566) $sline =~ /^\+\s*static\s+($BasicType)\s+const\b/) {
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4567) if (WARN("STATIC_CONST",
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4568) "Move const after static - use 'static const $1'\n" . $herecurr) &&
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4569) $fix) {
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4570) $fixed[$fixlinenr] =~ s/\bconst\s+static\b/static const/;
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4571) $fixed[$fixlinenr] =~ s/\bstatic\s+($BasicType)\s+const\b/static const $1/;
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4572) }
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4573) }
73169765e6e7a (Joe Perches 2020-12-15 20:44:30 -0800 4574)
9b0fa60d9be0a (Joe Perches 2014-04-03 14:49:18 -0700 4575) # check for non-global char *foo[] = {"bar", ...} declarations.
9b0fa60d9be0a (Joe Perches 2014-04-03 14:49:18 -0700 4576) if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
9b0fa60d9be0a (Joe Perches 2014-04-03 14:49:18 -0700 4577) WARN("STATIC_CONST_CHAR_ARRAY",
9b0fa60d9be0a (Joe Perches 2014-04-03 14:49:18 -0700 4578) "char * array declaration might be better as static const\n" .
9b0fa60d9be0a (Joe Perches 2014-04-03 14:49:18 -0700 4579) $herecurr);
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 4580) }
9b0fa60d9be0a (Joe Perches 2014-04-03 14:49:18 -0700 4581)
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4582) # check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4583) if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4584) my $array = $1;
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4585) if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4586) my $array_div = $1;
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4587) if (WARN("ARRAY_SIZE",
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4588) "Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4589) $fix) {
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4590) $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4591) }
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4592) }
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4593) }
b598b67060f14 (Joe Perches 2015-04-16 12:44:36 -0700 4594)
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4595) # check for function declarations without arguments like "int foo()"
16b7f3c89907a (Joe Perches 2020-04-06 20:11:17 -0700 4596) if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) {
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4597) if (ERROR("FUNCTION_WITHOUT_ARGS",
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4598) "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4599) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4600) $fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4601) }
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4602) }
b36190c5f8572 (Joe Perches 2014-01-27 17:07:18 -0800 4603)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4604) # check for new typedefs, only function parameters and sparse annotations
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4605) # make sense.
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4606) if ($line =~ /\btypedef\s/ &&
8054576dca7e7 (Andy Whitcroft 2009-01-06 14:41:26 -0800 4607) $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4608) $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
8ed22cad9ce16 (Andy Whitcroft 2008-10-15 22:02:32 -0700 4609) $line !~ /\b$typeTypedefs\b/ &&
46d832f5e2102 (Michael S. Tsirkin 2016-12-11 06:29:58 +0200 4610) $line !~ /\b__bitwise\b/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4611) WARN("NEW_TYPEDEFS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4612) "do not add new typedefs\n" . $herecurr);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4613) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4614)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4615) # * goes on variable not on type
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4616) # (char*[ const])
bfcb2cc798a14 (Andy Whitcroft 2012-01-10 15:10:15 -0800 4617) while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
bfcb2cc798a14 (Andy Whitcroft 2012-01-10 15:10:15 -0800 4618) #print "AA<$1>\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4619) my ($ident, $from, $to) = ($1, $2, $2);
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4620)
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4621) # Should start with a space.
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4622) $to =~ s/^(\S)/ $1/;
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4623) # Should not end with a space.
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4624) $to =~ s/\s+$//;
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4625) # '*'s should not have spaces between.
f9a0b3d17a01f (Andy Whitcroft 2009-01-15 13:51:05 -0800 4626) while ($to =~ s/\*\s+\*/\*\*/) {
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4627) }
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 4628)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4629) ## print "1: from<$from> to<$to> ident<$ident>\n";
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4630) if ($from ne $to) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4631) if (ERROR("POINTER_LOCATION",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4632) "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4633) $fix) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4634) my $sub_from = $ident;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4635) my $sub_to = $ident;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4636) $sub_to =~ s/\Q$from\E/$to/;
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4637) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4638) s@\Q$sub_from\E@$sub_to@;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4639) }
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4640) }
bfcb2cc798a14 (Andy Whitcroft 2012-01-10 15:10:15 -0800 4641) }
bfcb2cc798a14 (Andy Whitcroft 2012-01-10 15:10:15 -0800 4642) while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
bfcb2cc798a14 (Andy Whitcroft 2012-01-10 15:10:15 -0800 4643) #print "BB<$1>\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4644) my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4645)
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4646) # Should start with a space.
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4647) $to =~ s/^(\S)/ $1/;
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4648) # Should not end with a space.
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4649) $to =~ s/\s+$//;
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4650) # '*'s should not have spaces between.
f9a0b3d17a01f (Andy Whitcroft 2009-01-15 13:51:05 -0800 4651) while ($to =~ s/\*\s+\*/\*\*/) {
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4652) }
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4653) # Modifiers should have spaces.
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4654) $to =~ s/(\b$Modifier$)/$1 /;
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 4655)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4656) ## print "2: from<$from> to<$to> ident<$ident>\n";
667026e7b082a (Andy Whitcroft 2009-02-27 14:03:08 -0800 4657) if ($from ne $to && $ident !~ /^$Modifier$/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4658) if (ERROR("POINTER_LOCATION",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4659) "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4660) $fix) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4661)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4662) my $sub_from = $match;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4663) my $sub_to = $match;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4664) $sub_to =~ s/\Q$from\E/$to/;
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4665) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4666) s@\Q$sub_from\E@$sub_to@;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4667) }
65863862ba112 (Andy Whitcroft 2009-01-06 14:41:21 -0800 4668) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4669) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4670)
9d3e3c705eb39 (Joe Perches 2015-09-09 15:37:27 -0700 4671) # avoid BUG() or BUG_ON()
9d3e3c705eb39 (Joe Perches 2015-09-09 15:37:27 -0700 4672) if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 4673) my $msg_level = \&WARN;
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 4674) $msg_level = \&CHK if ($file);
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 4675) &{$msg_level}("AVOID_BUG",
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 4676) "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr);
9d3e3c705eb39 (Joe Perches 2015-09-09 15:37:27 -0700 4677) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4678)
9d3e3c705eb39 (Joe Perches 2015-09-09 15:37:27 -0700 4679) # avoid LINUX_VERSION_CODE
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4680) if ($line =~ /\bLINUX_VERSION_CODE\b/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4681) WARN("LINUX_VERSION_CODE",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4682) "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4683) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4684)
17441227f6258 (Joe Perches 2011-06-15 15:08:17 -0700 4685) # check for uses of printk_ratelimit
17441227f6258 (Joe Perches 2011-06-15 15:08:17 -0700 4686) if ($line =~ /\bprintk_ratelimit\s*\(/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 4687) WARN("PRINTK_RATELIMITED",
101ee6802a77d (Joe Perches 2015-02-13 14:38:54 -0800 4688) "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
17441227f6258 (Joe Perches 2011-06-15 15:08:17 -0700 4689) }
17441227f6258 (Joe Perches 2011-06-15 15:08:17 -0700 4690)
eeef5733e30e7 (Joe Perches 2017-11-17 15:28:41 -0800 4691) # printk should use KERN_* levels
eeef5733e30e7 (Joe Perches 2017-11-17 15:28:41 -0800 4692) if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
eeef5733e30e7 (Joe Perches 2017-11-17 15:28:41 -0800 4693) WARN("PRINTK_WITHOUT_KERN_LEVEL",
eeef5733e30e7 (Joe Perches 2017-11-17 15:28:41 -0800 4694) "printk() should include KERN_<LEVEL> facility level\n" . $herecurr);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4695) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4696)
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4697) # prefer variants of (subsystem|netdev|dev|pr)_<level> to printk(KERN_<LEVEL>
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4698) if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4699) my $printk = $1;
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4700) my $modifier = $2;
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4701) my $orig = $3;
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4702) $modifier = "" if (!defined($modifier));
243f3803cf2a3 (Joe Perches 2012-05-31 16:26:09 -0700 4703) my $level = lc($orig);
243f3803cf2a3 (Joe Perches 2012-05-31 16:26:09 -0700 4704) $level = "warn" if ($level eq "warning");
8f26b8376faad (Joe Perches 2012-10-04 17:13:32 -0700 4705) my $level2 = $level;
8f26b8376faad (Joe Perches 2012-10-04 17:13:32 -0700 4706) $level2 = "dbg" if ($level eq "debug");
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4707) $level .= $modifier;
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4708) $level2 .= $modifier;
243f3803cf2a3 (Joe Perches 2012-05-31 16:26:09 -0700 4709) WARN("PREFER_PR_LEVEL",
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4710) "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to $printk(KERN_$orig ...\n" . $herecurr);
243f3803cf2a3 (Joe Perches 2012-05-31 16:26:09 -0700 4711) }
243f3803cf2a3 (Joe Perches 2012-05-31 16:26:09 -0700 4712)
f5eea3b0442da (Joe Perches 2020-12-15 20:45:24 -0800 4713) # prefer dev_<level> to dev_printk(KERN_<LEVEL>
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4714) if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4715) my $orig = $1;
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4716) my $level = lc($orig);
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4717) $level = "warn" if ($level eq "warning");
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4718) $level = "dbg" if ($level eq "debug");
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4719) WARN("PREFER_DEV_LEVEL",
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4720) "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4721) }
dc1393130b026 (Joe Perches 2013-02-21 16:44:13 -0800 4722)
8020b25363128 (Nicolas Boichat 2020-10-15 20:12:02 -0700 4723) # trace_printk should not be used in production code.
8020b25363128 (Nicolas Boichat 2020-10-15 20:12:02 -0700 4724) if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) {
8020b25363128 (Nicolas Boichat 2020-10-15 20:12:02 -0700 4725) WARN("TRACE_PRINTK",
8020b25363128 (Nicolas Boichat 2020-10-15 20:12:02 -0700 4726) "Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr);
8020b25363128 (Nicolas Boichat 2020-10-15 20:12:02 -0700 4727) }
8020b25363128 (Nicolas Boichat 2020-10-15 20:12:02 -0700 4728)
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4729) # ENOSYS means "bad syscall nr" and nothing else. This will have a small
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4730) # number of false positives, but assembly files are not checked, so at
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4731) # least the arch entry code will not trigger this warning.
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4732) if ($line =~ /\bENOSYS\b/) {
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4733) WARN("ENOSYS",
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4734) "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr);
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4735) }
91c9afaf97ee5 (Andy Lutomirski 2015-04-16 12:44:44 -0700 4736)
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4737) # ENOTSUPP is not a standard error code and should be avoided in new patches.
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4738) # Folks usually mean EOPNOTSUPP (also called ENOTSUP), when they type ENOTSUPP.
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4739) # Similarly to ENOSYS warning a small number of false positives is expected.
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4740) if (!$file && $line =~ /\bENOTSUPP\b/) {
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4741) if (WARN("ENOTSUPP",
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4742) "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP\n" . $herecurr) &&
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4743) $fix) {
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4744) $fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/;
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4745) }
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4746) }
6b9ea5ff5abdc (Jakub Kicinski 2020-05-11 10:08:07 -0700 4747)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4748) # function brace can't be on same line, except for #defines of do while,
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4749) # or if closed on same line
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 4750) if ($perl_version_ok &&
2d453e3b41c80 (Joe Perches 2018-02-06 15:39:09 -0800 4751) $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
2d453e3b41c80 (Joe Perches 2018-02-06 15:39:09 -0800 4752) $sline !~ /\#\s*define\b.*do\s*\{/ &&
2d453e3b41c80 (Joe Perches 2018-02-06 15:39:09 -0800 4753) $sline !~ /}/) {
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4754) if (ERROR("OPEN_BRACE",
2d453e3b41c80 (Joe Perches 2018-02-06 15:39:09 -0800 4755) "open brace '{' following function definitions go on the next line\n" . $herecurr) &&
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4756) $fix) {
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4757) fix_delete_line($fixlinenr, $rawline);
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4758) my $fixed_line = $rawline;
03f4935135b9e (Dwaipayan Ray 2020-12-15 20:45:02 -0800 4759) $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/;
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4760) my $line1 = $1;
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4761) my $line2 = $2;
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4762) fix_insert_line($fixlinenr, ltrim($line1));
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4763) fix_insert_line($fixlinenr, "\+{");
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4764) if ($line2 !~ /^\s*$/) {
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4765) fix_insert_line($fixlinenr, "\+\t" . trim($line2));
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4766) }
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4767) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4768) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4769)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4770) # open braces for enum, union and struct go on the same line.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4771) if ($line =~ /^.\s*{/ &&
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4772) $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4773) if (ERROR("OPEN_BRACE",
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4774) "open brace '{' following $1 go on the same line\n" . $hereprev) &&
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4775) $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4776) fix_delete_line($fixlinenr - 1, $prevrawline);
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4777) fix_delete_line($fixlinenr, $rawline);
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4778) my $fixedline = rtrim($prevrawline) . " {";
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4779) fix_insert_line($fixlinenr, $fixedline);
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4780) $fixedline = $rawline;
8d81ae05d0176 (Cyril Bur 2017-07-10 15:52:21 -0700 4781) $fixedline =~ s/^(.\s*)\{\s*/$1\t/;
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4782) if ($fixedline !~ /^\+\s*$/) {
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4783) fix_insert_line($fixlinenr, $fixedline);
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4784) }
8d1824780f2f1 (Joe Perches 2014-08-06 16:11:12 -0700 4785) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4786) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 4787)
0c73b4eb7a825 (Andy Whitcroft 2010-10-26 14:23:15 -0700 4788) # missing space after union, struct or enum definition
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4789) if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4790) if (WARN("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4791) "missing space after $1 definition\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4792) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4793) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4794) s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4795) }
0c73b4eb7a825 (Andy Whitcroft 2010-10-26 14:23:15 -0700 4796) }
0c73b4eb7a825 (Andy Whitcroft 2010-10-26 14:23:15 -0700 4797)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4798) # Function pointer declarations
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4799) # check spacing between type, funcptr, and args
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4800) # canonical declaration is "type (*funcptr)(args...)"
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4801) if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4802) my $declare = $1;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4803) my $pre_pointer_space = $2;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4804) my $post_pointer_space = $3;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4805) my $funcname = $4;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4806) my $post_funcname_space = $5;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4807) my $pre_args_space = $6;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4808)
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4809) # the $Declare variable will capture all spaces after the type
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4810) # so check it for a missing trailing missing space but pointer return types
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4811) # don't need a space so don't warn for those.
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4812) my $post_declare_space = "";
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4813) if ($declare =~ /(\s+)$/) {
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4814) $post_declare_space = $1;
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4815) $declare = rtrim($declare);
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4816) }
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4817) if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4818) WARN("SPACING",
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4819) "missing space after return type\n" . $herecurr);
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4820) $post_declare_space = " ";
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4821) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4822)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4823) # unnecessary space "type (*funcptr)(args...)"
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4824) # This test is not currently implemented because these declarations are
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4825) # equivalent to
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4826) # int foo(int bar, ...)
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4827) # and this is form shouldn't/doesn't generate a checkpatch warning.
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4828) #
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4829) # elsif ($declare =~ /\s{2,}$/) {
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4830) # WARN("SPACING",
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4831) # "Multiple spaces after return type\n" . $herecurr);
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4832) # }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4833)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4834) # unnecessary space "type ( *funcptr)(args...)"
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4835) if (defined $pre_pointer_space &&
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4836) $pre_pointer_space =~ /^\s/) {
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4837) WARN("SPACING",
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4838) "Unnecessary space after function pointer open parenthesis\n" . $herecurr);
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4839) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4840)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4841) # unnecessary space "type (* funcptr)(args...)"
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4842) if (defined $post_pointer_space &&
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4843) $post_pointer_space =~ /^\s/) {
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4844) WARN("SPACING",
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4845) "Unnecessary space before function pointer name\n" . $herecurr);
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4846) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4847)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4848) # unnecessary space "type (*funcptr )(args...)"
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4849) if (defined $post_funcname_space &&
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4850) $post_funcname_space =~ /^\s/) {
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4851) WARN("SPACING",
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4852) "Unnecessary space after function pointer name\n" . $herecurr);
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4853) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4854)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4855) # unnecessary space "type (*funcptr) (args...)"
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4856) if (defined $pre_args_space &&
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4857) $pre_args_space =~ /^\s/) {
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4858) WARN("SPACING",
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4859) "Unnecessary space before function pointer arguments\n" . $herecurr);
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4860) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4861)
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4862) if (show_type("SPACING") && $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4863) $fixed[$fixlinenr] =~
91f72e9c6ed14 (Joe Perches 2014-04-03 14:49:12 -0700 4864) s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4865) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4866) }
31070b5d4490c (Joe Perches 2014-01-23 15:54:49 -0800 4867)
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4868) # check for spacing round square brackets; allowed:
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4869) # 1. with a type on the left -- int [] a;
fe2a7dbc85f37 (Andy Whitcroft 2008-10-15 22:02:15 -0700 4870) # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
fe2a7dbc85f37 (Andy Whitcroft 2008-10-15 22:02:15 -0700 4871) # 3. inside a curly brace -- = { [0...10] = 5 }
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4872) while ($line =~ /(.*?\s)\[/g) {
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4873) my ($where, $prefix) = ($-[1], $1);
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4874) if ($prefix !~ /$Type\s+$/ &&
fe2a7dbc85f37 (Andy Whitcroft 2008-10-15 22:02:15 -0700 4875) ($where != 0 || $prefix !~ /^.\s+$/) &&
38dca988bb208 (Heinrich Schuchardt 2018-04-10 16:34:14 -0700 4876) $prefix !~ /[{,:]\s+$/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4877) if (ERROR("BRACKET_SPACE",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4878) "space prohibited before open square bracket '['\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4879) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4880) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4881) s/^(\+.*?)\s+\[/$1\[/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4882) }
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4883) }
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4884) }
8d31cfcecf675 (Andy Whitcroft 2008-07-23 21:29:02 -0700 4885)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 4886) # check for spaces between functions and their parentheses.
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4887) while ($line =~ /($Ident)\s+\(/g) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4888) my $name = $1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4889) my $ctx_before = substr($line, 0, $-[1]);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4890) my $ctx = "$ctx_before$name";
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4891)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4892) # Ignore those directives where spaces _are_ permitted.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4893) if ($name =~ /^(?:
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4894) if|for|while|switch|return|case|
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4895) volatile|__volatile__|
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4896) __attribute__|format|__extension__|
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4897) asm|__asm__)$/x)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4898) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4899) # cpp #define statements have non-optional spaces, ie
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4900) # if there is a space between the name and the open
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4901) # parenthesis it is simply not a parameter group.
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4902) } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4903)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4904) # cpp #elif statement condition may start with a (
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 4905) } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4906)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4907) # If this whole things ends with a type its most
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4908) # likely a typedef for a function.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4909) } elsif ($ctx =~ /$Type$/) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4910)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 4911) } else {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4912) if (WARN("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4913) "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4914) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 4915) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4916) s/\b$name\s+\(/$name\(/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4917) }
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4918) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 4919) }
9a4cad4e25b91 (Eric Nelson 2012-05-31 16:26:09 -0700 4920)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 4921) # Check operator spacing.
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4922) if (!($line=~/\#\s*include/)) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4923) my $fixed_line = "";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4924) my $line_fixed = 0;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4925)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4926) my $ops = qr{
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4927) <<=|>>=|<=|>=|==|!=|
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4928) \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4929) =>|->|<<|>>|<|>|=|!|~|
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 4930) &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
847316231c2f8 (Joe Perches 2013-11-12 15:10:05 -0800 4931) \?:|\?|:
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 4932) }x;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4933) my @elements = split(/($ops|;)/, $opline);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4934)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4935) ## print("element count: <" . $#elements . ">\n");
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4936) ## foreach my $el (@elements) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4937) ## print("el: <$el>\n");
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4938) ## }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4939)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4940) my @fix_elements = ();
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 4941) my $off = 0;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4942)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4943) foreach my $el (@elements) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4944) push(@fix_elements, substr($rawline, $off, length($el)));
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4945) $off += length($el);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4946) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4947)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4948) $off = 0;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4949)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4950) my $blank = copy_spacing($opline);
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 4951) my $last_after = -1;
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4952)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4953) for (my $n = 0; $n < $#elements; $n += 2) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4954)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4955) my $good = $fix_elements[$n] . $fix_elements[$n + 1];
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4956)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4957) ## print("n: <$n> good: <$good>\n");
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 4958)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4959) $off += length($elements[$n]);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4960)
25985edcedea6 (Lucas De Marchi 2011-03-30 22:57:33 -0300 4961) # Pick up the preceding and succeeding characters.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4962) my $ca = substr($opline, 0, $off);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4963) my $cc = '';
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4964) if (length($opline) >= ($off + length($elements[$n + 1]))) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4965) $cc = substr($opline, $off + length($elements[$n + 1]));
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4966) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4967) my $cb = "$ca$;$cc";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4968)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4969) my $a = '';
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4970) $a = 'V' if ($elements[$n] ne '');
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4971) $a = 'W' if ($elements[$n] =~ /\s$/);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4972) $a = 'C' if ($elements[$n] =~ /$;$/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4973) $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4974) $a = 'O' if ($elements[$n] eq '');
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 4975) $a = 'E' if ($ca =~ /^\s*$/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4976)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4977) my $op = $elements[$n + 1];
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4978)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4979) my $c = '';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4980) if (defined $elements[$n + 2]) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4981) $c = 'V' if ($elements[$n + 2] ne '');
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4982) $c = 'W' if ($elements[$n + 2] =~ /^\s/);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 4983) $c = 'C' if ($elements[$n + 2] =~ /^$;/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4984) $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4985) $c = 'O' if ($elements[$n + 2] eq '');
8b1b33786b06a (Andy Whitcroft 2009-01-06 14:41:27 -0800 4986) $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4987) } else {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4988) $c = 'E';
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4989) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4990)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4991) my $ctx = "${a}x${c}";
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4992)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4993) my $at = "(ctx:$ctx)";
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 4994)
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4995) my $ptr = substr($blank, 0, $off) . "^";
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 4996) my $hereptr = "$hereline$ptr\n";
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 4997)
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 4998) # Pull out the value of this operator.
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 4999) my $op_type = substr($curr_values, $off + 1, 1);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5000)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5001) # Get the full operator variant.
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5002) my $opv = $op . substr($curr_vars, $off, 1);
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5003)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5004) # Ignore operators passed as parameters.
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5005) if ($op_type ne 'V' &&
d7fe8065ad891 (Sam Bobroff 2015-04-16 12:44:39 -0700 5006) $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5007)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5008) # # Ignore comments
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5009) # } elsif ($op =~ /^$;+$/) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5010)
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5011) # ; should have either the end of line or a space or \ after it
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5012) } elsif ($op eq ';') {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5013) if ($ctx !~ /.x[WEBC]/ &&
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5014) $cc !~ /^\\/ && $cc !~ /^;/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5015) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5016) "space required after that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5017) $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5018) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5019) }
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5020) }
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5021)
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5022) # // is a comment
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5023) } elsif ($op eq '//') {
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5024)
b00e48148e99a (Joe Perches 2014-04-03 14:49:33 -0700 5025) # : when part of a bitfield
b00e48148e99a (Joe Perches 2014-04-03 14:49:33 -0700 5026) } elsif ($opv eq ':B') {
b00e48148e99a (Joe Perches 2014-04-03 14:49:33 -0700 5027) # skip the bitfield test for now
b00e48148e99a (Joe Perches 2014-04-03 14:49:33 -0700 5028)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5029) # No spaces for:
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5030) # ->
b00e48148e99a (Joe Perches 2014-04-03 14:49:33 -0700 5031) } elsif ($op eq '->') {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 5032) if ($ctx =~ /Wx.|.xW/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5033) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5034) "spaces prohibited around that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5035) $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5036) if (defined $fix_elements[$n + 2]) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5037) $fix_elements[$n + 2] =~ s/^\s+//;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5038) }
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5039) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5040) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5041) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5042)
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5043) # , must not have a space before and must have a space on the right.
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5044) } elsif ($op eq ',') {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5045) my $rtrim_before = 0;
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5046) my $space_after = 0;
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5047) if ($ctx =~ /Wx./) {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5048) if (ERROR("SPACING",
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5049) "space prohibited before that '$op' $at\n" . $hereptr)) {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5050) $line_fixed = 1;
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5051) $rtrim_before = 1;
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5052) }
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5053) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5054) if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5055) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5056) "space required after that '$op' $at\n" . $hereptr)) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5057) $line_fixed = 1;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5058) $last_after = $n;
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5059) $space_after = 1;
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5060) }
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5061) }
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5062) if ($rtrim_before || $space_after) {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5063) if ($rtrim_before) {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5064) $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5065) } else {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5066) $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5067) }
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5068) if ($space_after) {
2381097b6c9b8 (Joe Perches 2014-12-10 15:51:32 -0800 5069) $good .= " ";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5070) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5071) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5072)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5073) # '*' as part of a type definition -- reported already.
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5074) } elsif ($opv eq '*_') {
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5075) #warn "'*' is part of type\n";
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5076)
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5077) # unary operators should have a space before and
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5078) # none after. May be left adjacent to another
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5079) # unary operator, or a cast
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5080) } elsif ($op eq '!' || $op eq '~' ||
74048ed811152 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5081) $opv eq '*U' || $opv eq '-U' ||
0d413866c7df6 (Andy Whitcroft 2008-10-15 22:02:16 -0700 5082) $opv eq '&U' || $opv eq '&&U') {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5083) if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5084) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5085) "space required before that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5086) if ($n != $last_after + 2) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5087) $good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5088) $line_fixed = 1;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5089) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5090) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5091) }
a3340b3578797 (Andy Whitcroft 2009-02-27 14:03:07 -0800 5092) if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 5093) # A unary '*' may be const
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 5094)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 5095) } elsif ($ctx =~ /.xW/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5096) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5097) "space prohibited after that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5098) $good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5099) if (defined $fix_elements[$n + 2]) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5100) $fix_elements[$n + 2] =~ s/^\s+//;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5101) }
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5102) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5103) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5104) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5105)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5106) # unary ++ and unary -- are allowed no space on one side.
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5107) } elsif ($op eq '++' or $op eq '--') {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5108) if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5109) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5110) "space required one side of that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5111) $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5112) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5113) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5114) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5115) if ($ctx =~ /Wx[BE]/ ||
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5116) ($ctx =~ /Wx./ && $cc =~ /^;/)) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5117) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5118) "space prohibited before that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5119) $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5120) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5121) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5122) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5123) if ($ctx =~ /ExW/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5124) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5125) "space prohibited after that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5126) $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5127) if (defined $fix_elements[$n + 2]) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5128) $fix_elements[$n + 2] =~ s/^\s+//;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5129) }
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5130) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5131) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 5132) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5133)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5134) # << and >> may either have or not have spaces both sides
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5135) } elsif ($op eq '<<' or $op eq '>>' or
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5136) $op eq '&' or $op eq '^' or $op eq '|' or
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5137) $op eq '+' or $op eq '-' or
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5138) $op eq '*' or $op eq '/' or
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5139) $op eq '%')
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5140) {
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5141) if ($check) {
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5142) if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5143) if (CHK("SPACING",
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5144) "spaces preferred around that '$op' $at\n" . $hereptr)) {
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5145) $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5146) $fix_elements[$n + 2] =~ s/^\s+//;
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5147) $line_fixed = 1;
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5148) }
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5149) } elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5150) if (CHK("SPACING",
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5151) "space preferred before that '$op' $at\n" . $hereptr)) {
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5152) $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5153) $line_fixed = 1;
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5154) }
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5155) }
d2e025f364369 (Joe Perches 2015-02-13 14:38:57 -0800 5156) } elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5157) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5158) "need consistent spacing around '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5159) $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5160) if (defined $fix_elements[$n + 2]) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5161) $fix_elements[$n + 2] =~ s/^\s+//;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5162) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5163) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5164) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5165) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5166)
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5167) # A colon needs no spaces before when it is
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5168) # terminating a case value or a label.
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5169) } elsif ($opv eq ':C' || $opv eq ':L') {
263afd39c06f5 (Chris Down 2021-02-25 17:22:04 -0800 5170) if ($ctx =~ /Wx./ and $realfile !~ m@.*\.lds\.h$@) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5171) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5172) "space prohibited before that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5173) $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5174) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5175) }
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5176) }
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5177)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5178) # All the others need spaces both sides.
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5179) } elsif ($ctx !~ /[EWC]x[CWE]/) {
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5180) my $ok = 0;
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5181)
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5182) # Ignore email addresses <foo@bar>
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5183) if (($op eq '<' &&
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5184) $cc =~ /^\S+\@\S+>/) ||
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5185) ($op eq '>' &&
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5186) $ca =~ /<\S+\@\S+$/))
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5187) {
342d3d2f13683 (Antonio Borneo 2020-04-06 20:11:01 -0700 5188) $ok = 1;
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5189) }
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5190)
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5191) # for asm volatile statements
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5192) # ignore a colon with another
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5193) # colon immediately before or after
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5194) if (($op eq ':') &&
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5195) ($ca =~ /:$/ || $cc =~ /^:/)) {
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5196) $ok = 1;
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5197) }
e0df7e1faebad (Joe Perches 2015-04-16 12:44:53 -0700 5198)
847316231c2f8 (Joe Perches 2013-11-12 15:10:05 -0800 5199) # messages are ERROR, but ?: are CHK
1f65f947a6a87 (Andy Whitcroft 2008-07-23 21:29:10 -0700 5200) if ($ok == 0) {
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 5201) my $msg_level = \&ERROR;
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 5202) $msg_level = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
847316231c2f8 (Joe Perches 2013-11-12 15:10:05 -0800 5203)
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 5204) if (&{$msg_level}("SPACING",
0675a8fbd71c1 (Jean Delvare 2017-09-08 16:16:07 -0700 5205) "spaces required around that '$op' $at\n" . $hereptr)) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5206) $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5207) if (defined $fix_elements[$n + 2]) {
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5208) $fix_elements[$n + 2] =~ s/^\s+//;
b34c648bb33ca (Joe Perches 2013-09-11 14:24:01 -0700 5209) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5210) $line_fixed = 1;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5211) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5212) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5213) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 5214) $off += length($elements[$n + 1]);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5215)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5216) ## print("n: <$n> GOOD: <$good>\n");
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5217)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5218) $fixed_line = $fixed_line . $good;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5219) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5220)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5221) if (($#elements % 2) == 0) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5222) $fixed_line = $fixed_line . $fix_elements[$#elements];
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5223) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5224)
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5225) if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5226) $fixed[$fixlinenr] = $fixed_line;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5227) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5228)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5229)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5230) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5231)
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5232) # check for whitespace before a non-naked semicolon
d2e248e7b0068 (Joe Perches 2014-01-23 15:54:41 -0800 5233) if ($line =~ /^\+.*\S\s+;\s*$/) {
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5234) if (WARN("SPACING",
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5235) "space prohibited before semicolon\n" . $herecurr) &&
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5236) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5237) 1 while $fixed[$fixlinenr] =~
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5238) s/^(\+.*\S)\s+;/$1;/;
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5239) }
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5240) }
786b632622800 (Joe Perches 2013-07-03 15:05:32 -0700 5241)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 5242) # check for multiple assignments
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 5243) if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5244) CHK("MULTIPLE_ASSIGNMENTS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5245) "multiple assignments should be avoided\n" . $herecurr);
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 5246) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 5247)
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5248) ## # check for multiple declarations, allowing for a function declaration
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5249) ## # continuation.
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5250) ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5251) ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5252) ##
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5253) ## # Remove any bracketed sections to ensure we do not
e73d27159400f (Dwaipayan Ray 2020-12-15 20:44:56 -0800 5254) ## # falsely report the parameters of functions.
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5255) ## my $ln = $line;
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5256) ## while ($ln =~ s/\([^\(\)]*\)//g) {
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5257) ## }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5258) ## if ($ln =~ /,/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5259) ## WARN("MULTIPLE_DECLARATION",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5260) ## "declaring multiple variables together should be avoided\n" . $herecurr);
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5261) ## }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5262) ## }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 5263)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5264) #need space before brace following if, while, etc
6b8c69e4384b0 (Geyslan G. Bem 2016-03-15 14:58:09 -0700 5265) if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
6ad724e2a48fc (Michal Zylowski 2018-08-21 21:58:08 -0700 5266) $line =~ /\b(?:else|do)\{/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5267) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5268) "space required before the open brace '{'\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5269) $fix) {
6ad724e2a48fc (Michal Zylowski 2018-08-21 21:58:08 -0700 5270) $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5271) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 5272) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 5273)
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5274) ## # check for blank lines before declarations
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5275) ## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5276) ## $prevrawline =~ /^.\s*$/) {
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5277) ## WARN("SPACING",
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5278) ## "No blank lines before declarations\n" . $hereprev);
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5279) ## }
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5280) ##
c4a62ef9102bf (Joe Perches 2013-07-03 15:05:28 -0700 5281)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 5282) # closing brace should have a space following it when it has anything
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 5283) # on the line
94fb98450456d (Joe Perches 2019-09-25 16:46:47 -0700 5284) if ($line =~ /}(?!(?:,|;|\)|\}))\S/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5285) if (ERROR("SPACING",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5286) "space required after that close brace '}'\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5287) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5288) $fixed[$fixlinenr] =~
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5289) s/}((?!(?:,|;|\)))\S)/} $1/;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5290) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5291) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5292)
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5293) # check spacing on square brackets
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5294) if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5295) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5296) "space prohibited after that open square bracket '['\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5297) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5298) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5299) s/\[\s+/\[/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5300) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5301) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5302) if ($line =~ /\s\]/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5303) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5304) "space prohibited before that close square bracket ']'\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5305) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5306) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5307) s/\s+\]/\]/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5308) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5309) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5310)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5311) # check spacing on parentheses
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5312) if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 5313) $line !~ /for\s*\(\s+;/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5314) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5315) "space prohibited after that open parenthesis '('\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5316) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5317) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5318) s/\(\s+/\(/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5319) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5320) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5321) if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5322) $line !~ /for\s*\(.*;\s+\)/ &&
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5323) $line !~ /:\s+\)/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5324) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5325) "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5326) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5327) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5328) s/\s+\)/\)/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5329) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5330) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 5331)
e2826fd07029e (Joe Perches 2014-08-06 16:10:48 -0700 5332) # check unnecessary parentheses around addressof/dereference single $Lvals
e2826fd07029e (Joe Perches 2014-08-06 16:10:48 -0700 5333) # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
e2826fd07029e (Joe Perches 2014-08-06 16:10:48 -0700 5334)
e2826fd07029e (Joe Perches 2014-08-06 16:10:48 -0700 5335) while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5336) my $var = $1;
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5337) if (CHK("UNNECESSARY_PARENTHESES",
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5338) "Unnecessary parentheses around $var\n" . $herecurr) &&
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5339) $fix) {
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5340) $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5341) }
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5342) }
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5343)
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5344) # check for unnecessary parentheses around function pointer uses
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5345) # ie: (foo->bar)(); should be foo->bar();
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5346) # but not "if (foo->bar) (" to avoid some false positives
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5347) if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5348) my $var = $2;
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5349) if (CHK("UNNECESSARY_PARENTHESES",
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5350) "Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5351) $fix) {
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5352) my $var2 = deparenthesize($var);
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5353) $var2 =~ s/\s//g;
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5354) $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5355) }
ea4acbb11e32a (Joe Perches 2014-12-10 15:51:51 -0800 5356) }
e2826fd07029e (Joe Perches 2014-08-06 16:10:48 -0700 5357)
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5358) # check for unnecessary parentheses around comparisons in if uses
a032aa4c4a54c (Joe Perches 2018-02-06 15:39:03 -0800 5359) # when !drivers/staging or command-line uses --strict
a032aa4c4a54c (Joe Perches 2018-02-06 15:39:03 -0800 5360) if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 5361) $perl_version_ok && defined($stat) &&
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5362) $stat =~ /(^.\s*if\s*($balanced_parens))/) {
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5363) my $if_stat = $1;
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5364) my $test = substr($2, 1, -1);
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5365) my $herectx;
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5366) while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5367) my $match = $1;
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5368) # avoid parentheses around potential macro args
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5369) next if ($match =~ /^\s*\w+\s*$/);
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5370) if (!defined($herectx)) {
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5371) $herectx = $here . "\n";
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5372) my $cnt = statement_rawlines($if_stat);
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5373) for (my $n = 0; $n < $cnt; $n++) {
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5374) my $rl = raw_line($linenr, $n);
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5375) $herectx .= $rl . "\n";
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5376) last if $rl =~ /^[ \+].*\{/;
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5377) }
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5378) }
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5379) CHK("UNNECESSARY_PARENTHESES",
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5380) "Unnecessary parentheses around '$match'\n" . $herectx);
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5381) }
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5382) }
63b7c73ec86b8 (Joe Perches 2017-09-08 16:16:01 -0700 5383)
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5384) # check that goto labels aren't indented (allow a single space indentation)
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5385) # and ignore bitfield definitions like foo:1
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5386) # Strictly, labels can have whitespace after the identifier and before the :
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5387) # but this is not allowed here as many ?: uses would appear to be labels
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5388) if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5389) $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
690786511b32b (Joe Perches 2021-06-30 18:56:22 -0700 5390) $sline !~ /^.\s+default:/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5391) if (WARN("INDENTED_LABEL",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5392) "labels should not be indented\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5393) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5394) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5395) s/^(.)\s+/$1/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5396) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5397) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5398)
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5399) # check if a statement with a comma should be two statements like:
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5400) # foo = bar(), /* comma should be semicolon */
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5401) # bar = baz();
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5402) if (defined($stat) &&
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5403) $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) {
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5404) my $cnt = statement_rawlines($stat);
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5405) my $herectx = get_stat_here($linenr, $cnt, $here);
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5406) WARN("SUSPECT_COMMA_SEMICOLON",
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5407) "Possible comma where semicolon could be used\n" . $herectx);
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5408) }
40873aba2c6b9 (Joe Perches 2020-10-15 20:11:56 -0700 5409)
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5410) # return is not a function
507e51418ca0c (Joe Perches 2013-11-12 15:10:13 -0800 5411) if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5412) my $spacing = $1;
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 5413) if ($perl_version_ok &&
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5414) $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5415) my $value = $1;
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5416) $value = deparenthesize($value);
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5417) if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5418) ERROR("RETURN_PARENTHESES",
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5419) "return is not a function, parentheses are not required\n" . $herecurr);
5b9553abfc97f (Joe Perches 2014-04-03 14:49:21 -0700 5420) }
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5421) } elsif ($spacing !~ /\s+/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5422) ERROR("SPACING",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5423) "space required before the open parenthesis '('\n" . $herecurr);
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5424) }
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5425) }
507e51418ca0c (Joe Perches 2013-11-12 15:10:13 -0800 5426)
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5427) # unnecessary return in a void function
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5428) # at end-of-function, with the previous line a single leading tab, then return;
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5429) # and the line before that not a goto label target like "out:"
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5430) if ($sline =~ /^[ \+]}\s*$/ &&
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5431) $prevline =~ /^\+\treturn\s*;\s*$/ &&
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5432) $linenr >= 3 &&
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5433) $lines[$linenr - 3] =~ /^[ +]/ &&
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5434) $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
9819cf252a0fa (Joe Perches 2014-06-04 16:12:09 -0700 5435) WARN("RETURN_VOID",
b43ae21bd1d81 (Joe Perches 2014-06-23 13:22:07 -0700 5436) "void function return statements are not generally useful\n" . $hereprev);
ea7dbab3e5054 (Dwaipayan Ray 2021-02-25 17:21:47 -0800 5437) }
9819cf252a0fa (Joe Perches 2014-06-04 16:12:09 -0700 5438)
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5439) # if statements using unnecessary parentheses - ie: if ((foo == bar))
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 5440) if ($perl_version_ok &&
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5441) $line =~ /\bif\s*((?:\(\s*){2,})/) {
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5442) my $openparens = $1;
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5443) my $count = $openparens =~ tr@\(@\(@;
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5444) my $msg = "";
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5445) if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5446) my $comp = $4; #Not $1 because of $LvalOrFunc
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5447) $msg = " - maybe == should be = ?" if ($comp eq "==");
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5448) WARN("UNNECESSARY_PARENTHESES",
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5449) "Unnecessary parentheses$msg\n" . $herecurr);
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5450) }
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5451) }
189248d8f4f3a (Joe Perches 2014-01-23 15:54:47 -0800 5452)
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5453) # comparisons with a constant or upper case identifier on the left
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5454) # avoid cases like "foo + BAR < baz"
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5455) # only fix matches surrounded by parentheses to avoid incorrect
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5456) # conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 5457) if ($perl_version_ok &&
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5458) $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5459) my $lead = $1;
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5460) my $const = $2;
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5461) my $comp = $3;
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5462) my $to = $4;
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5463) my $newcomp = $comp;
f39e1769bbfc4 (Joe Perches 2016-05-20 17:04:02 -0700 5464) if ($lead !~ /(?:$Operators|\.)\s*$/ &&
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5465) $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5466) WARN("CONSTANT_COMPARISON",
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5467) "Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5468) $fix) {
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5469) if ($comp eq "<") {
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5470) $newcomp = ">";
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5471) } elsif ($comp eq "<=") {
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5472) $newcomp = ">=";
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5473) } elsif ($comp eq ">") {
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5474) $newcomp = "<";
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5475) } elsif ($comp eq ">=") {
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5476) $newcomp = "<=";
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5477) }
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5478) $fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5479) }
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5480) }
c5595fa2f1ce3 (Joe Perches 2015-09-09 15:37:58 -0700 5481)
f34e4a4f979c0 (Joe Perches 2015-04-16 12:44:19 -0700 5482) # Return of what appears to be an errno should normally be negative
f34e4a4f979c0 (Joe Perches 2015-04-16 12:44:19 -0700 5483) if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
53a3c4487a05b (Andy Whitcroft 2010-10-26 14:23:14 -0700 5484) my $name = $1;
46b85bf967142 (Guenter Roeck 2021-06-30 18:56:25 -0700 5485) if ($name ne 'EOF' && $name ne 'ERROR' && $name !~ /^EPOLL/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5486) WARN("USE_NEGATIVE_ERRNO",
f34e4a4f979c0 (Joe Perches 2015-04-16 12:44:19 -0700 5487) "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
53a3c4487a05b (Andy Whitcroft 2010-10-26 14:23:14 -0700 5488) }
53a3c4487a05b (Andy Whitcroft 2010-10-26 14:23:14 -0700 5489) }
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5490)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5491) # Need a space before open parenthesis after if, while etc
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5492) if ($line =~ /\b(if|while|for|switch)\(/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5493) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5494) "space required before the open parenthesis '('\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5495) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5496) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5497) s/\b(if|while|for|switch)\(/$1 \(/;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 5498) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5499) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5500)
f5fe35dd95549 (Andy Whitcroft 2008-07-23 21:29:03 -0700 5501) # Check for illegal assignment in if conditional -- and check for trailing
f5fe35dd95549 (Andy Whitcroft 2008-07-23 21:29:03 -0700 5502) # statements after the conditional.
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5503) if ($line =~ /do\s*(?!{)/) {
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 5504) ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 5505) ctx_statement_block($linenr, $realcnt, 0)
3e469cdc08ac5 (Andy Whitcroft 2012-01-10 15:10:01 -0800 5506) if (!defined $stat);
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5507) my ($stat_next) = ctx_statement_block($line_nr_next,
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5508) $remain_next, $off_next);
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5509) $stat_next =~ s/\n./\n /g;
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5510) ##print "stat<$stat> stat_next<$stat_next>\n";
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5511)
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5512) if ($stat_next =~ /^\s*while\b/) {
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5513) # If the statement carries leading newlines,
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5514) # then count those as offsets.
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5515) my ($whitespace) =
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5516) ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5517) my $offset =
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5518) statement_rawlines($whitespace) - 1;
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5519)
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5520) $suppress_whiletrailers{$line_nr_next +
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5521) $offset} = 1;
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5522) }
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5523) }
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5524) if (!defined $suppress_whiletrailers{$linenr} &&
c11230f44b3c3 (Joe Perches 2013-11-21 14:31:57 -0800 5525) defined($stat) && defined($cond) &&
170d3a22688f0 (Andy Whitcroft 2008-10-15 22:02:30 -0700 5526) $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 5527) my ($s, $c) = ($stat, $cond);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5528)
b53c8e104ed07 (Andy Whitcroft 2009-01-06 14:41:29 -0800 5529) if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5530) if (ERROR("ASSIGN_IN_IF",
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5531) "do not use assignment in if condition\n" . $herecurr) &&
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5532) $fix && $perl_version_ok) {
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5533) if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) {
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5534) my $space = $1;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5535) my $not = $2;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5536) my $statement = $3;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5537) my $assigned = $4;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5538) my $test = $8;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5539) my $against = $9;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5540) my $brace = $15;
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5541) fix_delete_line($fixlinenr, $rawline);
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5542) fix_insert_line($fixlinenr, "$space$statement;");
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5543) my $newline = "${space}if (";
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5544) $newline .= '!' if defined($not);
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5545) $newline .= '(' if (defined $not && defined($test) && defined($against));
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5546) $newline .= "$assigned";
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5547) $newline .= " $test $against" if (defined($test) && defined($against));
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5548) $newline .= ')' if (defined $not && defined($test) && defined($against));
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5549) $newline .= ')';
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5550) $newline .= " {" if (defined($brace));
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5551) fix_insert_line($fixlinenr + 1, $newline);
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5552) }
65b64b3bec3fa (Joe Perches 2020-08-11 18:35:10 -0700 5553) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5554) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5555)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5556) # Find out what is on the end of the line after the
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5557) # conditional.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5558) substr($s, 0, length($c), '');
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5559) $s =~ s/\n.*//g;
342d3d2f13683 (Antonio Borneo 2020-04-06 20:11:01 -0700 5560) $s =~ s/$;//g; # Remove any comments
53210168feeff (Andy Whitcroft 2008-07-23 21:29:03 -0700 5561) if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
53210168feeff (Andy Whitcroft 2008-07-23 21:29:03 -0700 5562) $c !~ /}\s*while\s*/)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5563) {
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5564) # Find out how long the conditional actually is.
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5565) my @newlines = ($c =~ /\n/gs);
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5566) my $cond_lines = 1 + $#newlines;
42bdf74c95b69 (Hidetoshi Seto 2010-03-05 13:43:50 -0800 5567) my $stat_real = '';
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5568)
42bdf74c95b69 (Hidetoshi Seto 2010-03-05 13:43:50 -0800 5569) $stat_real = raw_line($linenr, $cond_lines)
42bdf74c95b69 (Hidetoshi Seto 2010-03-05 13:43:50 -0800 5570) . "\n" if ($cond_lines);
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5571) if (defined($stat_real) && $cond_lines > 1) {
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5572) $stat_real = "[...]\n$stat_real";
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5573) }
bb44ad39c8864 (Andy Whitcroft 2008-10-15 22:02:34 -0700 5574)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5575) ERROR("TRAILING_STATEMENTS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5576) "trailing statements should be on next line\n" . $herecurr . $stat_real);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5577) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5578) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5579)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5580) # Check for bitwise tests written as boolean
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5581) if ($line =~ /
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5582) (?:
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5583) (?:\[|\(|\&\&|\|\|)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5584) \s*0[xX][0-9]+\s*
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5585) (?:\&\&|\|\|)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5586) |
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5587) (?:\&\&|\|\|)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5588) \s*0[xX][0-9]+\s*
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5589) (?:\&\&|\|\||\)|\])
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5590) )/x)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5591) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5592) WARN("HEXADECIMAL_BOOLEAN_TEST",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5593) "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5594) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5595)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 5596) # if and else should not have general statements after it
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5597) if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5598) my $s = $1;
342d3d2f13683 (Antonio Borneo 2020-04-06 20:11:01 -0700 5599) $s =~ s/$;//g; # Remove any comments
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5600) if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5601) ERROR("TRAILING_STATEMENTS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5602) "trailing statements should be on next line\n" . $herecurr);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5603) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5604) }
39667782362be (Andy Whitcroft 2009-01-15 13:51:06 -0800 5605) # if should not continue a brace
39667782362be (Andy Whitcroft 2009-01-15 13:51:06 -0800 5606) if ($line =~ /}\s*if\b/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5607) ERROR("TRAILING_STATEMENTS",
048b123fad06f (Rasmus Villemoes 2014-08-06 16:10:37 -0700 5608) "trailing statements should be on next line (or did you mean 'else if'?)\n" .
39667782362be (Andy Whitcroft 2009-01-15 13:51:06 -0800 5609) $herecurr);
39667782362be (Andy Whitcroft 2009-01-15 13:51:06 -0800 5610) }
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5611) # case and default should not have general statements after them
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5612) if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5613) $line !~ /\G(?:
3fef12d6cb832 (Andy Whitcroft 2008-10-15 22:02:36 -0700 5614) (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5615) \s*return\s+
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5616) )/xg)
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5617) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5618) ERROR("TRAILING_STATEMENTS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5619) "trailing statements should be on next line\n" . $herecurr);
a1080bf80862c (Andy Whitcroft 2008-10-15 22:02:25 -0700 5620) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5621)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5622) # Check for }<nl>else {, these must be at the same
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5623) # indent level to be relevant to each other.
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5624) if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5625) $previndent == $indent) {
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5626) if (ERROR("ELSE_AFTER_BRACE",
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5627) "else should follow close brace '}'\n" . $hereprev) &&
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5628) $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5629) fix_delete_line($fixlinenr - 1, $prevrawline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5630) fix_delete_line($fixlinenr, $rawline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5631) my $fixedline = $prevrawline;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5632) $fixedline =~ s/}\s*$//;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5633) if ($fixedline !~ /^\+\s*$/) {
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5634) fix_insert_line($fixlinenr, $fixedline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5635) }
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5636) $fixedline = $rawline;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5637) $fixedline =~ s/^(.\s*)else/$1} else/;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5638) fix_insert_line($fixlinenr, $fixedline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5639) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5640) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5641)
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5642) if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5643) $previndent == $indent) {
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5644) my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5645)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5646) # Find out what is on the end of the line after the
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5647) # conditional.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5648) substr($s, 0, length($c), '');
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5649) $s =~ s/\n.*//g;
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5650)
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5651) if ($s =~ /^\s*;/) {
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5652) if (ERROR("WHILE_AFTER_BRACE",
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5653) "while should follow close brace '}'\n" . $hereprev) &&
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5654) $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5655) fix_delete_line($fixlinenr - 1, $prevrawline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5656) fix_delete_line($fixlinenr, $rawline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5657) my $fixedline = $prevrawline;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5658) my $trailing = $rawline;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5659) $trailing =~ s/^\+//;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5660) $trailing = trim($trailing);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5661) $fixedline =~ s/}\s*$/} $trailing/;
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5662) fix_insert_line($fixlinenr, $fixedline);
8b8856f4b102c (Joe Perches 2014-08-06 16:11:14 -0700 5663) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5664) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5665) }
c2fdda0dfbe85 (Andy Whitcroft 2008-02-08 04:20:54 -0800 5666)
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 5667) #Specific variable tests
323c1260ba2c4 (Joe Perches 2012-12-17 16:02:07 -0800 5668) while ($line =~ m{($Constant|$Lval)}g) {
323c1260ba2c4 (Joe Perches 2012-12-17 16:02:07 -0800 5669) my $var = $1;
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 5670)
95e2c6023b0e4 (Joe Perches 2013-07-03 15:05:20 -0700 5671) #CamelCase
807bd26c4c3e9 (Joe Perches 2013-07-03 15:05:22 -0700 5672) if ($var !~ /^$Constant$/ &&
be79794bc116f (Joe Perches 2013-07-03 15:05:20 -0700 5673) $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
4104a20646fe2 (Łukasz Stelmach 2020-12-15 20:44:27 -0800 5674) #Ignore some autogenerated defines and enum values
4104a20646fe2 (Łukasz Stelmach 2020-12-15 20:44:27 -0800 5675) $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
22735ce857a2d (Joe Perches 2013-07-03 15:05:33 -0700 5676) #Ignore Page<foo> variants
807bd26c4c3e9 (Joe Perches 2013-07-03 15:05:22 -0700 5677) $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
d439e6a5d78b9 (Joe Perches 2019-12-04 16:52:06 -0800 5678) #Ignore SI style variants like nS, mV and dB
d439e6a5d78b9 (Joe Perches 2019-12-04 16:52:06 -0800 5679) #(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
d439e6a5d78b9 (Joe Perches 2019-12-04 16:52:06 -0800 5680) $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
f512357646268 (Julius Werner 2014-12-10 15:51:54 -0800 5681) #Ignore some three character SI units explicitly, like MiB and KHz
f512357646268 (Julius Werner 2014-12-10 15:51:54 -0800 5682) $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5683) while ($var =~ m{($Ident)}g) {
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5684) my $word = $1;
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5685) next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5686) if ($check) {
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5687) seed_camelcase_includes();
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5688) if (!$file && !$camelcase_file_seeded) {
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5689) seed_camelcase_file($realfile);
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5690) $camelcase_file_seeded = 1;
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5691) }
d8b077101bcfb (Joe Perches 2013-11-12 15:10:06 -0800 5692) }
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5693) if (!defined $camelcase{$word}) {
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5694) $camelcase{$word} = 1;
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5695) CHK("CAMELCASE",
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5696) "Avoid CamelCase: <$word>\n" . $herecurr);
7e781f67df436 (Joe Perches 2013-09-11 14:23:55 -0700 5697) }
3445686af7215 (Joe Perches 2013-07-03 15:05:34 -0700 5698) }
323c1260ba2c4 (Joe Perches 2012-12-17 16:02:07 -0800 5699) }
323c1260ba2c4 (Joe Perches 2012-12-17 16:02:07 -0800 5700) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5701)
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5702) #no spaces allowed after \ in define
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5703) if ($line =~ /\#\s*define.*\\\s+$/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5704) if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5705) "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5706) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 5707) $fixed[$fixlinenr] =~ s/\s+$//;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 5708) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5709) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5710)
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5711) # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5712) # itself <asm/foo.h> (uses RAW line)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5713) if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
e09dec4831bbb (Andy Whitcroft 2008-10-15 22:02:20 -0700 5714) my $file = "$1.h";
e09dec4831bbb (Andy Whitcroft 2008-10-15 22:02:20 -0700 5715) my $checkfile = "include/linux/$file";
e09dec4831bbb (Andy Whitcroft 2008-10-15 22:02:20 -0700 5716) if (-f "$root/$checkfile" &&
e09dec4831bbb (Andy Whitcroft 2008-10-15 22:02:20 -0700 5717) $realfile ne $checkfile &&
7840a94cd1255 (Wolfram Sang 2010-08-09 17:20:57 -0700 5718) $1 !~ /$allowed_asm_includes/)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5719) {
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5720) my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5721) if ($asminclude > 0) {
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5722) if ($realfile =~ m{^arch/}) {
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5723) CHK("ARCH_INCLUDE_LINUX",
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5724) "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5725) } else {
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5726) WARN("INCLUDE_LINUX",
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5727) "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
0e212e0a72060 (Fabian Frederick 2015-04-16 12:44:25 -0700 5728) }
e09dec4831bbb (Andy Whitcroft 2008-10-15 22:02:20 -0700 5729) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5730) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5731) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5732)
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 5733) # multi-statement macros should be enclosed in a do while loop, grab the
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 5734) # first statement and ensure its the whole macro if its not enclosed
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5735) # in a known good container
b8f96a31f38c8 (Andy Whitcroft 2008-07-23 21:29:07 -0700 5736) if ($realfile !~ m@/vmlinux.lds.h$@ &&
b8f96a31f38c8 (Andy Whitcroft 2008-07-23 21:29:07 -0700 5737) $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5738) my $ln = $linenr;
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5739) my $cnt = $realcnt;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5740) my ($off, $dstat, $dcond, $rest);
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5741) my $ctx = '';
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5742) my $has_flow_statement = 0;
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5743) my $has_arg_concat = 0;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5744) ($dstat, $dcond, $ln, $cnt, $off) =
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5745) ctx_statement_block($linenr, $realcnt, 0);
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5746) $ctx = $dstat;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5747) #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
a3bb97a7aba36 (Andy Whitcroft 2008-07-23 21:29:00 -0700 5748) #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5749)
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5750) $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/);
62e15a6daab0f (Joe Perches 2016-01-20 14:59:18 -0800 5751) $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/);
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5752)
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5753) $dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//;
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5754) my $define_args = $1;
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5755) my $define_stmt = $dstat;
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5756) my @def_args = ();
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5757)
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5758) if (defined $define_args && $define_args ne "") {
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5759) $define_args = substr($define_args, 1, length($define_args) - 2);
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5760) $define_args =~ s/\s*//g;
8c8c45cfdd5d8 (Joe Perches 2018-08-21 21:57:43 -0700 5761) $define_args =~ s/\\\+?//g;
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5762) @def_args = split(",", $define_args);
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5763) }
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5764)
292f1a9b342d7 (Andy Whitcroft 2008-07-23 21:29:11 -0700 5765) $dstat =~ s/$;//g;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5766) $dstat =~ s/\\\n.//g;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5767) $dstat =~ s/^\s*//s;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5768) $dstat =~ s/\s*$//s;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 5769)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5770) # Flatten any parentheses and braces
2e44e8033a9bc (Dwaipayan Ray 2020-10-15 20:12:22 -0700 5771) while ($dstat =~ s/\([^\(\)]*\)/1u/ ||
2e44e8033a9bc (Dwaipayan Ray 2020-10-15 20:12:22 -0700 5772) $dstat =~ s/\{[^\{\}]*\}/1u/ ||
2e44e8033a9bc (Dwaipayan Ray 2020-10-15 20:12:22 -0700 5773) $dstat =~ s/.\[[^\[\]]*\]/1u/)
bf30d6ede099c (Andy Whitcroft 2008-10-15 22:02:33 -0700 5774) {
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 5775) }
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5776)
342d3d2f13683 (Antonio Borneo 2020-04-06 20:11:01 -0700 5777) # Flatten any obvious string concatenation.
33acb54a4379c (Joe Perches 2015-06-25 15:02:54 -0700 5778) while ($dstat =~ s/($String)\s*$Ident/$1/ ||
33acb54a4379c (Joe Perches 2015-06-25 15:02:54 -0700 5779) $dstat =~ s/$Ident\s*($String)/$1/)
e45bab8ebfee6 (Andy Whitcroft 2012-03-23 15:02:18 -0700 5780) {
e45bab8ebfee6 (Andy Whitcroft 2012-03-23 15:02:18 -0700 5781) }
e45bab8ebfee6 (Andy Whitcroft 2012-03-23 15:02:18 -0700 5782)
42e152931deba (Joe Perches 2016-03-15 14:58:01 -0700 5783) # Make asm volatile uses seem like a generic function
42e152931deba (Joe Perches 2016-03-15 14:58:01 -0700 5784) $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g;
42e152931deba (Joe Perches 2016-03-15 14:58:01 -0700 5785)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5786) my $exceptions = qr{
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5787) $Declare|
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5788) module_param_named|
a0a0a7a94c765 (Kees Cook 2012-10-04 17:13:38 -0700 5789) MODULE_PARM_DESC|
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5790) DECLARE_PER_CPU|
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5791) DEFINE_PER_CPU|
383099fd636de (Andy Whitcroft 2009-01-06 14:41:18 -0800 5792) __typeof__\(|
22fd2d3e4f75a (Stefani Seibold 2010-03-05 13:43:52 -0800 5793) union|
22fd2d3e4f75a (Stefani Seibold 2010-03-05 13:43:52 -0800 5794) struct|
ea71a0a019f91 (Andy Whitcroft 2009-09-21 17:04:38 -0700 5795) \.$Ident\s*=\s*|
6b10df4257367 (Vladimir Zapolskiy 2016-01-20 14:59:21 -0800 5796) ^\"|\"$|
6b10df4257367 (Vladimir Zapolskiy 2016-01-20 14:59:21 -0800 5797) ^\[
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 5798) }x;
5eaa20b984eb3 (Andy Whitcroft 2010-10-26 14:23:18 -0700 5799) #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5800)
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5801) $ctx =~ s/\n*$//;
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5802) my $stmt_cnt = statement_rawlines($ctx);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 5803) my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5804)
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5805) if ($dstat ne '' &&
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5806) $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5807) $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
3cc4b1c3f0d28 (Joe Perches 2013-07-03 15:05:27 -0700 5808) $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
356fd39813548 (Joe Perches 2014-08-06 16:10:31 -0700 5809) $dstat !~ /^'X'$/ && $dstat !~ /^'XX'$/ && # character constants
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5810) $dstat !~ /$exceptions/ &&
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5811) $dstat !~ /^\.$Ident\s*=/ && # .foo =
e942e2c3f7e09 (Joe Perches 2013-04-17 15:58:26 -0700 5812) $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
72f115f94d500 (Andy Whitcroft 2012-01-10 15:10:06 -0800 5813) $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
2e44e8033a9bc (Dwaipayan Ray 2020-10-15 20:12:22 -0700 5814) $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5815) $dstat !~ /^for\s*$Constant$/ && # for (...)
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5816) $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5817) $dstat !~ /^do\s*{/ && # do {...
4e5d56bdf892e (Eddie Kovsky 2015-09-09 15:37:52 -0700 5818) $dstat !~ /^\(\{/ && # ({...
f95a7e6a462ed (Joe Perches 2013-09-11 14:24:00 -0700 5819) $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5820) {
e795556a581a8 (Joe Perches 2017-05-08 15:55:48 -0700 5821) if ($dstat =~ /^\s*if\b/) {
e795556a581a8 (Joe Perches 2017-05-08 15:55:48 -0700 5822) ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
e795556a581a8 (Joe Perches 2017-05-08 15:55:48 -0700 5823) "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx");
e795556a581a8 (Joe Perches 2017-05-08 15:55:48 -0700 5824) } elsif ($dstat =~ /;/) {
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5825) ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5826) "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
f74bd1942e04a (Andy Whitcroft 2012-01-10 15:09:54 -0800 5827) } else {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 5828) ERROR("COMPLEX_MACRO",
388982b55e329 (Andrew Morton 2014-10-13 15:51:40 -0700 5829) "Macros with complex values should be enclosed in parentheses\n" . "$herectx");
d8aaf12142d06 (Andy Whitcroft 2007-06-23 17:16:44 -0700 5830) }
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5831)
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5832) }
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5833)
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5834) # Make $define_stmt single line, comment-free, etc
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5835) my @stmt_array = split('\n', $define_stmt);
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5836) my $first = 1;
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5837) $define_stmt = "";
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5838) foreach my $l (@stmt_array) {
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5839) $l =~ s/\\$//;
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5840) if ($first) {
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5841) $define_stmt = $l;
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5842) $first = 0;
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5843) } elsif ($l =~ /^[\+ ]/) {
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5844) $define_stmt .= substr($l, 1);
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5845) }
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5846) }
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5847) $define_stmt =~ s/$;//g;
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5848) $define_stmt =~ s/\s+/ /g;
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5849) $define_stmt = trim($define_stmt);
5207649b7b1d2 (Joe Perches 2016-10-11 13:52:14 -0700 5850)
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5851) # check if any macro arguments are reused (ignore '...' and 'type')
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5852) foreach my $arg (@def_args) {
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5853) next if ($arg =~ /\.\.\./);
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5854) next if ($arg =~ /^type$/i);
7fe528a27dee5 (Joe Perches 2017-07-10 15:52:27 -0700 5855) my $tmp_stmt = $define_stmt;
7b844345fc2a9 (Vincent Mailhol 2021-05-06 18:03:58 -0700 5856) $tmp_stmt =~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__stringify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
7fe528a27dee5 (Joe Perches 2017-07-10 15:52:27 -0700 5857) $tmp_stmt =~ s/\#+\s*$arg\b//g;
7fe528a27dee5 (Joe Perches 2017-07-10 15:52:27 -0700 5858) $tmp_stmt =~ s/\b$arg\s*\#\#//g;
d41362ed12b64 (Joe Perches 2018-05-25 14:48:04 -0700 5859) my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5860) if ($use_cnt > 1) {
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5861) CHK("MACRO_ARG_REUSE",
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5862) "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5863) }
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5864) # check if any macro arguments may have other precedence issues
7fe528a27dee5 (Joe Perches 2017-07-10 15:52:27 -0700 5865) if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5866) ((defined($1) && $1 ne ',') ||
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5867) (defined($2) && $2 ne ','))) {
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5868) CHK("MACRO_ARG_PRECEDENCE",
9192d41a3f0b9 (Joe Perches 2016-10-11 13:52:11 -0700 5869) "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx");
f59b64bffe163 (Joe Perches 2016-10-11 13:52:08 -0700 5870) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 5871) }
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5872)
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5873) # check for macros with flow control, but without ## concatenation
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5874) # ## concatenation is commonly a macro that defines a function so ignore those
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5875) if ($has_flow_statement && !$has_arg_concat) {
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5876) my $cnt = statement_rawlines($ctx);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 5877) my $herectx = get_stat_here($linenr, $cnt, $here);
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5878)
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5879) WARN("MACRO_WITH_FLOW_CONTROL",
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5880) "Macros with flow control statements should be avoided\n" . "$herectx");
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5881) }
08a2843e77fc5 (Joe Perches 2014-10-13 15:51:55 -0700 5882)
481eb486a88c9 (Joe Perches 2012-12-17 16:01:56 -0800 5883) # check for line continuations outside of #defines, preprocessor #, and asm
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5884)
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5885) } else {
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5886) if ($prevline !~ /^..*\\$/ &&
481eb486a88c9 (Joe Perches 2012-12-17 16:01:56 -0800 5887) $line !~ /^\+\s*\#.*\\$/ && # preprocessor
481eb486a88c9 (Joe Perches 2012-12-17 16:01:56 -0800 5888) $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ && # asm
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5889) $line =~ /^\+.*\\$/) {
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5890) WARN("LINE_CONTINUATIONS",
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5891) "Avoid unnecessary line continuations\n" . $herecurr);
5023d3472d444 (Joe Perches 2012-12-17 16:01:47 -0800 5892) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5893) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 5894)
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5895) # do {} while (0) macro tests:
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5896) # single-statement macros do not need to be enclosed in do while (0) loop,
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5897) # macro should not end with a semicolon
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 5898) if ($perl_version_ok &&
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5899) $realfile !~ m@/vmlinux.lds.h$@ &&
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5900) $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5901) my $ln = $linenr;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5902) my $cnt = $realcnt;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5903) my ($off, $dstat, $dcond, $rest);
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5904) my $ctx = '';
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5905) ($dstat, $dcond, $ln, $cnt, $off) =
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5906) ctx_statement_block($linenr, $realcnt, 0);
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5907) $ctx = $dstat;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5908)
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5909) $dstat =~ s/\\\n.//g;
1b36b201c081d (Joe Perches 2015-02-13 14:38:32 -0800 5910) $dstat =~ s/$;/ /g;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5911)
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5912) if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5913) my $stmts = $2;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5914) my $semis = $3;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5915)
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5916) $ctx =~ s/\n*$//;
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5917) my $cnt = statement_rawlines($ctx);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 5918) my $herectx = get_stat_here($linenr, $cnt, $here);
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5919)
ac8e97f8a7428 (Joe Perches 2012-08-21 16:15:53 -0700 5920) if (($stmts =~ tr/;/;/) == 1 &&
ac8e97f8a7428 (Joe Perches 2012-08-21 16:15:53 -0700 5921) $stmts !~ /^\s*(if|while|for|switch)\b/) {
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5922) WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5923) "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5924) }
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5925) if (defined $semis && $semis ne "") {
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5926) WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5927) "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5928) }
f5ef95b12eb03 (Joe Perches 2014-06-04 16:12:06 -0700 5929) } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
f5ef95b12eb03 (Joe Perches 2014-06-04 16:12:06 -0700 5930) $ctx =~ s/\n*$//;
f5ef95b12eb03 (Joe Perches 2014-06-04 16:12:06 -0700 5931) my $cnt = statement_rawlines($ctx);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 5932) my $herectx = get_stat_here($linenr, $cnt, $here);
f5ef95b12eb03 (Joe Perches 2014-06-04 16:12:06 -0700 5933)
f5ef95b12eb03 (Joe Perches 2014-06-04 16:12:06 -0700 5934) WARN("TRAILING_SEMICOLON",
f5ef95b12eb03 (Joe Perches 2014-06-04 16:12:06 -0700 5935) "macros should not use a trailing semicolon\n" . "$herectx");
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5936) }
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5937) }
b13edf7ff2dd0 (Joe Perches 2012-07-30 14:41:24 -0700 5938)
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 5939) # check for redundant bracing round if etc
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5940) if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5941) my ($level, $endln, @chunks) =
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5942) ctx_statement_full($linenr, $realcnt, 1);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5943) #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5944) #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5945) if ($#chunks > 0 && $level == 0) {
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5946) my @allowed = ();
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5947) my $allow = 0;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5948) my $seen = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5949) my $herectx = $here . "\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5950) my $ln = $linenr - 1;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5951) for my $chunk (@chunks) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5952) my ($cond, $block) = @{$chunk};
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5953)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5954) # If the condition carries leading newlines, then count those as offsets.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5955) my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5956) my $offset = statement_rawlines($whitespace) - 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5957)
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5958) $allowed[$allow] = 0;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5959) #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5960)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5961) # We have looked at and allowed this specific line.
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5962) $suppress_ifbraces{$ln + $offset} = 1;
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5963)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5964) $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5965) $ln += statement_rawlines($block) - 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5966)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 5967) substr($block, 0, length($cond), '');
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5968)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5969) $seen++ if ($block =~ /^\s*{/);
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5970)
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5971) #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5972) if (statement_lines($cond) > 1) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5973) #print "APW: ALLOWED: cond<$cond>\n";
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5974) $allowed[$allow] = 1;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5975) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5976) if ($block =~/\b(?:if|for|while)\b/) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5977) #print "APW: ALLOWED: block<$block>\n";
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5978) $allowed[$allow] = 1;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5979) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5980) if (statement_block_size($block) > 1) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 5981) #print "APW: ALLOWED: lines block<$block>\n";
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5982) $allowed[$allow] = 1;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5983) }
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5984) $allow++;
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5985) }
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5986) if ($seen) {
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5987) my $sum_allowed = 0;
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5988) foreach (@allowed) {
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5989) $sum_allowed += $_;
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5990) }
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5991) if ($sum_allowed == 0) {
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5992) WARN("BRACES",
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5993) "braces {} are not necessary for any arm of this statement\n" . $herectx);
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5994) } elsif ($sum_allowed != $allow &&
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5995) $seen != $allow) {
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5996) CHK("BRACES",
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5997) "braces {} should be used on all arms of this statement\n" . $herectx);
aad4f61498314 (Joe Perches 2012-03-23 15:02:19 -0700 5998) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 5999) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 6000) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 6001) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6002) if (!defined $suppress_ifbraces{$linenr - 1} &&
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 6003) $line =~ /\b(if|while|for|else)\b/) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6004) my $allowed = 0;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6005)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6006) # Check the pre-context.
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6007) if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6008) #print "APW: ALLOWED: pre<$1>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6009) $allowed = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6010) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6011)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6012) my ($level, $endln, @chunks) =
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6013) ctx_statement_full($linenr, $realcnt, $-[0]);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6014)
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6015) # Check the condition.
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6016) my ($cond, $block) = @{$chunks[0]};
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6017) #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6018) if (defined $cond) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6019) substr($block, 0, length($cond), '');
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6020) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6021) if (statement_lines($cond) > 1) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6022) #print "APW: ALLOWED: cond<$cond>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6023) $allowed = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6024) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6025) if ($block =~/\b(?:if|for|while)\b/) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6026) #print "APW: ALLOWED: block<$block>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6027) $allowed = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6028) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6029) if (statement_block_size($block) > 1) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6030) #print "APW: ALLOWED: lines block<$block>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6031) $allowed = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6032) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6033) # Check the post-context.
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6034) if (defined $chunks[1]) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6035) my ($cond, $block) = @{$chunks[1]};
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6036) if (defined $cond) {
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 6037) substr($block, 0, length($cond), '');
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6038) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6039) if ($block =~ /^\s*\{/) {
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6040) #print "APW: ALLOWED: chunk-1 block<$block>\n";
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6041) $allowed = 1;
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6042) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6043) }
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6044) if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
f055663c5853a (Andy Whitcroft 2008-10-15 22:02:23 -0700 6045) my $cnt = statement_rawlines($block);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 6046) my $herectx = get_stat_here($linenr, $cnt, $here);
cf655043d4ba6 (Andy Whitcroft 2008-03-04 14:28:20 -0800 6047)
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6048) WARN("BRACES",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6049) "braces {} are not necessary for single statement blocks\n" . $herectx);
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 6050) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 6051) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 6052)
e4c5babd32f97 (Joe Perches 2017-02-24 15:01:41 -0800 6053) # check for single line unbalanced braces
95330473636e5 (Sven Eckelmann 2017-02-24 15:01:43 -0800 6054) if ($sline =~ /^.\s*\}\s*else\s*$/ ||
95330473636e5 (Sven Eckelmann 2017-02-24 15:01:43 -0800 6055) $sline =~ /^.\s*else\s*\{\s*$/) {
e4c5babd32f97 (Joe Perches 2017-02-24 15:01:41 -0800 6056) CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
e4c5babd32f97 (Joe Perches 2017-02-24 15:01:41 -0800 6057) }
e4c5babd32f97 (Joe Perches 2017-02-24 15:01:41 -0800 6058)
0979ae66464bd (Joe Perches 2012-12-17 16:01:59 -0800 6059) # check for unnecessary blank lines around braces
77b9a53a62749 (Joe Perches 2013-07-03 15:05:29 -0700 6060) if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6061) if (CHK("BRACES",
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6062) "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6063) $fix && $prevrawline =~ /^\+/) {
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6064) fix_delete_line($fixlinenr - 1, $prevrawline);
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6065) }
0979ae66464bd (Joe Perches 2012-12-17 16:01:59 -0800 6066) }
77b9a53a62749 (Joe Perches 2013-07-03 15:05:29 -0700 6067) if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6068) if (CHK("BRACES",
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6069) "Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6070) $fix) {
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6071) fix_delete_line($fixlinenr, $rawline);
f8e58219dc58c (Joe Perches 2015-02-13 14:38:46 -0800 6072) }
0979ae66464bd (Joe Perches 2012-12-17 16:01:59 -0800 6073) }
0979ae66464bd (Joe Perches 2012-12-17 16:01:59 -0800 6074)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6075) # no volatiles please
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 6076) my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
6c72ffaab9851 (Andy Whitcroft 2007-10-18 03:05:08 -0700 6077) if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6078) WARN("VOLATILE",
8c27ceff3604b (Mauro Carvalho Chehab 2016-10-18 10:12:27 -0200 6079) "Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . $herecurr);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6080) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6081)
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6082) # Check for user-visible strings broken across lines, which breaks the ability
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6083) # to grep for the string. Make exceptions when the previous string ends in a
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6084) # newline (multiple lines in one string constant) or '\t', '\r', ';', or '{'
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6085) # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
33acb54a4379c (Joe Perches 2015-06-25 15:02:54 -0700 6086) if ($line =~ /^\+\s*$String/ &&
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6087) $prevline =~ /"\s*$/ &&
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6088) $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6089) if (WARN("SPLIT_STRING",
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6090) "quoted string split across lines\n" . $hereprev) &&
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6091) $fix &&
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6092) $prevrawline =~ /^\+.*"\s*$/ &&
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6093) $last_coalesced_string_linenr != $linenr - 1) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6094) my $extracted_string = get_quoted_string($line, $rawline);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6095) my $comma_close = "";
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6096) if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6097) $comma_close = $1;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6098) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6099)
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6100) fix_delete_line($fixlinenr - 1, $prevrawline);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6101) fix_delete_line($fixlinenr, $rawline);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6102) my $fixedline = $prevrawline;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6103) $fixedline =~ s/"\s*$//;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6104) $fixedline .= substr($extracted_string, 1) . trim($comma_close);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6105) fix_insert_line($fixlinenr - 1, $fixedline);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6106) $fixedline = $rawline;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6107) $fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6108) if ($fixedline !~ /\+\s*$/) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6109) fix_insert_line($fixlinenr, $fixedline);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6110) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6111) $last_coalesced_string_linenr = $linenr;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6112) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6113) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6114)
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6115) # check for missing a space in a string concatenation
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6116) if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6117) WARN('MISSING_SPACE',
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6118) "break quoted strings at a space character\n" . $hereprev);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6119) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6120)
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6121) # check for an embedded function name in a string when the function is known
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6122) # This does not work very well for -f --file checking as it depends on patch
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6123) # context providing the function name or a single line form for in-file
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6124) # function declarations
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 6125) if ($line =~ /^\+.*$String/ &&
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 6126) defined($context_function) &&
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6127) get_quoted_string($line, $rawline) =~ /\b$context_function\b/ &&
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6128) length(get_quoted_string($line, $rawline)) != (length($context_function) + 2)) {
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 6129) WARN("EMBEDDED_FUNCTION_NAME",
e4b7d3091def8 (Joe Perches 2017-05-08 15:55:51 -0700 6130) "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 6131) }
77cb8546bcd73 (Joe Perches 2017-02-24 15:01:28 -0800 6132)
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6133) # check for unnecessary function tracing like uses
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6134) # This does not use $logFunctions because there are many instances like
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6135) # 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6136) if ($rawline =~ /^\+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s*__func__\s*\)\s*;/) {
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6137) if (WARN("TRACING_LOGGING",
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6138) "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6139) $fix) {
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6140) fix_delete_line($fixlinenr, $rawline);
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6141) }
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6142) }
adb2da82fcf99 (Joe Perches 2021-02-25 17:21:50 -0800 6143)
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6144) # check for spaces before a quoted newline
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6145) if ($rawline =~ /^.*\".*\s\\n/) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6146) if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6147) "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6148) $fix) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6149) $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6150) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6151)
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6152) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6153)
f17dba4fc0496 (Joe Perches 2014-10-13 15:51:51 -0700 6154) # concatenated string without spaces between elements
d2af5aa6c036d (Joe Perches 2021-09-07 19:59:51 -0700 6155) if ($line =~ /$String[A-Z_]/ ||
d2af5aa6c036d (Joe Perches 2021-09-07 19:59:51 -0700 6156) ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6157) if (CHK("CONCATENATED_STRING",
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6158) "Concatenated strings should use spaces between elements\n" . $herecurr) &&
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6159) $fix) {
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6160) while ($line =~ /($String)/g) {
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6161) my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6162) $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6163) $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6164) }
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6165) }
f17dba4fc0496 (Joe Perches 2014-10-13 15:51:51 -0700 6166) }
f17dba4fc0496 (Joe Perches 2014-10-13 15:51:51 -0700 6167)
90ad30e5b2a75 (Joe Perches 2014-12-10 15:51:59 -0800 6168) # uncoalesced string fragments
d2af5aa6c036d (Joe Perches 2021-09-07 19:59:51 -0700 6169) if ($line =~ /$String\s*[Lu]?"/) {
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6170) if (WARN("STRING_FRAGMENTS",
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6171) "Consecutive strings are generally better as a single string\n" . $herecurr) &&
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6172) $fix) {
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6173) while ($line =~ /($String)(?=\s*")/g) {
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6174) my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6175) $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6176) }
79682c0c00893 (Joe Perches 2018-08-21 21:57:29 -0700 6177) }
90ad30e5b2a75 (Joe Perches 2014-12-10 15:51:59 -0800 6178) }
90ad30e5b2a75 (Joe Perches 2014-12-10 15:51:59 -0800 6179)
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6180) # check for non-standard and hex prefixed decimal printf formats
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6181) my $show_L = 1; #don't show the same defect twice
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6182) my $show_Z = 1;
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6183) while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6184) my $string = substr($rawline, $-[1], $+[1] - $-[1]);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6185) $string =~ s/%%/__/g;
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6186) # check for %L
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6187) if ($show_L && $string =~ /%[\*\d\.\$]*L([diouxX])/) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6188) WARN("PRINTF_L",
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6189) "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6190) $show_L = 0;
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6191) }
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6192) # check for %Z
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6193) if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) {
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6194) WARN("PRINTF_Z",
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6195) "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6196) $show_Z = 0;
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6197) }
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6198) # check for 0x<decimal>
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6199) if ($string =~ /0x%[\*\d\.\$\Llzth]*[diou]/) {
522b837c672eb (Alexey Dobriyan 2017-02-27 14:30:05 -0800 6200) ERROR("PRINTF_0XDECIMAL",
6e30075742316 (Joe Perches 2015-09-09 15:37:47 -0700 6201) "Prefixing 0x with decimal output is defective\n" . $herecurr);
6e30075742316 (Joe Perches 2015-09-09 15:37:47 -0700 6202) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6203) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6204)
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6205) # check for line continuations in quoted strings with odd counts of "
3f7f335dbc867 (Joe Perches 2018-02-06 15:38:52 -0800 6206) if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) {
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6207) WARN("LINE_CONTINUATIONS",
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6208) "Avoid line continuations in quoted strings\n" . $herecurr);
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6209) }
5e4f6ba5eb7fa (Joe Perches 2014-12-10 15:52:05 -0800 6210)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6211) # warn about #if 0
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6212) if ($line =~ /^.\s*\#\s*if\s+0\b/) {
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6213) WARN("IF_0",
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6214) "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr);
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6215) }
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6216)
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6217) # warn about #if 1
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6218) if ($line =~ /^.\s*\#\s*if\s+1\b/) {
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6219) WARN("IF_1",
60f890105547f (Prakruthi Deepak Heragu 2018-08-21 21:57:57 -0700 6220) "Consider removing the #if 1 and its #endif\n" . $herecurr);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6221) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6222)
03df4b51f33e1 (Andy Whitcroft 2012-12-17 16:01:52 -0800 6223) # check for needless "if (<foo>) fn(<foo>)" uses
03df4b51f33e1 (Andy Whitcroft 2012-12-17 16:01:52 -0800 6224) if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6225) my $tested = quotemeta($1);
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6226) my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6227) if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6228) my $func = $1;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6229) if (WARN('NEEDLESS_IF',
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6230) "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6231) $fix) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6232) my $do_fix = 1;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6233) my $leading_tabs = "";
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6234) my $new_leading_tabs = "";
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6235) if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6236) $leading_tabs = $1;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6237) } else {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6238) $do_fix = 0;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6239) }
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6240) if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6241) $new_leading_tabs = $1;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6242) if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6243) $do_fix = 0;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6244) }
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6245) } else {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6246) $do_fix = 0;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6247) }
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6248) if ($do_fix) {
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6249) fix_delete_line($fixlinenr - 1, $prevrawline);
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6250) $fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6251) }
100425deeb758 (Joe Perches 2015-09-09 15:37:36 -0700 6252) }
4c432a8f01345 (Greg Kroah-Hartman 2008-07-23 21:29:04 -0700 6253) }
4c432a8f01345 (Greg Kroah-Hartman 2008-07-23 21:29:04 -0700 6254) }
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 6255)
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6256) # check for unnecessary "Out of Memory" messages
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6257) if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6258) $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6259) (defined $1 || defined $3) &&
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6260) $linenr > 3) {
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6261) my $testval = $2;
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6262) my $testline = $lines[$linenr - 3];
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6263)
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6264) my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6265) # print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6266)
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 6267) if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ &&
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 6268) $s !~ /\b__GFP_NOWARN\b/ ) {
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6269) WARN("OOM_MESSAGE",
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6270) "Possible unnecessary 'out of memory' message\n" . $hereprev);
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6271) }
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6272) }
ebfdc40969f24 (Joe Perches 2014-08-06 16:10:27 -0700 6273)
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6274) # check for logging functions with KERN_<LEVEL>
dcaf112365369 (Paolo Bonzini 2015-02-13 14:38:26 -0800 6275) if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6276) $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6277) my $level = $1;
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6278) if (WARN("UNNECESSARY_KERN_LEVEL",
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6279) "Possible unnecessary $level\n" . $herecurr) &&
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6280) $fix) {
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6281) $fixed[$fixlinenr] =~ s/\s*$level\s*//;
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6282) }
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6283) }
f78d98f6ce66f (Joe Perches 2014-10-13 15:52:01 -0700 6284)
45c55e92fcee9 (Joe Perches 2017-02-24 15:01:31 -0800 6285) # check for logging continuations
45c55e92fcee9 (Joe Perches 2017-02-24 15:01:31 -0800 6286) if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
45c55e92fcee9 (Joe Perches 2017-02-24 15:01:31 -0800 6287) WARN("LOGGING_CONTINUATION",
45c55e92fcee9 (Joe Perches 2017-02-24 15:01:31 -0800 6288) "Avoid logging continuation uses where feasible\n" . $herecurr);
45c55e92fcee9 (Joe Perches 2017-02-24 15:01:31 -0800 6289) }
45c55e92fcee9 (Joe Perches 2017-02-24 15:01:31 -0800 6290)
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6291) # check for unnecessary use of %h[xudi] and %hh[xudi] in logging functions
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6292) if (defined $stat &&
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6293) $line =~ /\b$logFunctions\s*\(/ &&
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6294) index($stat, '"') >= 0) {
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6295) my $lc = $stat =~ tr@\n@@;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6296) $lc = $lc + $linenr;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6297) my $stat_real = get_stat_real($linenr, $lc);
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6298) pos($stat_real) = index($stat_real, '"');
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6299) while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) {
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6300) my $pspec = $1;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6301) my $h = $2;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6302) my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6303) if (WARN("UNNECESSARY_MODIFIER",
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6304) "Integer promotion: Using '$h' in '$pspec' is unnecessary\n" . "$here\n$stat_real\n") &&
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6305) $fix && $fixed[$fixlinenr + $lineoff] =~ /^\+/) {
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6306) my $nspec = $pspec;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6307) $nspec =~ s/h//g;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6308) $fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/;
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6309) }
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6310) }
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6311) }
70eb2275ff8e0 (Dwaipayan Ray 2020-12-15 20:45:15 -0800 6312)
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6313) # check for mask then right shift without a parentheses
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6314) if ($perl_version_ok &&
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6315) $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6316) $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6317) WARN("MASK_THEN_SHIFT",
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6318) "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6319) }
abb08a53883ed (Joe Perches 2014-12-10 15:51:46 -0800 6320)
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6321) # check for pointer comparisons to NULL
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6322) if ($perl_version_ok) {
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6323) while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6324) my $val = $1;
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6325) my $equal = "!";
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6326) $equal = "" if ($4 eq "!=");
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6327) if (CHK("COMPARISON_TO_NULL",
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6328) "Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6329) $fix) {
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6330) $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6331) }
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6332) }
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6333) }
b75ac618df751 (Joe Perches 2014-12-10 15:52:02 -0800 6334)
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6335) # check for bad placement of section $InitAttribute (e.g.: __initdata)
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6336) if ($line =~ /(\b$InitAttribute\b)/) {
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6337) my $attr = $1;
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6338) if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6339) my $ptr = $1;
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6340) my $var = $2;
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6341) if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6342) ERROR("MISPLACED_INIT",
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6343) "$attr should be placed after $var\n" . $herecurr)) ||
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6344) ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6345) WARN("MISPLACED_INIT",
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6346) "$attr should be placed after $var\n" . $herecurr))) &&
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6347) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6348) $fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6349) }
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6350) }
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6351) }
8716de383b82f (Joe Perches 2013-09-11 14:24:05 -0700 6352)
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6353) # check for $InitAttributeData (ie: __initdata) with const
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6354) if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6355) my $attr = $1;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6356) $attr =~ /($InitAttributePrefix)(.*)/;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6357) my $attr_prefix = $1;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6358) my $attr_type = $2;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6359) if (ERROR("INIT_ATTRIBUTE",
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6360) "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6361) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6362) $fixed[$fixlinenr] =~
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6363) s/$InitAttributeData/${attr_prefix}initconst/;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6364) }
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6365) }
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6366)
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6367) # check for $InitAttributeConst (ie: __initconst) without const
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6368) if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6369) my $attr = $1;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6370) if (ERROR("INIT_ATTRIBUTE",
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6371) "Use of $attr requires a separate use of const\n" . $herecurr) &&
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6372) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6373) my $lead = $fixed[$fixlinenr] =~
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6374) /(^\+\s*(?:static\s+))/;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6375) $lead = rtrim($1);
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6376) $lead = "$lead " if ($lead !~ /^\+$/);
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6377) $lead = "${lead}const ";
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6378) $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6379) }
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6380) }
e970b8846ae47 (Joe Perches 2013-11-12 15:10:10 -0800 6381)
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6382) # check for __read_mostly with const non-pointer (should just be const)
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6383) if ($line =~ /\b__read_mostly\b/ &&
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6384) $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6385) if (ERROR("CONST_READ_MOSTLY",
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6386) "Invalid use of __read_mostly with const type\n" . $herecurr) &&
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6387) $fix) {
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6388) $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6389) }
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6390) }
c17893c7407fb (Joe Perches 2015-04-16 12:44:42 -0700 6391)
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6392) # don't use __constant_<foo> functions outside of include/uapi/
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6393) if ($realfile !~ m@^include/uapi/@ &&
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6394) $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6395) my $constant_func = $1;
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6396) my $func = $constant_func;
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6397) $func =~ s/^__constant_//;
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6398) if (WARN("CONSTANT_CONVERSION",
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6399) "$constant_func should be $func\n" . $herecurr) &&
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6400) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6401) $fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6402) }
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6403) }
fbdb8138cf0c7 (Joe Perches 2014-04-03 14:49:14 -0700 6404)
1a15a250862fd (Patrick Pannuto 2010-08-09 17:21:01 -0700 6405) # prefer usleep_range over udelay
37581c28e9e77 (Bruce Allan 2013-02-21 16:44:19 -0800 6406) if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
43c1d77c39320 (Joe Perches 2014-04-03 14:49:11 -0700 6407) my $delay = $1;
1a15a250862fd (Patrick Pannuto 2010-08-09 17:21:01 -0700 6408) # ignore udelay's < 10, however
43c1d77c39320 (Joe Perches 2014-04-03 14:49:11 -0700 6409) if (! ($delay < 10) ) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6410) CHK("USLEEP_RANGE",
458f69ef36656 (Mauro Carvalho Chehab 2019-06-12 14:53:00 -0300 6411) "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr);
43c1d77c39320 (Joe Perches 2014-04-03 14:49:11 -0700 6412) }
43c1d77c39320 (Joe Perches 2014-04-03 14:49:11 -0700 6413) if ($delay > 2000) {
43c1d77c39320 (Joe Perches 2014-04-03 14:49:11 -0700 6414) WARN("LONG_UDELAY",
43c1d77c39320 (Joe Perches 2014-04-03 14:49:11 -0700 6415) "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
1a15a250862fd (Patrick Pannuto 2010-08-09 17:21:01 -0700 6416) }
1a15a250862fd (Patrick Pannuto 2010-08-09 17:21:01 -0700 6417) }
1a15a250862fd (Patrick Pannuto 2010-08-09 17:21:01 -0700 6418)
09ef87255da0e (Patrick Pannuto 2010-08-09 17:21:02 -0700 6419) # warn about unexpectedly long msleep's
09ef87255da0e (Patrick Pannuto 2010-08-09 17:21:02 -0700 6420) if ($line =~ /\bmsleep\s*\((\d+)\);/) {
09ef87255da0e (Patrick Pannuto 2010-08-09 17:21:02 -0700 6421) if ($1 < 20) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6422) WARN("MSLEEP",
458f69ef36656 (Mauro Carvalho Chehab 2019-06-12 14:53:00 -0300 6423) "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr);
09ef87255da0e (Patrick Pannuto 2010-08-09 17:21:02 -0700 6424) }
09ef87255da0e (Patrick Pannuto 2010-08-09 17:21:02 -0700 6425) }
09ef87255da0e (Patrick Pannuto 2010-08-09 17:21:02 -0700 6426)
36ec19390effc (Joe Perches 2013-07-03 15:05:25 -0700 6427) # check for comparisons of jiffies
36ec19390effc (Joe Perches 2013-07-03 15:05:25 -0700 6428) if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
36ec19390effc (Joe Perches 2013-07-03 15:05:25 -0700 6429) WARN("JIFFIES_COMPARISON",
36ec19390effc (Joe Perches 2013-07-03 15:05:25 -0700 6430) "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
36ec19390effc (Joe Perches 2013-07-03 15:05:25 -0700 6431) }
36ec19390effc (Joe Perches 2013-07-03 15:05:25 -0700 6432)
9d7a34a5135d2 (Joe Perches 2013-07-03 15:05:26 -0700 6433) # check for comparisons of get_jiffies_64()
9d7a34a5135d2 (Joe Perches 2013-07-03 15:05:26 -0700 6434) if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
9d7a34a5135d2 (Joe Perches 2013-07-03 15:05:26 -0700 6435) WARN("JIFFIES_COMPARISON",
9d7a34a5135d2 (Joe Perches 2013-07-03 15:05:26 -0700 6436) "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
9d7a34a5135d2 (Joe Perches 2013-07-03 15:05:26 -0700 6437) }
9d7a34a5135d2 (Joe Perches 2013-07-03 15:05:26 -0700 6438)
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6439) # warn about #ifdefs in C files
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6440) # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6441) # print "#ifdef in C files should be avoided\n";
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6442) # print "$herecurr";
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6443) # $clean = 0;
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6444) # }
00df344fd06fd (Andy Whitcroft 2007-06-08 13:47:06 -0700 6445)
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 6446) # warn about spacing in #ifdefs
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6447) if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 6448) if (ERROR("SPACING",
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 6449) "exactly one space required after that #$1\n" . $herecurr) &&
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 6450) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6451) $fixed[$fixlinenr] =~
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 6452) s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 6453) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 6454)
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 6455) }
22f2a2ef9b468 (Andy Whitcroft 2007-08-10 13:01:03 -0700 6456)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6457) # check for spinlock_t definitions without a comment.
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6458) if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6459) $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6460) my $which = $1;
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6461) if (!ctx_has_comment($first_line, $linenr)) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6462) CHK("UNCOMMENTED_DEFINITION",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6463) "$1 definition without comment\n" . $herecurr);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6464) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6465) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6466) # check for memory barriers without a comment.
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6467)
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6468) my $barriers = qr{
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6469) mb|
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6470) rmb|
ad83ec6ce1361 (Will Deacon 2019-11-07 14:49:00 +0000 6471) wmb
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6472) }x;
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6473) my $barrier_stems = qr{
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6474) mb__before_atomic|
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6475) mb__after_atomic|
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6476) store_release|
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6477) load_acquire|
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6478) store_mb|
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6479) (?:$barriers)
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6480) }x;
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6481) my $all_barriers = qr{
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6482) (?:$barriers)|
43e361f23c49d (Michael S. Tsirkin 2016-01-04 10:00:10 +0200 6483) smp_(?:$barrier_stems)|
43e361f23c49d (Michael S. Tsirkin 2016-01-04 10:00:10 +0200 6484) virt_(?:$barrier_stems)
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6485) }x;
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6486)
402c2553a2472 (Michael S. Tsirkin 2016-01-04 09:39:01 +0200 6487) if ($line =~ /\b(?:$all_barriers)\s*\(/) {
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6488) if (!ctx_has_comment($first_line, $linenr)) {
c1fd7bb99637e (Joe Perches 2013-11-12 15:10:11 -0800 6489) WARN("MEMORY_BARRIER",
c1fd7bb99637e (Joe Perches 2013-11-12 15:10:11 -0800 6490) "memory barrier without comment\n" . $herecurr);
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6491) }
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6492) }
3ad81779ad35c (Paul E. McKenney 2015-07-02 11:55:40 -0700 6493)
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6494) my $underscore_smp_barriers = qr{__smp_(?:$barrier_stems)}x;
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6495)
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6496) if ($realfile !~ m@^include/asm-generic/@ &&
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6497) $realfile !~ m@/barrier\.h$@ &&
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6498) $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ &&
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6499) $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) {
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6500) WARN("MEMORY_BARRIER",
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6501) "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6502) }
f4073b0f6e11a (Michael S. Tsirkin 2016-01-04 09:54:51 +0200 6503)
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6504) # check for waitqueue_active without a comment.
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6505) if ($line =~ /\bwaitqueue_active\s*\(/) {
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6506) if (!ctx_has_comment($first_line, $linenr)) {
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6507) WARN("WAITQUEUE_ACTIVE",
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6508) "waitqueue_active without comment\n" . $herecurr);
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6509) }
cb426e99ff922 (Joe Perches 2015-06-25 15:02:46 -0700 6510) }
3ad81779ad35c (Paul E. McKenney 2015-07-02 11:55:40 -0700 6511)
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6512) # check for data_race without a comment.
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6513) if ($line =~ /\bdata_race\s*\(/) {
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6514) if (!ctx_has_comment($first_line, $linenr)) {
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6515) WARN("DATA_RACE",
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6516) "data_race without comment\n" . $herecurr);
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6517) }
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6518) }
5099a722e9727 (Marco Elver 2020-04-01 12:17:14 +0200 6519)
4a0df2ef4569a (Andy Whitcroft 2007-06-08 13:46:39 -0700 6520) # check of hardware specific defines
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6521) if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6522) CHK("ARCH_DEFINES",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6523) "architecture specific defines should be avoided\n" . $herecurr);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 6524) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 6525)
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6526) # check that the storage class is not after a type
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6527) if ($line =~ /\b($Type)\s+($Storage)\b/) {
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6528) WARN("STORAGE_CLASS",
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6529) "storage class '$2' should be located before type '$1'\n" . $herecurr);
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6530) }
d4977c78e9c7d (Tobias Klauser 2010-05-24 14:33:30 -0700 6531) # Check that the storage class is at the beginning of a declaration
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6532) if ($line =~ /\b$Storage\b/ &&
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6533) $line !~ /^.\s*$Storage/ &&
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6534) $line =~ /^.\s*(.+?)\$Storage\s/ &&
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6535) $1 !~ /[\,\)]\s*$/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6536) WARN("STORAGE_CLASS",
596ed45b5b5b7 (Joe Perches 2017-07-12 14:37:02 -0700 6537) "storage class should be at the beginning of the declaration\n" . $herecurr);
d4977c78e9c7d (Tobias Klauser 2010-05-24 14:33:30 -0700 6538) }
d4977c78e9c7d (Tobias Klauser 2010-05-24 14:33:30 -0700 6539)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6540) # check the location of the inline attribute, that it is between
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6541) # storage class and type.
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 6542) if ($line =~ /\b$Type\s+$Inline\b/ ||
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 6543) $line =~ /\b$Inline\s+$Storage\b/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6544) ERROR("INLINE_LOCATION",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6545) "inline keyword should sit between storage class and type\n" . $herecurr);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6546) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6547)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 6548) # Check for __inline__ and __inline, prefer inline
2b7ab45395dc4 (Joe Perches 2013-11-12 15:10:14 -0800 6549) if ($realfile !~ m@\binclude/uapi/@ &&
2b7ab45395dc4 (Joe Perches 2013-11-12 15:10:14 -0800 6550) $line =~ /\b(__inline__|__inline)\b/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6551) if (WARN("INLINE",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6552) "plain inline is preferred over $1\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6553) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6554) $fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6555)
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6556) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 6557) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 6558)
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6559) # Check for compiler attributes
2b7ab45395dc4 (Joe Perches 2013-11-12 15:10:14 -0800 6560) if ($realfile !~ m@\binclude/uapi/@ &&
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6561) $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) {
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6562) my $attr = $1;
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6563) $attr =~ s/\s*\(\s*(.*)\)\s*/$1/;
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6564)
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6565) my %attr_list = (
0830aab0e1d4d (Joe Perches 2020-12-15 20:44:50 -0800 6566) "alias" => "__alias",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6567) "aligned" => "__aligned",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6568) "always_inline" => "__always_inline",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6569) "assume_aligned" => "__assume_aligned",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6570) "cold" => "__cold",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6571) "const" => "__attribute_const__",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6572) "copy" => "__copy",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6573) "designated_init" => "__designated_init",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6574) "externally_visible" => "__visible",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6575) "format" => "printf|scanf",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6576) "gnu_inline" => "__gnu_inline",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6577) "malloc" => "__malloc",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6578) "mode" => "__mode",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6579) "no_caller_saved_registers" => "__no_caller_saved_registers",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6580) "noclone" => "__noclone",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6581) "noinline" => "noinline",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6582) "nonstring" => "__nonstring",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6583) "noreturn" => "__noreturn",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6584) "packed" => "__packed",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6585) "pure" => "__pure",
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6586) "section" => "__section",
0830aab0e1d4d (Joe Perches 2020-12-15 20:44:50 -0800 6587) "used" => "__used",
0830aab0e1d4d (Joe Perches 2020-12-15 20:44:50 -0800 6588) "weak" => "__weak"
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6589) );
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6590)
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6591) while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) {
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6592) my $orig_attr = $1;
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6593) my $params = '';
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6594) $params = $2 if defined($2);
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6595) my $curr_attr = $orig_attr;
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6596) $curr_attr =~ s/^[\s_]+|[\s_]+$//g;
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6597) if (exists($attr_list{$curr_attr})) {
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6598) my $new = $attr_list{$curr_attr};
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6599) if ($curr_attr eq "format" && $params) {
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6600) $params =~ /^\s*\(\s*(\w+)\s*,\s*(.*)/;
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6601) $new = "__$1\($2";
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6602) } else {
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6603) $new = "$new$params";
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6604) }
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6605) if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO",
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6606) "Prefer $new over __attribute__(($orig_attr$params))\n" . $herecurr) &&
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6607) $fix) {
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6608) my $remove = "\Q$orig_attr\E" . '\s*' . "\Q$params\E" . '(?:\s*,\s*)?';
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6609) $fixed[$fixlinenr] =~ s/$remove//;
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6610) $fixed[$fixlinenr] =~ s/\b__attribute__/$new __attribute__/;
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6611) $fixed[$fixlinenr] =~ s/\}\Q$new\E/} $new/;
339f29d91acf3 (Joe Perches 2020-12-15 20:44:43 -0800 6612) $fixed[$fixlinenr] =~ s/ __attribute__\s*\(\s*\(\s*\)\s*\)//;
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6613) }
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6614) }
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6615) }
5f14d3bd87ef5 (Joe Perches 2012-01-10 15:09:52 -0800 6616)
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6617) # Check for __attribute__ unused, prefer __always_unused or __maybe_unused
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6618) if ($attr =~ /^_*unused/) {
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6619) WARN("PREFER_DEFINED_ATTRIBUTE_MACRO",
7ebe1d173cae0 (Dwaipayan Ray 2020-12-15 20:44:36 -0800 6620) "__always_unused or __maybe_unused is preferred over __attribute__((__unused__))\n" . $herecurr);
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6621) }
6061d949dd984 (Joe Perches 2012-03-23 15:02:16 -0700 6622) }
6061d949dd984 (Joe Perches 2012-03-23 15:02:16 -0700 6623)
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6624) # Check for __attribute__ weak, or __weak declarations (may have link issues)
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6625) if ($perl_version_ok &&
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6626) $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6627) ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6628) $line =~ /\b__weak\b/)) {
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6629) ERROR("WEAK_DECLARATION",
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6630) "Using weak declarations can have unintended link defects\n" . $herecurr);
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6631) }
619a908aa334c (Joe Perches 2014-12-10 15:51:35 -0800 6632)
fd39f904b1768 (Tomas Winkler 2016-12-12 16:46:34 -0800 6633) # check for c99 types like uint8_t used outside of uapi/ and tools/
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6634) if ($realfile !~ m@\binclude/uapi/@ &&
fd39f904b1768 (Tomas Winkler 2016-12-12 16:46:34 -0800 6635) $realfile !~ m@\btools/@ &&
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6636) $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6637) my $type = $1;
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6638) if ($type =~ /\b($typeC99Typedefs)\b/) {
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6639) $type = $1;
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6640) my $kernel_type = 'u';
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6641) $kernel_type = 's' if ($type =~ /^_*[si]/);
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6642) $type =~ /(\d+)/;
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6643) $kernel_type .= $1;
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6644) if (CHK("PREFER_KERNEL_TYPES",
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6645) "Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) &&
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6646) $fix) {
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6647) $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6648) }
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6649) }
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6650) }
e6176fa4728fb (Joe Perches 2015-06-25 15:02:49 -0700 6651)
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6652) # check for cast of C90 native int or longer types constants
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6653) if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6654) my $cast = $1;
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6655) my $const = $2;
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6656) my $suffix = "";
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6657) my $newconst = $const;
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6658) $newconst =~ s/${Int_type}$//;
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6659) $suffix .= 'U' if ($cast =~ /\bunsigned\b/);
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6660) if ($cast =~ /\blong\s+long\b/) {
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6661) $suffix .= 'LL';
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6662) } elsif ($cast =~ /\blong\b/) {
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6663) $suffix .= 'L';
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6664) }
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6665) if (WARN("TYPECAST_INT_CONSTANT",
0972b8bfe0de8 (Joe Perches 2021-02-25 17:21:54 -0800 6666) "Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr) &&
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6667) $fix) {
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6668) $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6669) }
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6670) }
938224b5e596c (Joe Perches 2016-01-20 14:59:15 -0800 6671)
8f53a9b80f011 (Joe Perches 2010-03-05 13:43:48 -0800 6672) # check for sizeof(&)
8f53a9b80f011 (Joe Perches 2010-03-05 13:43:48 -0800 6673) if ($line =~ /\bsizeof\s*\(\s*\&/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6674) WARN("SIZEOF_ADDRESS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6675) "sizeof(& should be avoided\n" . $herecurr);
8f53a9b80f011 (Joe Perches 2010-03-05 13:43:48 -0800 6676) }
8f53a9b80f011 (Joe Perches 2010-03-05 13:43:48 -0800 6677)
66c80b6077256 (Joe Perches 2012-07-30 14:41:22 -0700 6678) # check for sizeof without parenthesis
66c80b6077256 (Joe Perches 2012-07-30 14:41:22 -0700 6679) if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6680) if (WARN("SIZEOF_PARENTHESIS",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6681) "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6682) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6683) $fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6684) }
66c80b6077256 (Joe Perches 2012-07-30 14:41:22 -0700 6685) }
66c80b6077256 (Joe Perches 2012-07-30 14:41:22 -0700 6686)
88982fea52d01 (Joe Perches 2012-12-17 16:02:00 -0800 6687) # check for struct spinlock declarations
88982fea52d01 (Joe Perches 2012-12-17 16:02:00 -0800 6688) if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
88982fea52d01 (Joe Perches 2012-12-17 16:02:00 -0800 6689) WARN("USE_SPINLOCK_T",
88982fea52d01 (Joe Perches 2012-12-17 16:02:00 -0800 6690) "struct spinlock should be spinlock_t\n" . $herecurr);
88982fea52d01 (Joe Perches 2012-12-17 16:02:00 -0800 6691) }
88982fea52d01 (Joe Perches 2012-12-17 16:02:00 -0800 6692)
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 6693) # check for seq_printf uses that could be seq_puts
066687279ccf5 (Joe Perches 2013-11-12 15:10:07 -0800 6694) if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 6695) my $fmt = get_quoted_string($line, $rawline);
caac1d5fddf2d (Heba Aamer 2015-02-13 14:38:49 -0800 6696) $fmt =~ s/%%//g;
caac1d5fddf2d (Heba Aamer 2015-02-13 14:38:49 -0800 6697) if ($fmt !~ /%/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6698) if (WARN("PREFER_SEQ_PUTS",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6699) "Prefer seq_puts to seq_printf\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6700) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6701) $fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 6702) }
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 6703) }
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 6704) }
a6962d7273d8f (Joe Perches 2013-04-29 16:18:13 -0700 6705)
478b17998066a (Joe Perches 2018-04-10 16:33:34 -0700 6706) # check for vsprintf extension %p<foo> misuses
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6707) if ($perl_version_ok &&
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6708) defined $stat &&
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6709) $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6710) $1 !~ /^_*volatile_*$/) {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6711) my $stat_real;
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6712)
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6713) my $lc = $stat =~ tr@\n@@;
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6714) $lc = $lc + $linenr;
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6715) for (my $count = $linenr; $count <= $lc; $count++) {
ffe075132af8b (Joe Perches 2018-07-13 16:59:23 -0700 6716) my $specifier;
ffe075132af8b (Joe Perches 2018-07-13 16:59:23 -0700 6717) my $extension;
3bd32d6a2ee62 (Sakari Ailus 2019-10-03 15:32:18 +0300 6718) my $qualifier;
ffe075132af8b (Joe Perches 2018-07-13 16:59:23 -0700 6719) my $bad_specifier = "";
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6720) my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6721) $fmt =~ s/%%//g;
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6722)
3bd32d6a2ee62 (Sakari Ailus 2019-10-03 15:32:18 +0300 6723) while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*))/g) {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6724) $specifier = $1;
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6725) $extension = $2;
3bd32d6a2ee62 (Sakari Ailus 2019-10-03 15:32:18 +0300 6726) $qualifier = $3;
af612e43de6d2 (Sakari Ailus 2021-02-16 17:57:20 +0200 6727) if ($extension !~ /[4SsBKRraEehMmIiUDdgVCbGNOxtf]/ ||
3bd32d6a2ee62 (Sakari Ailus 2019-10-03 15:32:18 +0300 6728) ($extension eq "f" &&
af612e43de6d2 (Sakari Ailus 2021-02-16 17:57:20 +0200 6729) defined $qualifier && $qualifier !~ /^w/) ||
af612e43de6d2 (Sakari Ailus 2021-02-16 17:57:20 +0200 6730) ($extension eq "4" &&
af612e43de6d2 (Sakari Ailus 2021-02-16 17:57:20 +0200 6731) defined $qualifier && $qualifier !~ /^cc/)) {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6732) $bad_specifier = $specifier;
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6733) last;
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6734) }
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6735) if ($extension eq "x" && !defined($stat_real)) {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6736) if (!defined($stat_real)) {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6737) $stat_real = get_stat_real($linenr, $lc);
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6738) }
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6739) WARN("VSPRINTF_SPECIFIER_PX",
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6740) "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n");
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6741) }
1df7338ac9655 (Sergey Senozhatsky 2017-11-10 08:48:30 +0900 6742) }
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6743) if ($bad_specifier ne "") {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6744) my $stat_real = get_stat_real($linenr, $lc);
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6745) my $ext_type = "Invalid";
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6746) my $use = "";
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6747) if ($bad_specifier =~ /p[Ff]/) {
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6748) $use = " - use %pS instead";
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6749) $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6750) }
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 6751)
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6752) WARN("VSPRINTF_POINTER_EXTENSION",
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6753) "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n");
e3c6bc95668b9 (Tobin C. Harding 2018-04-10 16:33:31 -0700 6754) }
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6755) }
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6756) }
0b523769ebb94 (Joe Perches 2017-05-08 15:55:36 -0700 6757)
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6758) # Check for misused memsets
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6759) if ($perl_version_ok &&
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6760) defined $stat &&
9e20a8535f3fd (Mateusz Kulikowski 2015-06-25 15:03:16 -0700 6761) $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6762)
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6763) my $ms_addr = $2;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6764) my $ms_val = $7;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6765) my $ms_size = $12;
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6766)
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6767) if ($ms_size =~ /^(0x|)0$/i) {
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6768) ERROR("MEMSET",
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6769) "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6770) } elsif ($ms_size =~ /^(0x|)1$/i) {
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6771) WARN("MEMSET",
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6772) "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6773) }
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6774) }
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6775)
98a9bba51c6e4 (Joe Perches 2014-01-23 15:54:52 -0800 6776) # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6777) # if ($perl_version_ok &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6778) # defined $stat &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6779) # $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6780) # if (WARN("PREFER_ETHER_ADDR_COPY",
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6781) # "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6782) # $fix) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6783) # $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6784) # }
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6785) # }
98a9bba51c6e4 (Joe Perches 2014-01-23 15:54:52 -0800 6786)
b6117d175be99 (Mateusz Kulikowski 2015-06-25 15:03:13 -0700 6787) # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6788) # if ($perl_version_ok &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6789) # defined $stat &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6790) # $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6791) # WARN("PREFER_ETHER_ADDR_EQUAL",
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6792) # "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6793) # }
b6117d175be99 (Mateusz Kulikowski 2015-06-25 15:03:13 -0700 6794)
8617cd09bc874 (Mateusz Kulikowski 2015-06-25 15:03:19 -0700 6795) # check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
8617cd09bc874 (Mateusz Kulikowski 2015-06-25 15:03:19 -0700 6796) # check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6797) # if ($perl_version_ok &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6798) # defined $stat &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6799) # $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6800) #
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6801) # my $ms_val = $7;
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6802) #
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6803) # if ($ms_val =~ /^(?:0x|)0+$/i) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6804) # if (WARN("PREFER_ETH_ZERO_ADDR",
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6805) # "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6806) # $fix) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6807) # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6808) # }
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6809) # } elsif ($ms_val =~ /^(?:0xff|255)$/i) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6810) # if (WARN("PREFER_ETH_BROADCAST_ADDR",
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6811) # "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6812) # $fix) {
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6813) # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6814) # }
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6815) # }
f333195d41e15 (Joe Perches 2016-10-11 13:51:53 -0700 6816) # }
8617cd09bc874 (Mateusz Kulikowski 2015-06-25 15:03:19 -0700 6817)
5dbdb2d87c294 (Joe Perches 2020-12-29 15:14:31 -0800 6818) # strlcpy uses that should likely be strscpy
5dbdb2d87c294 (Joe Perches 2020-12-29 15:14:31 -0800 6819) if ($line =~ /\bstrlcpy\s*\(/) {
5dbdb2d87c294 (Joe Perches 2020-12-29 15:14:31 -0800 6820) WARN("STRLCPY",
5dbdb2d87c294 (Joe Perches 2020-12-29 15:14:31 -0800 6821) "Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr);
5dbdb2d87c294 (Joe Perches 2020-12-29 15:14:31 -0800 6822) }
5dbdb2d87c294 (Joe Perches 2020-12-29 15:14:31 -0800 6823)
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6824) # typecasts on min/max could be min_t/max_t
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6825) if ($perl_version_ok &&
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6826) defined $stat &&
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6827) $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6828) if (defined $2 || defined $7) {
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6829) my $call = $1;
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6830) my $cast1 = deparenthesize($2);
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6831) my $arg1 = $3;
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6832) my $cast2 = deparenthesize($7);
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6833) my $arg2 = $8;
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6834) my $cast;
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6835)
d1fe9c099cecc (Joe Perches 2012-03-23 15:02:16 -0700 6836) if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) {
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6837) $cast = "$cast1 or $cast2";
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6838) } elsif ($cast1 ne "") {
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6839) $cast = $cast1;
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6840) } else {
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6841) $cast = $cast2;
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6842) }
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6843) WARN("MINMAX",
d7c76ba7e58bc (Joe Perches 2012-01-10 15:09:58 -0800 6844) "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6845) }
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6846) }
554e165cf3261 (Andy Whitcroft 2012-01-10 15:09:57 -0800 6847)
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6848) # check usleep_range arguments
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6849) if ($perl_version_ok &&
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6850) defined $stat &&
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6851) $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6852) my $min = $1;
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6853) my $max = $7;
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6854) if ($min eq $max) {
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6855) WARN("USLEEP_RANGE",
458f69ef36656 (Mauro Carvalho Chehab 2019-06-12 14:53:00 -0300 6856) "usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n");
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6857) } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6858) $min > $max) {
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6859) WARN("USLEEP_RANGE",
458f69ef36656 (Mauro Carvalho Chehab 2019-06-12 14:53:00 -0300 6860) "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n");
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6861) }
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6862) }
4a273195a551a (Joe Perches 2012-07-30 14:41:20 -0700 6863)
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6864) # check for naked sscanf
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6865) if ($perl_version_ok &&
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6866) defined $stat &&
6c8bd7076d796 (Joe Perches 2014-04-03 14:49:16 -0700 6867) $line =~ /\bsscanf\b/ &&
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6868) ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6869) $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6870) $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6871) my $lc = $stat =~ tr@\n@@;
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6872) $lc = $lc + $linenr;
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 6873) my $stat_real = get_stat_real($linenr, $lc);
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6874) WARN("NAKED_SSCANF",
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6875) "unchecked sscanf return value\n" . "$here\n$stat_real\n");
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6876) }
823b794ce176b (Joe Perches 2013-11-12 15:10:15 -0800 6877)
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6878) # check for simple sscanf that should be kstrto<foo>
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6879) if ($perl_version_ok &&
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6880) defined $stat &&
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6881) $line =~ /\bsscanf\b/) {
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6882) my $lc = $stat =~ tr@\n@@;
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6883) $lc = $lc + $linenr;
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 6884) my $stat_real = get_stat_real($linenr, $lc);
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6885) if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6886) my $format = $6;
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6887) my $count = $format =~ tr@%@%@;
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6888) if ($count == 1 &&
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6889) $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) {
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6890) WARN("SSCANF_TO_KSTRTO",
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6891) "Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n");
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6892) }
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6893) }
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6894) }
afc819ab0293b (Joe Perches 2014-06-04 16:12:08 -0700 6895)
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6896) # check for new externs in .h files.
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6897) if ($realfile =~ /\.h$/ &&
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6898) $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
d1d85780dd30e (Joe Perches 2013-09-24 15:27:46 -0700 6899) if (CHK("AVOID_EXTERNS",
d1d85780dd30e (Joe Perches 2013-09-24 15:27:46 -0700 6900) "extern prototypes should be avoided in .h files\n" . $herecurr) &&
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6901) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 6902) $fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6903) }
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6904) }
70dc8a48357ce (Joe Perches 2013-09-11 14:23:58 -0700 6905)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6906) # check for new externs in .c files.
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6907) if ($realfile =~ /\.c$/ && defined $stat &&
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6908) $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6909) {
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6910) my $function_name = $1;
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6911) my $paren_space = $2;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6912)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6913) my $s = $stat;
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6914) if (defined $cond) {
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6915) substr($s, 0, length($cond), '');
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6916) }
d8b44b58a7073 (Kees Cook 2020-06-03 14:18:09 -0700 6917) if ($s =~ /^\s*;/)
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 6918) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6919) WARN("AVOID_EXTERNS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6920) "externs should be avoided in .c files\n" . $herecurr);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6921) }
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6922)
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6923) if ($paren_space =~ /\n/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6924) WARN("FUNCTION_ARGUMENTS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6925) "arguments for function declarations should follow identifier\n" . $herecurr);
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 6926) }
9c9ba34ee3dbc (Andy Whitcroft 2008-04-29 00:59:33 -0700 6927)
9c9ba34ee3dbc (Andy Whitcroft 2008-04-29 00:59:33 -0700 6928) } elsif ($realfile =~ /\.c$/ && defined $stat &&
9c9ba34ee3dbc (Andy Whitcroft 2008-04-29 00:59:33 -0700 6929) $stat =~ /^.\s*extern\s+/)
9c9ba34ee3dbc (Andy Whitcroft 2008-04-29 00:59:33 -0700 6930) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6931) WARN("AVOID_EXTERNS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6932) "externs should be avoided in .c files\n" . $herecurr);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6933) }
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6934)
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6935) # check for function declarations that have arguments without identifier names
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6936) if (defined $stat &&
d8b44b58a7073 (Kees Cook 2020-06-03 14:18:09 -0700 6937) $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
d8b44b58a7073 (Kees Cook 2020-06-03 14:18:09 -0700 6938) $1 ne "void") {
d8b44b58a7073 (Kees Cook 2020-06-03 14:18:09 -0700 6939) my $args = trim($1);
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6940) while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6941) my $arg = trim($1);
d8b44b58a7073 (Kees Cook 2020-06-03 14:18:09 -0700 6942) if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6943) WARN("FUNCTION_ARGUMENTS",
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6944) "function definition argument '$arg' should also have an identifier name\n" . $herecurr);
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6945) }
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6946) }
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6947) }
ca0d8929e75ab (Joe Perches 2016-10-11 13:52:16 -0700 6948)
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6949) # check for function definitions
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6950) if ($perl_version_ok &&
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6951) defined $stat &&
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6952) $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) {
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6953) $context_function = $1;
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6954)
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6955) # check for multiline function definition with misplaced open brace
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6956) my $ok = 0;
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6957) my $cnt = statement_rawlines($stat);
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6958) my $herectx = $here . "\n";
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6959) for (my $n = 0; $n < $cnt; $n++) {
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6960) my $rl = raw_line($linenr, $n);
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6961) $herectx .= $rl . "\n";
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6962) $ok = 1 if ($rl =~ /^[ \+]\{/);
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6963) $ok = 1 if ($rl =~ /\{/ && $n == 0);
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6964) last if $rl =~ /^[ \+].*\{/;
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6965) }
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6966) if (!$ok) {
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6967) ERROR("OPEN_BRACE",
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6968) "open brace '{' following function definitions go on the next line\n" . $herectx);
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6969) }
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6970) }
a0ad75964e58c (Joe Perches 2017-07-10 15:52:19 -0700 6971)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6972) # checks for new __setup's
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6973) if ($rawline =~ /\b__setup\("([^"]*)"/) {
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6974) my $name = $1;
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6975)
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6976) if (!grep(/$name/, @setup_docs)) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6977) CHK("UNDOCUMENTED_SETUP",
2581ac7c2f6b0 (Tim Froidcoeur 2020-06-10 18:41:38 -0700 6978) "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $herecurr);
de7d4f0e1172a (Andy Whitcroft 2007-07-15 23:37:22 -0700 6979) }
653d4876b730f (Andy Whitcroft 2007-06-23 17:16:34 -0700 6980) }
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 6981)
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 6982) # check for pointless casting of alloc functions
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 6983) if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6984) WARN("UNNECESSARY_CASTS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 6985) "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
9c0ca6f9a0a08 (Andy Whitcroft 2007-10-16 23:29:38 -0700 6986) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 6987)
a640d25cead66 (Joe Perches 2013-07-03 15:05:21 -0700 6988) # alloc style
a640d25cead66 (Joe Perches 2013-07-03 15:05:21 -0700 6989) # p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6990) if ($perl_version_ok &&
e29a70f1537b1 (Joe Perches 2019-03-07 16:28:35 -0800 6991) $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
a640d25cead66 (Joe Perches 2013-07-03 15:05:21 -0700 6992) CHK("ALLOC_SIZEOF_STRUCT",
a640d25cead66 (Joe Perches 2013-07-03 15:05:21 -0700 6993) "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
a640d25cead66 (Joe Perches 2013-07-03 15:05:21 -0700 6994) }
a640d25cead66 (Joe Perches 2013-07-03 15:05:21 -0700 6995)
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 6996) # check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 6997) if ($perl_version_ok &&
1b4a2ed4c8773 (Joe Perches 2017-05-08 15:55:57 -0700 6998) defined $stat &&
1b4a2ed4c8773 (Joe Perches 2017-05-08 15:55:57 -0700 6999) $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7000) my $oldfunc = $3;
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7001) my $a1 = $4;
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7002) my $a2 = $10;
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7003) my $newfunc = "kmalloc_array";
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7004) $newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7005) my $r1 = $a1;
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7006) my $r2 = $a2;
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7007) if ($a1 =~ /^sizeof\s*\S/) {
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7008) $r1 = $a2;
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7009) $r2 = $a1;
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7010) }
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7011) if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
e367455a9f25b (Joe Perches 2014-08-06 16:10:55 -0700 7012) !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
1b4a2ed4c8773 (Joe Perches 2017-05-08 15:55:57 -0700 7013) my $cnt = statement_rawlines($stat);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 7014) my $herectx = get_stat_here($linenr, $cnt, $here);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 7015)
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7016) if (WARN("ALLOC_WITH_MULTIPLY",
1b4a2ed4c8773 (Joe Perches 2017-05-08 15:55:57 -0700 7017) "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
1b4a2ed4c8773 (Joe Perches 2017-05-08 15:55:57 -0700 7018) $cnt == 1 &&
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7019) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 7020) $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7021) }
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7022) }
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7023) }
60a55369aad33 (Joe Perches 2014-06-04 16:12:07 -0700 7024)
972fdea2e6ece (Joe Perches 2013-04-29 16:18:12 -0700 7025) # check for krealloc arg reuse
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 7026) if ($perl_version_ok &&
4cab63cea374c (Joe Perches 2018-08-21 21:57:50 -0700 7027) $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ &&
4cab63cea374c (Joe Perches 2018-08-21 21:57:50 -0700 7028) $1 eq $3) {
972fdea2e6ece (Joe Perches 2013-04-29 16:18:12 -0700 7029) WARN("KREALLOC_ARG_REUSE",
972fdea2e6ece (Joe Perches 2013-04-29 16:18:12 -0700 7030) "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
972fdea2e6ece (Joe Perches 2013-04-29 16:18:12 -0700 7031) }
972fdea2e6ece (Joe Perches 2013-04-29 16:18:12 -0700 7032)
5ce59ae0bcc0f (Joe Perches 2013-02-21 16:44:18 -0800 7033) # check for alloc argument mismatch
7e6cdd7fd9438 (Christophe JAILLET 2021-05-06 18:04:01 -0700 7034) if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
5ce59ae0bcc0f (Joe Perches 2013-02-21 16:44:18 -0800 7035) WARN("ALLOC_ARRAY_ARGS",
5ce59ae0bcc0f (Joe Perches 2013-02-21 16:44:18 -0800 7036) "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
5ce59ae0bcc0f (Joe Perches 2013-02-21 16:44:18 -0800 7037) }
5ce59ae0bcc0f (Joe Perches 2013-02-21 16:44:18 -0800 7038)
caf2a54f101a5 (Joe Perches 2011-01-12 16:59:56 -0800 7039) # check for multiple semicolons
caf2a54f101a5 (Joe Perches 2011-01-12 16:59:56 -0800 7040) if ($line =~ /;\s*;\s*$/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7041) if (WARN("ONE_SEMICOLON",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7042) "Statements terminations use 1 semicolon\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7043) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 7044) $fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7045) }
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7046) }
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7047)
cec3aaa56638c (Tomas Winkler 2016-08-02 14:04:39 -0700 7048) # check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
cec3aaa56638c (Tomas Winkler 2016-08-02 14:04:39 -0700 7049) if ($realfile !~ m@^include/uapi/@ &&
cec3aaa56638c (Tomas Winkler 2016-08-02 14:04:39 -0700 7050) $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7051) my $ull = "";
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7052) $ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7053) if (CHK("BIT_MACRO",
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7054) "Prefer using the BIT$ull macro\n" . $herecurr) &&
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7055) $fix) {
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7056) $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7057) }
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7058) }
0ab9019184f1d (Joe Perches 2014-12-10 15:51:57 -0800 7059)
50161266973bc (Joe Perches 2020-08-11 18:35:07 -0700 7060) # check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 7061) if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
50161266973bc (Joe Perches 2020-08-11 18:35:07 -0700 7062) WARN("IS_ENABLED_CONFIG",
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 7063) "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
50161266973bc (Joe Perches 2020-08-11 18:35:07 -0700 7064) }
50161266973bc (Joe Perches 2020-08-11 18:35:07 -0700 7065)
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7066) # check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 7067) if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7068) my $config = $1;
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7069) if (WARN("PREFER_IS_ENABLED",
3e89ad8506f39 (Jerome Forissier 2020-10-15 20:11:49 -0700 7070) "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) &&
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7071) $fix) {
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7072) $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7073) }
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7074) }
2d6327459ec5e (Joe Perches 2016-05-20 17:04:00 -0700 7075)
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7076) # check for /* fallthrough */ like comment, prefer fallthrough;
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7077) my @fallthroughs = (
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7078) 'fallthrough',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7079) '@fallthrough@',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7080) 'lint -fallthrough[ \t]*',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7081) 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7082) '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7083) 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7084) 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7085) );
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7086) if ($raw_comment ne '') {
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7087) foreach my $ft (@fallthroughs) {
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7088) if ($raw_comment =~ /$ft/) {
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7089) my $msg_level = \&WARN;
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7090) $msg_level = \&CHK if ($file);
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7091) &{$msg_level}("PREFER_FALLTHROUGH",
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7092) "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr);
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7093) last;
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7094) }
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7095) }
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7096) }
f36d3eb89a430 (Joe Perches 2020-04-06 20:10:58 -0700 7097)
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7098) # check for switch/default statements without a break;
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 7099) if ($perl_version_ok &&
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7100) defined $stat &&
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7101) $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7102) my $cnt = statement_rawlines($stat);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 7103) my $herectx = get_stat_here($linenr, $cnt, $here);
e3d95a2a05afd (Tobin C. Harding 2018-04-10 16:33:27 -0700 7104)
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7105) WARN("DEFAULT_NO_BREAK",
d1e2ad07e78c4 (Joe Perches 2012-12-17 16:02:01 -0800 7106) "switch default: should use break\n" . $herectx);
caf2a54f101a5 (Joe Perches 2011-01-12 16:59:56 -0800 7107) }
caf2a54f101a5 (Joe Perches 2011-01-12 16:59:56 -0800 7108)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7109) # check for gcc specific __FUNCTION__
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7110) if ($line =~ /\b__FUNCTION__\b/) {
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7111) if (WARN("USE_FUNC",
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7112) "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7113) $fix) {
194f66fc95673 (Joe Perches 2014-08-06 16:11:03 -0700 7114) $fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
d5e616fc1c1dd (Joe Perches 2013-09-11 14:23:54 -0700 7115) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7116) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7117)
62ec818f55ccc (Joe Perches 2015-02-13 14:38:18 -0800 7118) # check for uses of __DATE__, __TIME__, __TIMESTAMP__
62ec818f55ccc (Joe Perches 2015-02-13 14:38:18 -0800 7119) while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) {
62ec818f55ccc (Joe Perches 2015-02-13 14:38:18 -0800 7120) ERROR("DATE_TIME",
62ec818f55ccc (Joe Perches 2015-02-13 14:38:18 -0800 7121) "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
62ec818f55ccc (Joe Perches 2015-02-13 14:38:18 -0800 7122) }
62ec818f55ccc (Joe Perches 2015-02-13 14:38:18 -0800 7123)
2c92488ab2988 (Joe Perches 2012-03-23 15:02:20 -0700 7124) # check for use of yield()
2c92488ab2988 (Joe Perches 2012-03-23 15:02:20 -0700 7125) if ($line =~ /\byield\s*\(\s*\)/) {
2c92488ab2988 (Joe Perches 2012-03-23 15:02:20 -0700 7126) WARN("YIELD",
2c92488ab2988 (Joe Perches 2012-03-23 15:02:20 -0700 7127) "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
2c92488ab2988 (Joe Perches 2012-03-23 15:02:20 -0700 7128) }
2c92488ab2988 (Joe Perches 2012-03-23 15:02:20 -0700 7129)
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7130) # check for comparisons against true and false
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7131) if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7132) my $lead = $1;
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7133) my $arg = $2;
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7134) my $test = $3;
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7135) my $otype = $4;
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7136) my $trail = $5;
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7137) my $op = "!";
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7138)
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7139) ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7140)
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7141) my $type = lc($otype);
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7142) if ($type =~ /^(?:true|false)$/) {
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7143) if (("$test" eq "==" && "$type" eq "true") ||
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7144) ("$test" eq "!=" && "$type" eq "false")) {
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7145) $op = "";
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7146) }
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7147)
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7148) CHK("BOOL_COMPARISON",
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7149) "Using comparison to $otype is error prone\n" . $herecurr);
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7150)
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7151) ## maybe suggesting a correct construct would better
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7152) ## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7153)
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7154) }
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7155) }
179f8f40fc3ae (Joe Perches 2013-07-03 15:05:30 -0700 7156)
4882720b267b7 (Thomas Gleixner 2010-09-07 14:34:01 +0000 7157) # check for semaphores initialized locked
4882720b267b7 (Thomas Gleixner 2010-09-07 14:34:01 +0000 7158) if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7159) WARN("CONSIDER_COMPLETION",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7160) "consider using a completion\n" . $herecurr);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7161) }
6712d85852b34 (Joe Perches 2012-03-23 15:02:20 -0700 7162)
67d0a0754455f (Joe Perches 2011-10-31 17:13:10 -0700 7163) # recommend kstrto* over simple_strto* and strict_strto*
67d0a0754455f (Joe Perches 2011-10-31 17:13:10 -0700 7164) if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7165) WARN("CONSIDER_KSTRTO",
67d0a0754455f (Joe Perches 2011-10-31 17:13:10 -0700 7166) "$1 is obsolete, use k$3 instead\n" . $herecurr);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7167) }
6712d85852b34 (Joe Perches 2012-03-23 15:02:20 -0700 7168)
ae3ccc4678fec (Fabian Frederick 2014-06-04 16:12:10 -0700 7169) # check for __initcall(), use device_initcall() explicitly or more appropriate function please
f3db6639fee57 (Michael Ellerman 2008-07-23 21:28:57 -0700 7170) if ($line =~ /^.\s*__initcall\s*\(/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7171) WARN("USE_DEVICE_INITCALL",
ae3ccc4678fec (Fabian Frederick 2014-06-04 16:12:10 -0700 7172) "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
f3db6639fee57 (Michael Ellerman 2008-07-23 21:28:57 -0700 7173) }
6712d85852b34 (Joe Perches 2012-03-23 15:02:20 -0700 7174)
3d709ab5a1767 (Paul E. McKenney 2018-11-11 10:49:10 -0800 7175) # check for spin_is_locked(), suggest lockdep instead
3d709ab5a1767 (Paul E. McKenney 2018-11-11 10:49:10 -0800 7176) if ($line =~ /\bspin_is_locked\(/) {
3d709ab5a1767 (Paul E. McKenney 2018-11-11 10:49:10 -0800 7177) WARN("USE_LOCKDEP",
3d709ab5a1767 (Paul E. McKenney 2018-11-11 10:49:10 -0800 7178) "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr);
3d709ab5a1767 (Paul E. McKenney 2018-11-11 10:49:10 -0800 7179) }
3d709ab5a1767 (Paul E. McKenney 2018-11-11 10:49:10 -0800 7180)
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7181) # check for deprecated apis
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7182) if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7183) my $deprecated_api = $1;
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7184) my $new_api = $deprecated_apis{$deprecated_api};
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7185) WARN("DEPRECATED_API",
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7186) "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr);
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7187) }
9189c7e706038 (Joe Perches 2018-09-07 15:26:18 -0700 7188)
0f3c5aab5e005 (Joe Perches 2015-02-13 14:39:05 -0800 7189) # check for various structs that are normally const (ops, kgdb, device_tree)
d9190e4e1a057 (Joe Perches 2017-05-08 15:55:45 -0700 7190) # and avoid what seem like struct definitions 'struct foo {'
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 7191) if (defined($const_structs) &&
ced69da1db0b5 (Quentin Monnet 2020-08-11 18:35:13 -0700 7192) $line !~ /\bconst\b/ &&
d9190e4e1a057 (Joe Perches 2017-05-08 15:55:45 -0700 7193) $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7194) WARN("CONST_STRUCT",
d9190e4e1a057 (Joe Perches 2017-05-08 15:55:45 -0700 7195) "struct $1 should normally be const\n" . $herecurr);
2b6db5cb65cb1 (Andy Whitcroft 2009-01-06 14:41:29 -0800 7196) }
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7197)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7198) # use of NR_CPUS is usually wrong
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7199) # ignore definitions of NR_CPUS and usage to define arrays as likely right
35cdcbfc5cfc3 (Peng Wang 2021-02-25 17:21:44 -0800 7200) # ignore designated initializers using NR_CPUS
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7201) if ($line =~ /\bNR_CPUS\b/ &&
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 7202) $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
c45dcabd2626c (Andy Whitcroft 2008-06-05 22:46:01 -0700 7203) $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 7204) $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
171ae1a491e21 (Andy Whitcroft 2008-04-29 00:59:32 -0700 7205) $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
35cdcbfc5cfc3 (Peng Wang 2021-02-25 17:21:44 -0800 7206) $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/ &&
35cdcbfc5cfc3 (Peng Wang 2021-02-25 17:21:44 -0800 7207) $line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/)
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7208) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7209) WARN("NR_CPUS",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7210) "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
773647a09add0 (Andy Whitcroft 2008-03-28 14:15:58 -0700 7211) }
9c9ba34ee3dbc (Andy Whitcroft 2008-04-29 00:59:33 -0700 7212)
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 7213) # Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 7214) if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 7215) ERROR("DEFINE_ARCH_HAS",
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 7216) "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 7217) }
52ea85061d188 (Joe Perches 2013-11-12 15:10:09 -0800 7218)
acd9362c248e3 (Joe Perches 2015-02-13 14:38:38 -0800 7219) # likely/unlikely comparisons similar to "(likely(foo) > 0)"
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 7220) if ($perl_version_ok &&
acd9362c248e3 (Joe Perches 2015-02-13 14:38:38 -0800 7221) $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
acd9362c248e3 (Joe Perches 2015-02-13 14:38:38 -0800 7222) WARN("LIKELY_MISUSE",
acd9362c248e3 (Joe Perches 2015-02-13 14:38:38 -0800 7223) "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
acd9362c248e3 (Joe Perches 2015-02-13 14:38:38 -0800 7224) }
acd9362c248e3 (Joe Perches 2015-02-13 14:38:38 -0800 7225)
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7226) # return sysfs_emit(foo, fmt, ...) fmt without newline
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7227) if ($line =~ /\breturn\s+sysfs_emit\s*\(\s*$FuncArg\s*,\s*($String)/ &&
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7228) substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) {
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7229) my $offset = $+[6] - 1;
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7230) if (WARN("SYSFS_EMIT",
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7231) "return sysfs_emit(...) formats should include a terminating newline\n" . $herecurr) &&
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7232) $fix) {
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7233) substr($fixed[$fixlinenr], $offset, 0) = '\\n';
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7234) }
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7235) }
fbe745416d11b (Joe Perches 2021-05-06 18:03:55 -0700 7236)
de3f186f87cf1 (Denis Efremov 2019-09-25 16:49:25 -0700 7237) # nested likely/unlikely calls
de3f186f87cf1 (Denis Efremov 2019-09-25 16:49:25 -0700 7238) if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
de3f186f87cf1 (Denis Efremov 2019-09-25 16:49:25 -0700 7239) WARN("LIKELY_MISUSE",
de3f186f87cf1 (Denis Efremov 2019-09-25 16:49:25 -0700 7240) "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr);
de3f186f87cf1 (Denis Efremov 2019-09-25 16:49:25 -0700 7241) }
de3f186f87cf1 (Denis Efremov 2019-09-25 16:49:25 -0700 7242)
691d77b6b85c2 (Andy Whitcroft 2009-01-06 14:41:16 -0800 7243) # whine mightly about in_atomic
691d77b6b85c2 (Andy Whitcroft 2009-01-06 14:41:16 -0800 7244) if ($line =~ /\bin_atomic\s*\(/) {
691d77b6b85c2 (Andy Whitcroft 2009-01-06 14:41:16 -0800 7245) if ($realfile =~ m@^drivers/@) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7246) ERROR("IN_ATOMIC",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7247) "do not use in_atomic in drivers\n" . $herecurr);
f4a8773676c21 (Andy Whitcroft 2009-02-27 14:03:05 -0800 7248) } elsif ($realfile !~ m@^kernel/@) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7249) WARN("IN_ATOMIC",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7250) "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
691d77b6b85c2 (Andy Whitcroft 2009-01-06 14:41:16 -0800 7251) }
691d77b6b85c2 (Andy Whitcroft 2009-01-06 14:41:16 -0800 7252) }
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7253)
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7254) # check for lockdep_set_novalidate_class
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7255) if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7256) $line =~ /__lockdep_no_validate__\s*\)/ ) {
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7257) if ($realfile !~ m@^kernel/lockdep@ &&
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7258) $realfile !~ m@^include/linux/lockdep@ &&
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7259) $realfile !~ m@^drivers/base/core@) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7260) ERROR("LOCKDEP",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7261) "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7262) }
1704f47b50b5d (Peter Zijlstra 2010-03-19 01:37:42 +0100 7263) }
88f8831c05585 (Dave Jones 2011-01-12 16:59:59 -0800 7264)
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 7265) if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ ||
b392c64f59d7b (Joe Perches 2015-04-16 12:44:16 -0700 7266) $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7267) WARN("EXPORTED_WORLD_WRITABLE",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7268) "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
88f8831c05585 (Dave Jones 2011-01-12 16:59:59 -0800 7269) }
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 7270)
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7271) # check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO>
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7272) # and whether or not function naming is typical and if
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7273) # DEVICE_ATTR permissions uses are unusual too
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 7274) if ($perl_version_ok &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7275) defined $stat &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7276) $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7277) my $var = $1;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7278) my $perms = $2;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7279) my $show = $3;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7280) my $store = $4;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7281) my $octal_perms = perms_to_octal($perms);
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7282) if ($show =~ /^${var}_show$/ &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7283) $store =~ /^${var}_store$/ &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7284) $octal_perms eq "0644") {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7285) if (WARN("DEVICE_ATTR_RW",
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7286) "Use DEVICE_ATTR_RW\n" . $herecurr) &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7287) $fix) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7288) $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7289) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7290) } elsif ($show =~ /^${var}_show$/ &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7291) $store =~ /^NULL$/ &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7292) $octal_perms eq "0444") {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7293) if (WARN("DEVICE_ATTR_RO",
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7294) "Use DEVICE_ATTR_RO\n" . $herecurr) &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7295) $fix) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7296) $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7297) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7298) } elsif ($show =~ /^NULL$/ &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7299) $store =~ /^${var}_store$/ &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7300) $octal_perms eq "0200") {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7301) if (WARN("DEVICE_ATTR_WO",
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7302) "Use DEVICE_ATTR_WO\n" . $herecurr) &&
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7303) $fix) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7304) $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7305) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7306) } elsif ($octal_perms eq "0644" ||
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7307) $octal_perms eq "0444" ||
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7308) $octal_perms eq "0200") {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7309) my $newshow = "$show";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7310) $newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show");
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7311) my $newstore = $store;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7312) $newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store");
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7313) my $rename = "";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7314) if ($show ne $newshow) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7315) $rename .= " '$show' to '$newshow'";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7316) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7317) if ($store ne $newstore) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7318) $rename .= " '$store' to '$newstore'";
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7319) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7320) WARN("DEVICE_ATTR_FUNCTIONS",
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7321) "Consider renaming function(s)$rename\n" . $herecurr);
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7322) } else {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7323) WARN("DEVICE_ATTR_PERMS",
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7324) "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr);
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7325) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7326) }
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7327)
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7328) # Mode permission misuses where it seems decimal should be octal
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7329) # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7330) # o Ignore module_param*(...) uses with a decimal 0 permission as that has a
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7331) # specific definition of not visible in sysfs.
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7332) # o Ignore proc_create*(...) uses with a decimal 0 permission as that means
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7333) # use the default permissions
5b57980de6b22 (Joe Perches 2018-08-21 21:57:33 -0700 7334) if ($perl_version_ok &&
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7335) defined $stat &&
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7336) $line =~ /$mode_perms_search/) {
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7337) foreach my $entry (@mode_permission_funcs) {
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7338) my $func = $entry->[0];
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7339) my $arg_pos = $entry->[1];
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7340)
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7341) my $lc = $stat =~ tr@\n@@;
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7342) $lc = $lc + $linenr;
2a9f9d851c602 (Tobin C. Harding 2018-04-10 16:33:20 -0700 7343) my $stat_real = get_stat_real($linenr, $lc);
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7344)
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7345) my $skip_args = "";
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7346) if ($arg_pos > 1) {
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7347) $arg_pos--;
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7348) $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7349) }
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 7350) my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]";
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7351) if ($stat =~ /$test/) {
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7352) my $val = $1;
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7353) $val = $6 if ($skip_args ne "");
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7354) if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") &&
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7355) (($val =~ /^$Int$/ && $val !~ /^$Octal$/) ||
73121534c963f (Joe Perches 2018-02-06 15:38:49 -0800 7356) ($val =~ /^$Octal$/ && length($val) ne 4))) {
515a235ef9bcd (Joe Perches 2014-04-03 14:49:24 -0700 7357) ERROR("NON_OCTAL_PERMISSIONS",
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7358) "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real);
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 7359) }
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 7360) if ($val =~ /^$Octal$/ && (oct($val) & 02)) {
c0a5c89858337 (Joe Perches 2015-02-13 14:38:21 -0800 7361) ERROR("EXPORTED_WORLD_WRITABLE",
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7362) "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\n" . $stat_real);
f90774e1fd270 (Joe Perches 2016-10-11 13:51:47 -0700 7363) }
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 7364) }
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 7365) }
2435880fe5cd5 (Joe Perches 2014-04-03 14:49:13 -0700 7366) }
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7367)
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7368) # check for uses of S_<PERMS> that could be octal for readability
bc22d9a7d3aa7 (Joe Perches 2018-04-10 16:33:53 -0700 7369) while ($line =~ m{\b($multi_mode_perms_string_search)\b}g) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7370) my $oval = $1;
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7371) my $octal = perms_to_octal($oval);
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7372) if (WARN("SYMBOLIC_PERMS",
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7373) "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) &&
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7374) $fix) {
001804689b0d4 (Joe Perches 2018-02-06 15:38:55 -0800 7375) $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/;
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7376) }
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7377) }
459cf0ae5d660 (Joe Perches 2016-10-11 13:52:19 -0700 7378)
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7379) # validate content of MODULE_LICENSE against list from include/linux/module.h
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7380) if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7381) my $extracted_string = get_quoted_string($line, $rawline);
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7382) my $valid_licenses = qr{
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7383) GPL|
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7384) GPL\ v2|
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7385) GPL\ and\ additional\ rights|
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7386) Dual\ BSD/GPL|
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7387) Dual\ MIT/GPL|
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7388) Dual\ MPL/GPL|
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7389) Proprietary
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7390) }x;
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7391) if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) {
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7392) WARN("MODULE_LICENSE",
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7393) "unknown module license " . $extracted_string . "\n" . $herecurr);
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7394) }
5a6d20ce19b77 (Bjorn Andersson 2015-06-25 15:03:24 -0700 7395) }
6a8d76cbd647d (Matteo Croce 2019-07-16 16:27:48 -0700 7396)
6a8d76cbd647d (Matteo Croce 2019-07-16 16:27:48 -0700 7397) # check for sysctl duplicate constants
6a8d76cbd647d (Matteo Croce 2019-07-16 16:27:48 -0700 7398) if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) {
6a8d76cbd647d (Matteo Croce 2019-07-16 16:27:48 -0700 7399) WARN("DUPLICATED_SYSCTL_CONST",
6a8d76cbd647d (Matteo Croce 2019-07-16 16:27:48 -0700 7400) "duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr);
6a8d76cbd647d (Matteo Croce 2019-07-16 16:27:48 -0700 7401) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7402) }
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7403)
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7404) # If we have no input at all, then there is nothing to report on
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7405) # so just keep quiet.
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7406) if ($#rawlines == -1) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7407) exit(0);
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7408) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7409)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7410) # In mailback mode only produce a report in the negative, for
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7411) # things that appear to be patches.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7412) if ($mailback && ($clean == 1 || !$is_patch)) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7413) exit(0);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7414) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7415)
e73d27159400f (Dwaipayan Ray 2020-12-15 20:44:56 -0800 7416) # This is not a patch, and we are in 'no-patch' mode so
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7417) # just keep quiet.
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7418) if (!$chk_patch && !$is_patch) {
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7419) exit(0);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7420) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7421)
a08ffbef4ab79 (Stafford Horne 2017-10-03 16:16:51 -0700 7422) if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7423) ERROR("NOT_UNIFIED_DIFF",
000d1cc1829f9 (Joe Perches 2011-07-25 17:13:25 -0700 7424) "Does not appear to be a unified-diff format patch\n");
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7425) }
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 7426) if ($is_patch && $has_commit_log && $chk_signoff) {
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 7427) if ($signoff == 0) {
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 7428) ERROR("MISSING_SIGN_OFF",
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 7429) "Missing Signed-off-by: line(s)\n");
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7430) } elsif ($authorsignoff != 1) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7431) # authorsignoff values:
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7432) # 0 -> missing sign off
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7433) # 1 -> sign off identical
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7434) # 2 -> names and addresses match, comments mismatch
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7435) # 3 -> addresses match, names different
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7436) # 4 -> names match, addresses different
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7437) # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7438)
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7439) my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7440)
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7441) if ($authorsignoff == 0) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7442) ERROR("NO_AUTHOR_SIGN_OFF",
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7443) "Missing Signed-off-by: line by nominal patch author '$author'\n");
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7444) } elsif ($authorsignoff == 2) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7445) CHK("FROM_SIGN_OFF_MISMATCH",
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7446) "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7447) } elsif ($authorsignoff == 3) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7448) WARN("FROM_SIGN_OFF_MISMATCH",
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7449) "From:/Signed-off-by: email name mismatch: $sob_msg\n");
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7450) } elsif ($authorsignoff == 4) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7451) WARN("FROM_SIGN_OFF_MISMATCH",
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7452) "From:/Signed-off-by: email address mismatch: $sob_msg\n");
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7453) } elsif ($authorsignoff == 5) {
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7454) WARN("FROM_SIGN_OFF_MISMATCH",
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7455) "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
48ca2d8ac8a1d (Dwaipayan Ray 2020-10-15 20:12:28 -0700 7456) }
cd2614967d8b6 (Geert Uytterhoeven 2018-08-21 21:57:40 -0700 7457) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7458) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7459)
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7460) print report_dump();
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7461) if ($summary && !($clean == 1 && $quiet == 1)) {
13214adf738ab (Andy Whitcroft 2008-02-08 04:22:03 -0800 7462) print "$filename " if ($summary_file);
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7463) print "total: $cnt_error errors, $cnt_warn warnings, " .
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7464) (($check)? "$cnt_chk checks, " : "") .
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7465) "$cnt_lines lines checked\n";
f0a594c1c74fe (Andy Whitcroft 2007-07-19 01:48:34 -0700 7466) }
8905a67c63ff3 (Andy Whitcroft 2007-11-28 16:21:06 -0800 7467)
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7468) if ($quiet == 0) {
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7469) # If there were any defects found and not already fixing them
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7470) if (!$clean and !$fix) {
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7471) print << "EOM"
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7472)
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7473) NOTE: For some of the reported defects, checkpatch may be able to
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7474) mechanically convert to the typical style using --fix or --fix-inplace.
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7475) EOM
ef212196369cb (Joe Perches 2016-05-20 17:04:11 -0700 7476) }
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7477) # If there were whitespace errors which cleanpatch can fix
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7478) # then suggest that.
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7479) if ($rpt_cleaners) {
b0781216e7bff (Mike Frysinger 2011-03-22 16:34:43 -0700 7480) $rpt_cleaners = 0;
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7481) print << "EOM"
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7482)
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7483) NOTE: Whitespace errors detected.
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7484) You may wish to use scripts/cleanpatch or scripts/cleanfile
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7485) EOM
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7486) }
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7487) }
d2c0a23514d8a (Andy Whitcroft 2010-10-26 14:23:12 -0700 7488)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 7489) if ($clean == 0 && $fix &&
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 7490) ("@rawlines" ne "@fixed" ||
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 7491) $#fixed_inserted >= 0 || $#fixed_deleted >= 0)) {
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 7492) my $newfile = $filename;
9624b8d65cd1e (Joe Perches 2014-01-23 15:54:44 -0800 7493) $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7494) my $linecount = 0;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7495) my $f;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7496)
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 7497) @fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted);
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 7498)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7499) open($f, '>', $newfile)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7500) or die "$P: Can't open $newfile for write\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7501) foreach my $fixed_line (@fixed) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7502) $linecount++;
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7503) if ($file) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7504) if ($linecount > 3) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7505) $fixed_line =~ s/^\+//;
d752fcc88b7dd (Joe Perches 2014-08-06 16:11:05 -0700 7506) print $f $fixed_line . "\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7507) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7508) } else {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7509) print $f $fixed_line . "\n";
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7510) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7511) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7512) close($f);
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7513)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7514) if (!$quiet) {
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7515) print << "EOM";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7516)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7517) Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7518)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7519) Do _NOT_ trust the results written to this file.
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7520) Do _NOT_ submit these changes without inspecting them for correctness.
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7521)
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7522) This EXPERIMENTAL file is simply a convenience to help rewrite patches.
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7523) No warranties, expressed or implied...
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7524) EOM
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7525) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7526) }
3705ce5bcc103 (Joe Perches 2013-07-03 15:05:31 -0700 7527)
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7528) if ($quiet == 0) {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7529) print "\n";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7530) if ($clean == 1) {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7531) print "$vname has no obvious style problems and is ready for submission.\n";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7532) } else {
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7533) print "$vname has style problems, please review.\n";
d8469f16207c6 (Joe Perches 2015-06-25 15:03:00 -0700 7534) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7535) }
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7536) return $clean;
0a920b5b666d0 (Andy Whitcroft 2007-06-01 00:46:48 -0700 7537) }