Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) #!/usr/bin/env perl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) # (c) 2001, Dave Jones. (the file handling bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) # (c) 2010-2018 Joe Perches <joe@perches.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) use strict;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) use warnings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) use POSIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) use File::Basename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) use Cwd 'abs_path';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) use Term::ANSIColor qw(:constants);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) use Encode qw(decode encode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) my $P = $0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) my $D = dirname(abs_path($P));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) my $V = '0.32';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) use Getopt::Long qw(:config no_auto_abbrev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) my $quiet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) my $tree = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) my $chk_signoff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) my $chk_patch = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) my $tst_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) my $emacs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) my $terse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) my $showfile = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) my $file = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) my $git = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) my %git_commits = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) my $check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) my $check_orig = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) my $summary = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) my $mailback = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) my $summary_file = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) my $show_types = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) my $list_types = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) my $fix = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) my $fix_inplace = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) my $root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) my $gitroot = $ENV{'GIT_DIR'};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) $gitroot = ".git" if !defined($gitroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) my %debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) my %camelcase = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) my %use_type = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) my @use = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) my %ignore_type = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) my @ignore = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) my $help = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) my $configuration_file = ".checkpatch.conf";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) my $max_line_length = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) my $ignore_perl_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) my $minimum_perl_version = 5.10.0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) my $min_conf_desc_length = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) my $spelling_file = "$D/spelling.txt";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) my $codespell = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) my $codespellfile = "/usr/share/codespell/dictionary.txt";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) my $conststructsfile = "$D/const_structs.checkpatch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) my $typedefsfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) my $color = "auto";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) # git output parsing needs US English output, so first set backtick child process LANGUAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) my $git_command ='export LANGUAGE=en_US.UTF-8; git';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) my $tabsize = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) my ${CONFIG_} = "CONFIG_";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) sub help {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	my ($exitcode) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	print << "EOM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) Usage: $P [OPTION]... [FILE]...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) Version: $V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) Options:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)   -q, --quiet                quiet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)   --no-tree                  run without a kernel tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)   --no-signoff               do not check for 'Signed-off-by' line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)   --patch                    treat FILE as patchfile (default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)   --emacs                    emacs compile window format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)   --terse                    one line per report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)   --showfile                 emit diffed file position, not input file position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)   -g, --git                  treat FILE as a single commit or git revision range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)                              single git commit with:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)                                <rev>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)                                <rev>^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)                                <rev>~n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)                              multiple git commits with:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)                                <rev1>..<rev2>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)                                <rev1>...<rev2>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)                                <rev>-<count>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)                              git merges are ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)   -f, --file                 treat FILE as regular source file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)   --subjective, --strict     enable more subjective tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)   --list-types               list the possible message types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)   --types TYPE(,TYPE2...)    show only these comma separated message types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)   --ignore TYPE(,TYPE2...)   ignore various comma separated message types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)   --show-types               show the specific message type in the output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)   --max-line-length=n        set the maximum line length, (default $max_line_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)                              if exceeded, warn on patches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)                              requires --strict for use with --file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)   --min-conf-desc-length=n   set the min description length, if shorter, warn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)   --tab-size=n               set the number of spaces for tab (default $tabsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)   --root=PATH                PATH to the kernel tree root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)   --no-summary               suppress the per-file summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)   --mailback                 only produce a report in case of warnings/errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)   --summary-file             include the filename in summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)   --debug KEY=[0|1]          turn on/off debugging of KEY, where KEY is one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)                              'values', 'possible', 'type', and 'attr' (default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)                              is all off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)   --test-only=WORD           report only warnings/errors containing WORD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)                              literally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)   --fix                      EXPERIMENTAL - may create horrible results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)                              If correctable single-line errors exist, create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)                              "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)                              with potential errors corrected to the preferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121)                              checkpatch style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)   --fix-inplace              EXPERIMENTAL - may create horrible results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)                              Is the same as --fix, but overwrites the input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)                              file.  It's your fault if there's no backup or git
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)   --ignore-perl-version      override checking of perl version.  expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)                              runtime errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)   --codespell                Use the codespell dictionary for spelling/typos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)                              (default:/usr/share/codespell/dictionary.txt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)   --codespellfile            Use this codespell dictionary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)   --typedefsfile             Read additional types from this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)   --color[=WHEN]             Use colors 'always', 'never', or only when output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)                              is a terminal ('auto'). Default is 'auto'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)   --kconfig-prefix=WORD      use WORD as a prefix for Kconfig symbols (default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)                              ${CONFIG_})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)   -h, --help, --version      display this help and exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) When FILE is - read standard input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) EOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	exit($exitcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) sub uniq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	my %seen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	return grep { !$seen{$_}++ } @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) sub list_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	my ($exitcode) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	my $count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	local $/ = undef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	open(my $script, '<', abs_path($P)) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	    die "$P: Can't read '$P' $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	my $text = <$script>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	close($script);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	my @types = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	# Also catch when type or level is passed through a variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	for ($text =~ /(?:(?:\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		push (@types, $_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	@types = sort(uniq(@types));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	print("#\tMessage type\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	foreach my $type (@types) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		print(++$count . "\t" . $type . "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	exit($exitcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) my $conf = which_conf($configuration_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) if (-f $conf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	my @conf_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	open(my $conffile, '<', "$conf")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	    or warn "$P: Can't find a readable $configuration_file file $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	while (<$conffile>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		my $line = $_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		$line =~ s/\s*\n?$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		$line =~ s/^\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		$line =~ s/\s+/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		next if ($line =~ m/^\s*#/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		next if ($line =~ m/^\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		my @words = split(" ", $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		foreach my $word (@words) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			last if ($word =~ m/^#/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 			push (@conf_args, $word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	close($conffile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	unshift(@ARGV, @conf_args) if @conf_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) # Perl's Getopt::Long allows options to take optional arguments after a space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) # Prevent --color by itself from consuming other arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) foreach (@ARGV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	if ($_ eq "--color" || $_ eq "-color") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		$_ = "--color=$color";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) GetOptions(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	'q|quiet+'	=> \$quiet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	'tree!'		=> \$tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	'signoff!'	=> \$chk_signoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	'patch!'	=> \$chk_patch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	'emacs!'	=> \$emacs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	'terse!'	=> \$terse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	'showfile!'	=> \$showfile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	'f|file!'	=> \$file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	'g|git!'	=> \$git,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	'subjective!'	=> \$check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	'strict!'	=> \$check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	'ignore=s'	=> \@ignore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	'types=s'	=> \@use,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	'show-types!'	=> \$show_types,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	'list-types!'	=> \$list_types,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	'max-line-length=i' => \$max_line_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	'min-conf-desc-length=i' => \$min_conf_desc_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	'tab-size=i'	=> \$tabsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	'root=s'	=> \$root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	'summary!'	=> \$summary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	'mailback!'	=> \$mailback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	'summary-file!'	=> \$summary_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	'fix!'		=> \$fix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	'fix-inplace!'	=> \$fix_inplace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	'ignore-perl-version!' => \$ignore_perl_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	'debug=s'	=> \%debug,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	'test-only=s'	=> \$tst_only,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	'codespell!'	=> \$codespell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	'codespellfile=s'	=> \$codespellfile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	'typedefsfile=s'	=> \$typedefsfile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	'color=s'	=> \$color,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	'no-color'	=> \$color,	#keep old behaviors of -nocolor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	'nocolor'	=> \$color,	#keep old behaviors of -nocolor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	'kconfig-prefix=s'	=> \${CONFIG_},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	'h|help'	=> \$help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	'version'	=> \$help
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) ) or help(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) help(0) if ($help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) list_types(0) if ($list_types);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) $fix = 1 if ($fix_inplace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) $check_orig = $check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) my $exit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) my $perl_version_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) if ($^V && $^V lt $minimum_perl_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	$perl_version_ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	exit(1) if (!$ignore_perl_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) #if no filenames are given, push '-' to read patch from stdin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) if ($#ARGV < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	push(@ARGV, '-');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) if ($color =~ /^[01]$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	$color = !$color;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) } elsif ($color =~ /^always$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	$color = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) } elsif ($color =~ /^never$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	$color = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) } elsif ($color =~ /^auto$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	$color = (-t STDOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	die "$P: Invalid color mode: $color\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) # skip TAB size 1 to avoid additional checks on $tabsize - 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) die "$P: Invalid TAB size: $tabsize\n" if ($tabsize < 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) sub hash_save_array_words {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	my ($hashRef, $arrayRef) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	my @array = split(/,/, join(',', @$arrayRef));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	foreach my $word (@array) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		$word =~ s/\s*\n?$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		$word =~ s/^\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		$word =~ s/\s+/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		$word =~ tr/[a-z]/[A-Z]/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		next if ($word =~ m/^\s*#/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		next if ($word =~ m/^\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		$hashRef->{$word}++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) sub hash_show_words {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	my ($hashRef, $prefix) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	if (keys %$hashRef) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		print "\nNOTE: $prefix message types:";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		foreach my $word (sort keys %$hashRef) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			print " $word";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		print "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) hash_save_array_words(\%ignore_type, \@ignore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) hash_save_array_words(\%use_type, \@use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) my $dbg_values = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) my $dbg_possible = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) my $dbg_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) my $dbg_attr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) for my $key (keys %debug) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	## no critic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	eval "\${dbg_$key} = '$debug{$key}';";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	die "$@" if ($@);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) my $rpt_cleaners = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) if ($terse) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	$emacs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	$quiet++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) if ($tree) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	if (defined $root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		if (!top_of_kernel_tree($root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			die "$P: $root: --root does not point at a valid tree\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		if (top_of_kernel_tree('.')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			$root = '.';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		} elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 						top_of_kernel_tree($1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			$root = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	if (!defined $root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		print "Must be run from the top-level dir. of a kernel tree\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		exit(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) my $emitted_corrupt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) our $Ident	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 			[A-Za-z_][A-Za-z\d_]*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			(?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) our $Storage	= qr{extern|static|asmlinkage};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) our $Sparse	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			__user|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			__kernel|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			__force|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			__iomem|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			__must_check|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			__kprobes|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			__ref|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			__refconst|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			__refdata|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			__rcu|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			__private
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) # Notes to $Attribute:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) our $Attribute	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			const|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			__percpu|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			__nocast|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			__safe|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			__bitwise|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			__packed__|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 			__packed2__|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			__naked|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			__maybe_unused|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			__always_unused|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			__noreturn|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			__used|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			__cold|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 			__pure|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			__noclone|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 			__deprecated|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			__read_mostly|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 			__ro_after_init|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 			__kprobes|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 			$InitAttribute|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			____cacheline_aligned|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			____cacheline_aligned_in_smp|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 			____cacheline_internodealigned_in_smp|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			__weak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) our $Modifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) our $Inline	= qr{inline|__always_inline|noinline|__inline|__inline__};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) our $Member	= qr{->$Ident|\.$Ident|\[[^]]*\]};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) our $Lval	= qr{$Ident(?:$Member)*};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) our $Int_type	= qr{(?i)llu|ull|ll|lu|ul|l|u};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) our $Binary	= qr{(?i)0b[01]+$Int_type?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) our $Hex	= qr{(?i)0x[0-9a-f]+$Int_type?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) our $Int	= qr{[0-9]+$Int_type?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) our $Octal	= qr{0[0-7]+$Int_type?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) our $String	= qr{"[X\t]*"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) our $Float_hex	= qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) our $Float_dec	= qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) our $Float_int	= qr{(?i)[0-9]+e-?[0-9]+[fl]?};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) our $Float	= qr{$Float_hex|$Float_dec|$Float_int};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) our $Constant	= qr{$Float|$Binary|$Octal|$Hex|$Int};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) our $Assignment	= qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) our $Compare    = qr{<=|>=|==|!=|<|(?<!-)>};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) our $Arithmetic = qr{\+|-|\*|\/|%};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) our $Operators	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 			<=|>=|==|!=|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			=>|->|<<|>>|<|>|!|~|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			&&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) our $BasicType;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) our $NonptrType;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) our $NonptrTypeMisordered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) our $NonptrTypeWithAttr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) our $Type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) our $TypeMisordered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) our $Declare;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) our $DeclareMisordered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) our $NON_ASCII_UTF8	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	[\xC2-\xDF][\x80-\xBF]               # non-overlong 2-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	|  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	|  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	|  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	| [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	|  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) our $UTF8	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	[\x09\x0A\x0D\x20-\x7E]              # ASCII
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	| $NON_ASCII_UTF8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) our $typeOtherOSTypedefs = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	u_(?:char|short|int|long) |          # bsd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	u(?:nchar|short|int|long)            # sysv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) our $typeKernelTypedefs = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	(?:__)?(?:u|s|be|le)(?:8|16|32|64)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	atomic_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) our $typeTypedefs = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	$typeC99Typedefs\b|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	$typeOtherOSTypedefs\b|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	$typeKernelTypedefs\b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) our $logFunctions = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	printk(?:_ratelimited|_once|_deferred_once|_deferred|)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	TP_printk|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	WARN(?:_RATELIMIT|_ONCE|)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	panic|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	MODULE_[A-Z_]+|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	seq_vprintf|seq_printf|seq_puts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) our $allocFunctions = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	(?:(?:devm_)?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		(?:kv|k|v)[czm]alloc(?:_node|_array)? |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		kstrdup(?:_const)? |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		kmemdup(?:_nul)?) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	(?:\w+)?alloc_skb(?:_ip_align)? |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				# dev_alloc_skb/netdev_alloc_skb, et al
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	dma_alloc_coherent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) our $signature_tags = qr{(?xi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	Signed-off-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	Co-developed-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	Acked-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	Tested-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	Reviewed-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	Reported-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	Suggested-by:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	To:|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	Cc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) our @typeListMisordered = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	qr{char\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	qr{int\s+(?:(?:un)?signed\s+)?short\s},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	qr{int\s+short(?:\s+(?:un)?signed)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	qr{short\s+int(?:\s+(?:un)?signed)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	qr{(?:un)?signed\s+int\s+short},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	qr{short\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	qr{long\s+int\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	qr{int\s+long\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	qr{long\s+(?:un)?signed\s+int},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	qr{int\s+(?:un)?signed\s+long},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	qr{int\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	qr{int\s+long\s+long\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	qr{long\s+long\s+int\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	qr{long\s+long\s+(?:un)?signed\s+int},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	qr{long\s+long\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	qr{long\s+(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) our @typeList = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	qr{void},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	qr{(?:(?:un)?signed\s+)?char},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	qr{(?:(?:un)?signed\s+)?short\s+int},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	qr{(?:(?:un)?signed\s+)?short},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	qr{(?:(?:un)?signed\s+)?int},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	qr{(?:(?:un)?signed\s+)?long\s+int},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	qr{(?:(?:un)?signed\s+)?long\s+long},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	qr{(?:(?:un)?signed\s+)?long},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	qr{(?:un)?signed},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	qr{float},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	qr{double},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	qr{bool},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	qr{struct\s+$Ident},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	qr{union\s+$Ident},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	qr{enum\s+$Ident},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	qr{${Ident}_t},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	qr{${Ident}_handler},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	qr{${Ident}_handler_fn},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	@typeListMisordered,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) our $C90_int_types = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	long\s+long\s+int\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	long\s+long\s+(?:un)?signed\s+int|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	long\s+long\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	(?:(?:un)?signed\s+)?long\s+long\s+int|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	(?:(?:un)?signed\s+)?long\s+long|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	int\s+long\s+long\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	int\s+(?:(?:un)?signed\s+)?long\s+long|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	long\s+int\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	long\s+(?:un)?signed\s+int|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	long\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	(?:(?:un)?signed\s+)?long\s+int|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	(?:(?:un)?signed\s+)?long|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	int\s+long\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	int\s+(?:(?:un)?signed\s+)?long|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	int\s+(?:un)?signed|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	(?:(?:un)?signed\s+)?int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) our @typeListFile = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) our @typeListWithAttr = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	@typeList,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	qr{struct\s+$InitAttribute\s+$Ident},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	qr{union\s+$InitAttribute\s+$Ident},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) our @modifierList = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	qr{fastcall},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) our @modifierListFile = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) our @mode_permission_funcs = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	["module_param", 3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	["module_param_(?:array|named|string)", 4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	["module_param_array_named", 5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	["proc_create(?:_data|)", 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	["IIO_DEV_ATTR_[A-Z_]+", 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	["SENSOR_(?:DEVICE_|)ATTR_2", 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	["SENSOR_TEMPLATE(?:_2|)", 3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	["__ATTR", 2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) #Create a search pattern for all these functions to speed up a loop below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) our $mode_perms_search = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) foreach my $entry (@mode_permission_funcs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	$mode_perms_search .= '|' if ($mode_perms_search ne "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	$mode_perms_search .= $entry->[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) $mode_perms_search = "(?:${mode_perms_search})";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) our %deprecated_apis = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	"synchronize_rcu_bh"			=> "synchronize_rcu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	"synchronize_rcu_bh_expedited"		=> "synchronize_rcu_expedited",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	"call_rcu_bh"				=> "call_rcu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	"rcu_barrier_bh"			=> "rcu_barrier",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	"synchronize_sched"			=> "synchronize_rcu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	"synchronize_sched_expedited"		=> "synchronize_rcu_expedited",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	"call_rcu_sched"			=> "call_rcu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	"rcu_barrier_sched"			=> "rcu_barrier",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	"get_state_synchronize_sched"		=> "get_state_synchronize_rcu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	"cond_synchronize_sched"		=> "cond_synchronize_rcu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) #Create a search pattern for all these strings to speed up a loop below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) our $deprecated_apis_search = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) foreach my $entry (keys %deprecated_apis) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	$deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	$deprecated_apis_search .= $entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) $deprecated_apis_search = "(?:${deprecated_apis_search})";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) our $mode_perms_world_writable = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	S_IWUGO		|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	S_IWOTH		|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	S_IRWXUGO	|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	S_IALLUGO	|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	0[0-7][0-7][2367]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) our %mode_permission_string_types = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	"S_IRWXU" => 0700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	"S_IRUSR" => 0400,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	"S_IWUSR" => 0200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	"S_IXUSR" => 0100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	"S_IRWXG" => 0070,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	"S_IRGRP" => 0040,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	"S_IWGRP" => 0020,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	"S_IXGRP" => 0010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	"S_IRWXO" => 0007,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	"S_IROTH" => 0004,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	"S_IWOTH" => 0002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	"S_IXOTH" => 0001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	"S_IRWXUGO" => 0777,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	"S_IRUGO" => 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	"S_IWUGO" => 0222,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	"S_IXUGO" => 0111,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) #Create a search pattern for all these strings to speed up a loop below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) our $mode_perms_string_search = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) foreach my $entry (keys %mode_permission_string_types) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	$mode_perms_string_search .= '|' if ($mode_perms_string_search ne "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	$mode_perms_string_search .= $entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) our $single_mode_perms_string_search = "(?:${mode_perms_string_search})";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) our $multi_mode_perms_string_search = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	${single_mode_perms_string_search}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	(?:\s*\|\s*${single_mode_perms_string_search})*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) sub perms_to_octal {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	my ($string) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	my $val = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	my $oval = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	my $to = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	my $curpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	my $lastpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		$curpos = pos($string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		my $match = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		my $omatch = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		$lastpos = $curpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		$to |= $mode_permission_string_types{$match};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		$val .= '\s*\|\s*' if ($val ne "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		$val .= $match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		$oval .= $omatch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	$oval =~ s/^\s*\|\s*//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	$oval =~ s/\s*\|\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	return sprintf("%04o", $to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) our $allowed_asm_includes = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	irq|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	memory|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	time|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	reboot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) # memory.h: ARM has a custom one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) # Load common spelling mistakes and build regular expression list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) my $misspellings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) my %spelling_fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) if (open(my $spelling, '<', $spelling_file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	while (<$spelling>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		my $line = $_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		$line =~ s/\s*\n?$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		$line =~ s/^\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		next if ($line =~ m/^\s*#/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		next if ($line =~ m/^\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		my ($suspect, $fix) = split(/\|\|/, $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		$spelling_fix{$suspect} = $fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	close($spelling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	warn "No typos will be found - file '$spelling_file': $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) if ($codespell) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (open(my $spelling, '<', $codespellfile)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		while (<$spelling>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 			my $line = $_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			$line =~ s/\s*\n?$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 			$line =~ s/^\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			next if ($line =~ m/^\s*#/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			next if ($line =~ m/^\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 			next if ($line =~ m/, disabled/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 			$line =~ s/,.*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			my ($suspect, $fix) = split(/->/, $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			$spelling_fix{$suspect} = $fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		close($spelling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		warn "No codespell typos will be found - file '$codespellfile': $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) sub read_words {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	my ($wordsRef, $file) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (open(my $words, '<', $file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		while (<$words>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			my $line = $_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			$line =~ s/\s*\n?$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			$line =~ s/^\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 			next if ($line =~ m/^\s*#/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			next if ($line =~ m/^\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			if ($line =~ /\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 				print("$file: '$line' invalid - ignored\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 				next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 			$$wordsRef .= '|' if (defined $$wordsRef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 			$$wordsRef .= $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		close($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) my $const_structs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) if (show_type("CONST_STRUCT")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	read_words(\$const_structs, $conststructsfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	    or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) if (defined($typedefsfile)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	my $typeOtherTypedefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	read_words(\$typeOtherTypedefs, $typedefsfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	    or warn "No additional types will be considered - file '$typedefsfile': $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	$typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) sub build_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	my $mods = "(?x:  \n" . join("|\n  ", (@modifierList, @modifierListFile)) . "\n)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	my $all = "(?x:  \n" . join("|\n  ", (@typeList, @typeListFile)) . "\n)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	my $Misordered = "(?x:  \n" . join("|\n  ", @typeListMisordered) . "\n)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	my $allWithAttr = "(?x:  \n" . join("|\n  ", @typeListWithAttr) . "\n)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	$Modifier	= qr{(?:$Attribute|$Sparse|$mods)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	$BasicType	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 				(?:$typeTypedefs\b)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 				(?:${all}\b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	$NonptrType	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 			(?:$Modifier\s+|const\s+)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 				(?:typeof|__typeof__)\s*\([^\)]*\)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 				(?:$typeTypedefs\b)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 				(?:${all}\b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 			(?:\s+$Modifier|\s+const)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	$NonptrTypeMisordered	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			(?:$Modifier\s+|const\s+)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 				(?:${Misordered}\b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 			(?:\s+$Modifier|\s+const)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	$NonptrTypeWithAttr	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			(?:$Modifier\s+|const\s+)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 				(?:typeof|__typeof__)\s*\([^\)]*\)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 				(?:$typeTypedefs\b)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 				(?:${allWithAttr}\b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 			)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 			(?:\s+$Modifier|\s+const)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	$Type	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			$NonptrType
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			(?:\s+$Inline|\s+$Modifier)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	$TypeMisordered	= qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			$NonptrTypeMisordered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			(?:\s+$Inline|\s+$Modifier)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		  }x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	$Declare	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	$DeclareMisordered	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) build_types();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) our $Typecast	= qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) # Using $balanced_parens, $LvalOrFunc, or $FuncArg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) # requires at least perl version v5.10.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) # Any use must be runtime checked with $^V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) our $LvalOrFunc	= qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) our $declaration_macros = qr{(?x:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	(?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	(?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	(?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) )};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) sub deparenthesize {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	my ($string) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return "" if (!defined($string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	while ($string =~ /^\s*\(.*\)\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		$string =~ s@^\s*\(\s*@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		$string =~ s@\s*\)\s*$@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	$string =~ s@\s+@ @g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	return $string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) sub seed_camelcase_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	my ($file) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	return if (!(-f $file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	local $/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	open(my $include_file, '<', "$file")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	    or warn "$P: Can't read '$file' $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	my $text = <$include_file>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	close($include_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	my @lines = split('\n', $text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	foreach my $line (@lines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			$camelcase{$1} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		} elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			$camelcase{$1} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		} elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 			$camelcase{$1} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) our %maintained_status = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) sub is_maintained_obsolete {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	my ($filename) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	if (!exists($maintained_status{$filename})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		$maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	return $maintained_status{$filename} =~ /obsolete/i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) sub is_SPDX_License_valid {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	my ($license) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	my $root_path = abs_path($root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	return 0 if ($status ne "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) my $camelcase_seeded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) sub seed_camelcase_includes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	return if ($camelcase_seeded);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	my $files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	my $camelcase_cache = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	my @include_files = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	$camelcase_seeded = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	if (-e "$gitroot") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		chomp $git_last_include_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		$camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		my $last_mod_date = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		$files = `find $root/include -name "*.h"`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		@include_files = split('\n', $files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		foreach my $file (@include_files) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			my $date = POSIX::strftime("%Y%m%d%H%M",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 						   localtime((stat $file)[9]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 			$last_mod_date = $date if ($last_mod_date < $date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		$camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	if ($camelcase_cache ne "" && -f $camelcase_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		open(my $camelcase_file, '<', "$camelcase_cache")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		    or warn "$P: Can't read '$camelcase_cache' $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		while (<$camelcase_file>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			chomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			$camelcase{$_} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		close($camelcase_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	if (-e "$gitroot") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		$files = `${git_command} ls-files "include/*.h"`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		@include_files = split('\n', $files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	foreach my $file (@include_files) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		seed_camelcase_file($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	if ($camelcase_cache ne "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		unlink glob ".checkpatch-camelcase.*";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		open(my $camelcase_file, '>', "$camelcase_cache")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		    or warn "$P: Can't write '$camelcase_cache' $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			print $camelcase_file ("$_\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		close($camelcase_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) sub git_is_single_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	my ($filename) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	return 0 if ((which("git") eq "") || !(-e "$gitroot"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	my $count = $output =~ tr/\n//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	return $count eq 1 && $output =~ m{^${filename}$};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) sub git_commit_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	my ($commit, $id, $desc) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	$output =~ s/^\s*//gm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	my @lines = split("\n", $output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	return ($id, $desc) if ($#lines < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) # Maybe one day convert this block of bash into something that returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) # all matching commit ids, but it's very slow...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) #		echo "checking commits $1..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) #		git rev-list --remotes | grep -i "^$1" |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) #		while read line ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) #		    git log --format='%H %s' -1 $line |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) #		    echo "commit $(cut -c 1-12,41-)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) #		done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	} elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		$id = undef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		$id = substr($lines[0], 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		$desc = substr($lines[0], 41);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	return ($id, $desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) $chk_signoff = 0 if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) my @rawlines = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) my @lines = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) my @fixed = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) my @fixed_inserted = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) my @fixed_deleted = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) my $fixlinenr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) # If input is git commits, extract all commits from the commit expressions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) die "$P: No git repository found\n" if ($git && !-e "$gitroot");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if ($git) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	my @commits = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	foreach my $commit_expr (@ARGV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		my $git_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		if ($commit_expr =~ m/^(.*)-(\d+)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			$git_range = "-$2 $1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		} elsif ($commit_expr =~ m/\.\./) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			$git_range = "$commit_expr";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 			$git_range = "-1 $commit_expr";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		foreach my $line (split(/\n/, $lines)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			$line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			next if (!defined($1) || !defined($2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			my $sha1 = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			my $subject = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			unshift(@commits, $sha1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			$git_commits{$sha1} = $subject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	die "$P: no git commits after extraction!\n" if (@commits == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	@ARGV = @commits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) my $vname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) $allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) for my $filename (@ARGV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	my $FILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	my $is_git_file = git_is_single_file($filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	my $oldfile = $file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	$file = 1 if ($is_git_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if ($git) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 			die "$P: $filename: git format-patch failed - $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	} elsif ($file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		open($FILE, '-|', "diff -u /dev/null $filename") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			die "$P: $filename: diff failed - $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	} elsif ($filename eq '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		open($FILE, '<&STDIN');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		open($FILE, '<', "$filename") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			die "$P: $filename: open failed - $!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	if ($filename eq '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		$vname = 'Your patch';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	} elsif ($git) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		$vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		$vname = $filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	while (<$FILE>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		chomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		push(@rawlines, $_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		$vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	close($FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	if ($#ARGV > 0 && $quiet == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		print '-' x length($vname) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		print "$vname\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		print '-' x length($vname) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	if (!process($filename)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		$exit = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	@rawlines = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	@lines = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	@fixed = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	@fixed_inserted = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	@fixed_deleted = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	$fixlinenr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	@modifierListFile = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	@typeListFile = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	build_types();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	$file = $oldfile if ($is_git_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if (!$quiet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	hash_show_words(\%use_type, "Used");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	hash_show_words(\%ignore_type, "Ignored");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	if (!$perl_version_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		print << "EOM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) NOTE: perl $^V is not modern enough to detect all possible issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)       An upgrade to at least perl $minimum_perl_version is suggested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) EOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	if ($exit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		print << "EOM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) NOTE: If any of the errors are false positives, please report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)       them to the maintainer, see CHECKPATCH in MAINTAINERS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) EOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) exit($exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) sub top_of_kernel_tree {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	my ($root) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	my @tree_check = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		"COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		"README", "Documentation", "arch", "include", "drivers",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		"fs", "init", "ipc", "kernel", "lib", "scripts",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	foreach my $check (@tree_check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		if (! -e $root . '/' . $check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) sub parse_email {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	my ($formatted_email) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	my $name = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	my $name_comment = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	my $address = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	my $comment = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		$name = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		$address = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		$comment = $3 if defined $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	} elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		$address = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		$comment = $2 if defined $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	} elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		$address = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		$comment = $2 if defined $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		$formatted_email =~ s/\Q$address\E.*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		$name = $formatted_email;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		$name = trim($name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		$name =~ s/^\"|\"$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		# If there's a name left after stripping spaces and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		# leading quotes, and the address doesn't have both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		# leading and trailing angle brackets, the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		# is invalid. ie:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		#   "joe smith joe@smith.com" bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		#   "joe smith <joe@smith.com" bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		if ($name ne "" && $address !~ /^<[^>]+>$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			$name = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 			$address = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 			$comment = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	$comment = trim($comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	$name = trim($name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	$name =~ s/^\"|\"$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	if ($name =~ s/(\s*\([^\)]+\))\s*//) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		$name_comment = trim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	$address = trim($address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	$address =~ s/^\<|\>$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		$name = "\"$name\"";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	return ($name, $name_comment, $address, $comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) sub format_email {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	my ($name, $name_comment, $address, $comment) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	my $formatted_email;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	$name_comment = trim($name_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	$comment = trim($comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	$name = trim($name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	$name =~ s/^\"|\"$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	$address = trim($address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		$name = "\"$name\"";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	if ("$name" eq "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		$formatted_email = "$address";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		$formatted_email = "$name$name_comment <$address>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	$formatted_email .= "$comment";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	return $formatted_email;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) sub reformat_email {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	my ($email) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	return format_email($email_name, $name_comment, $email_address, $comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) sub same_email_addresses {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	my ($email1, $email2, $match_comment) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	if ($match_comment != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		return $email1_name eq $email2_name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		       $email1_address eq $email2_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	return $email1_name eq $email2_name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	       $email1_address eq $email2_address &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	       $name1_comment eq $name2_comment &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	       $comment1 eq $comment2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) sub which {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	my ($bin) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	foreach my $path (split(/:/, $ENV{PATH})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 		if (-e "$path/$bin") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 			return "$path/$bin";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	return "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) sub which_conf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	my ($conf) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		if (-e "$path/$conf") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 			return "$path/$conf";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	return "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) sub expand_tabs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	my ($str) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	my $res = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	my $n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	for my $c (split(//, $str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		if ($c eq "\t") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 			$res .= ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 			$n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 			for (; ($n % $tabsize) != 0; $n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 				$res .= ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		$res .= $c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		$n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	return $res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) sub copy_spacing {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	(my $res = shift) =~ tr/\t/ /c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	return $res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) sub line_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	my ($line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	# Drop the diff line leader and expand tabs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	$line =~ s/^.//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	$line = expand_tabs($line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	# Pick the indent from the front of the line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	my ($white) = ($line =~ /^(\s*)/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	return (length($line), length($white));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) my $sanitise_quote = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) sub sanitise_line_reset {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	my ($in_comment) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	if ($in_comment) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		$sanitise_quote = '*/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		$sanitise_quote = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) sub sanitise_line {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	my ($line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	my $res = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	my $l = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	my $qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	my $off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	my $c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	# Always copy over the diff marker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	$res = substr($line, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	for ($off = 1; $off < length($line); $off++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		$c = substr($line, $off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		# Comments we are whacking completely including the begin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 		# and end, all to $;.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 			$sanitise_quote = '*/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 			substr($res, $off, 2, "$;$;");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 			$sanitise_quote = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 			substr($res, $off, 2, "$;$;");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 			$sanitise_quote = '//';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 			substr($res, $off, 2, $sanitise_quote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		# A \ in a string means ignore the next character.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		    $c eq "\\") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			substr($res, $off, 2, 'XX');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		# Regular quotes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		if ($c eq "'" || $c eq '"') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			if ($sanitise_quote eq '') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 				$sanitise_quote = $c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 				substr($res, $off, 1, $c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 				next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			} elsif ($sanitise_quote eq $c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 				$sanitise_quote = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		#print "c<$c> SQ<$sanitise_quote>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 			substr($res, $off, 1, $;);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		} elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			substr($res, $off, 1, $;);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		} elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 			substr($res, $off, 1, 'X');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 			substr($res, $off, 1, $c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	if ($sanitise_quote eq '//') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		$sanitise_quote = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	# The pathname on a #include may be surrounded by '<' and '>'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		my $clean = 'X' x length($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		$res =~ s@\<.*\>@<$clean>@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	# The whole of a #error is a string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	} elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		my $clean = 'X' x length($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		$res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	if ($allow_c99_comments && $res =~ m@(//.*$)@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		my $match = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		$res =~ s/\Q$match\E/"$;" x length($match)/e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	return $res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) sub get_quoted_string {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	my ($line, $rawline) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	return "" if (!defined($line) || !defined($rawline));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	return "" if ($line !~ m/($String)/g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	return substr($rawline, $-[0], $+[0] - $-[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) sub ctx_statement_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	my ($linenr, $remain, $off) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	my $line = $linenr - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	my $blk = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	my $soff = $off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	my $coff = $off - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	my $coff_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	my $loff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	my $type = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	my $level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	my @stack = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	my $p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	my $c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	my $len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	my $remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		@stack = (['', 0]) if ($#stack == -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		#warn "CSB: blk<$blk> remain<$remain>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		# If we are about to drop off the end, pull in more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		# context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		if ($off >= $len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 			for (; $remain > 0; $line++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 				last if (!defined $lines[$line]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 				next if ($lines[$line] =~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 				$remain--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 				$loff = $len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 				$blk .= $lines[$line] . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 				$len = length($blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 				$line++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 				last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 			# Bail if there is no further context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 			#warn "CSB: blk<$blk> off<$off> len<$len>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 			if ($off >= $len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 				last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 			if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 				$level++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 				$type = '#';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		$p = $c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		$c = substr($blk, $off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		$remainder = substr($blk, $off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		#warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		# Handle nested #if/#else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			push(@stack, [ $type, $level ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		} elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			($type, $level) = @{$stack[$#stack - 1]};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		} elsif ($remainder =~ /^#\s*endif\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 			($type, $level) = @{pop(@stack)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		# Statement ends at the ';' or a close '}' at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		# outermost level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		if ($level == 0 && $c eq ';') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 			last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		# An else is really a conditional as long as its not else if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		if ($level == 0 && $coff_set == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 				(!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 				$remainder =~ /^(else)(?:\s|{)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 				$remainder !~ /^else\s+if\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			$coff = $off + length($1) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 			$coff_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 			#warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 			#warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		if (($type eq '' || $type eq '(') && $c eq '(') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 			$level++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 			$type = '(';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		if ($type eq '(' && $c eq ')') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 			$level--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 			$type = ($level != 0)? '(' : '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 			if ($level == 0 && $coff < $soff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 				$coff = $off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 				$coff_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 				#warn "CSB: mark coff<$coff>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 		if (($type eq '' || $type eq '{') && $c eq '{') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 			$level++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 			$type = '{';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		if ($type eq '{' && $c eq '}') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 			$level--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			$type = ($level != 0)? '{' : '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			if ($level == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 				if (substr($blk, $off + 1, 1) eq ';') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 					$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 				last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		# Preprocessor commands end at the newline unless escaped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		if ($type eq '#' && $c eq "\n" && $p ne "\\") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 			$level--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			$type = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 			$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 		$off++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	# We are truly at the end, so shuffle to the next line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	if ($off == $len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		$loff = $len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		$line++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		$remain--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	my $statement = substr($blk, $soff, $off - $soff + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	my $condition = substr($blk, $soff, $coff - $soff + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	#warn "STATEMENT<$statement>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	#warn "CONDITION<$condition>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	#print "coff<$coff> soff<$off> loff<$loff>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	return ($statement, $condition,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 			$line, $remain + 1, $off - $loff + 1, $level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) sub statement_lines {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	my ($stmt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	# Strip the diff line prefixes and rip blank lines at start and end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	$stmt =~ s/(^|\n)./$1/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	$stmt =~ s/^\s*//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	$stmt =~ s/\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	my @stmt_lines = ($stmt =~ /\n/g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	return $#stmt_lines + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) sub statement_rawlines {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	my ($stmt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	my @stmt_lines = ($stmt =~ /\n/g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	return $#stmt_lines + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) sub statement_block_size {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	my ($stmt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	$stmt =~ s/(^|\n)./$1/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	$stmt =~ s/^\s*{//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	$stmt =~ s/}\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	$stmt =~ s/^\s*//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	$stmt =~ s/\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	my @stmt_lines = ($stmt =~ /\n/g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	my @stmt_statements = ($stmt =~ /;/g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	my $stmt_lines = $#stmt_lines + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	my $stmt_statements = $#stmt_statements + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	if ($stmt_lines > $stmt_statements) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 		return $stmt_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		return $stmt_statements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) sub ctx_statement_full {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	my ($linenr, $remain, $off) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	my ($statement, $condition, $level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	my (@chunks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	# Grab the first conditional/block pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	($statement, $condition, $linenr, $remain, $off, $level) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 				ctx_statement_block($linenr, $remain, $off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	#print "F: c<$condition> s<$statement> remain<$remain>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	push(@chunks, [ $condition, $statement ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		return ($level, $linenr, @chunks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	# Pull in the following conditional/block pairs and see if they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	# could continue the statement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		($statement, $condition, $linenr, $remain, $off, $level) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 				ctx_statement_block($linenr, $remain, $off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		#print "C: c<$condition> s<$statement> remain<$remain>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		#print "C: push\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		push(@chunks, [ $condition, $statement ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	return ($level, $linenr, @chunks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) sub ctx_block_get {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	my ($linenr, $remain, $outer, $open, $close, $off) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	my $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	my $start = $linenr - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	my $blk = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	my @o;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	my @c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	my @res = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	my $level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	my @stack = ($level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	for ($line = $start; $remain > 0; $line++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		next if ($rawlines[$line] =~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		$remain--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		$blk .= $rawlines[$line];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		# Handle nested #if/#else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 			push(@stack, $level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 		} elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			$level = $stack[$#stack - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		} elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 			$level = pop(@stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		foreach my $c (split(//, $lines[$line])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 			##print "C<$c>L<$level><$open$close>O<$off>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 			if ($off > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 				$off--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 				next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 			if ($c eq $close && $level > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 				$level--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 				last if ($level == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 			} elsif ($c eq $open) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 				$level++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		if (!$outer || $level <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 			push(@res, $rawlines[$line]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 		last if ($level == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	return ($level, @res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) sub ctx_block_outer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	my ($linenr, $remain) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	return @r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) sub ctx_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	my ($linenr, $remain) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	return @r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) sub ctx_statement {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	my ($linenr, $remain, $off) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	return @r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) sub ctx_block_level {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	my ($linenr, $remain) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) sub ctx_statement_level {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	my ($linenr, $remain, $off) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) sub ctx_locate_comment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	my ($first_line, $end_line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	# If c99 comment on the current line, or the line before or after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	return $current_comment if (defined $current_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	return $current_comment if (defined $current_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	($current_comment) = ($rawlines[$end_line] =~ m@^[\+ ].*(//.*$)@);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	return $current_comment if (defined $current_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	# Catch a comment on the end of the line itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	return $current_comment if (defined $current_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	# Look through the context and try and figure out if there is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	# comment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	my $in_comment = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	$current_comment = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 		my $line = $rawlines[$linenr - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		#warn "           $line\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 			$in_comment = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 		if ($line =~ m@/\*@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 			$in_comment = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		if (!$in_comment && $current_comment ne '') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			$current_comment = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		$current_comment .= $line . "\n" if ($in_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		if ($line =~ m@\*/@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 			$in_comment = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	chomp($current_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	return($current_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) sub ctx_has_comment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	my ($first_line, $end_line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	my $cmt = ctx_locate_comment($first_line, $end_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	##print "LINE: $rawlines[$end_line - 1 ]\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	##print "CMMT: $cmt\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	return ($cmt ne '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) sub raw_line {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	my ($linenr, $cnt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	my $offset = $linenr - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	$cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	my $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	while ($cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		$line = $rawlines[$offset++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 		next if (defined($line) && $line =~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 		$cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	return $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) sub get_stat_real {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	my ($linenr, $lc) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	my $stat_real = raw_line($linenr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	for (my $count = $linenr + 1; $count <= $lc; $count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 		$stat_real = $stat_real . "\n" . raw_line($count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	return $stat_real;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) sub get_stat_here {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	my ($linenr, $cnt, $here) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	my $herectx = $here . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	for (my $n = 0; $n < $cnt; $n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		$herectx .= raw_line($linenr, $n) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	return $herectx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) sub cat_vet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	my ($vet) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	my ($res, $coded);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	$res = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		$res .= $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		if ($2 ne '') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 			$coded = sprintf("^%c", unpack('C', $2) + 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 			$res .= $coded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	$res =~ s/$/\$/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	return $res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) my $av_preprocessor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) my $av_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) my @av_paren_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) my $av_pend_colon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) sub annotate_reset {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	$av_preprocessor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	$av_pending = '_';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	@av_paren_type = ('E');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	$av_pend_colon = 'O';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) sub annotate_values {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	my ($stream, $type) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	my $res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	my $var = '_' x length($stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	my $cur = $stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	print "$stream\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	while (length($cur)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 		@av_paren_type = ('E') if ($#av_paren_type < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		print " <" . join('', @av_paren_type) .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 				"> <$type> <$av_pending>" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 		if ($cur =~ /^(\s+)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 			print "WS($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 			if ($1 =~ /\n/ && $av_preprocessor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 				$type = pop(@av_paren_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 				$av_preprocessor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 		} elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 			print "CAST($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 			push(@av_paren_type, $type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 			$type = 'c';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 		} elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 			print "DECLARE($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 			$type = 'T';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		} elsif ($cur =~ /^($Modifier)\s*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 			print "MODIFIER($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 			$type = 'T';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		} elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 			print "DEFINE($1,$2)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 			$av_preprocessor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 			push(@av_paren_type, $type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 			if ($2 ne '') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 				$av_pending = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 			$type = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		} elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 			print "UNDEF($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 			$av_preprocessor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 			push(@av_paren_type, $type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 		} elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 			print "PRE_START($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 			$av_preprocessor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 			push(@av_paren_type, $type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 			push(@av_paren_type, $type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 			$type = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 		} elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 			print "PRE_RESTART($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 			$av_preprocessor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 			push(@av_paren_type, $av_paren_type[$#av_paren_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 			$type = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		} elsif ($cur =~ /^(\#\s*(?:endif))/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 			print "PRE_END($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 			$av_preprocessor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 			# Assume all arms of the conditional end as this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 			# one does, and continue as if the #endif was not here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 			pop(@av_paren_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 			push(@av_paren_type, $type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 			$type = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		} elsif ($cur =~ /^(\\\n)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 			print "PRECONT($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 		} elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 			print "ATTR($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 			$av_pending = $type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 		} elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 			print "SIZEOF($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 			if (defined $2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 				$av_pending = 'V';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 		} elsif ($cur =~ /^(if|while|for)\b/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 			print "COND($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 			$av_pending = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		} elsif ($cur =~/^(case)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 			print "CASE($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 			$av_pend_colon = 'C';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		} elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 			print "KEYWORD($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		} elsif ($cur =~ /^(\()/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 			print "PAREN('$1')\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 			push(@av_paren_type, $av_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 			$av_pending = '_';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 		} elsif ($cur =~ /^(\))/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 			my $new_type = pop(@av_paren_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 			if ($new_type ne '_') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 				$type = $new_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 				print "PAREN('$1') -> $type\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 							if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 				print "PAREN('$1')\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 		} elsif ($cur =~ /^($Ident)\s*\(/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 			print "FUNC($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 			$type = 'V';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 			$av_pending = 'V';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 		} elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 			if (defined $2 && $type eq 'C' || $type eq 'T') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 				$av_pend_colon = 'B';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 			} elsif ($type eq 'E') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 				$av_pend_colon = 'L';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 			print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 			$type = 'V';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		} elsif ($cur =~ /^($Ident|$Constant)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 			print "IDENT($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 			$type = 'V';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		} elsif ($cur =~ /^($Assignment)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 			print "ASSIGN($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		} elsif ($cur =~/^(;|{|})/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 			print "END($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 			$type = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 			$av_pend_colon = 'O';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 		} elsif ($cur =~/^(,)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 			print "COMMA($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 			$type = 'C';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		} elsif ($cur =~ /^(\?)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 			print "QUESTION($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 		} elsif ($cur =~ /^(:)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 			print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 			substr($var, length($res), 1, $av_pend_colon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 			if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 				$type = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 				$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 			$av_pend_colon = 'O';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 		} elsif ($cur =~ /^(\[)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 			print "CLOSE($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 		} elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 			my $variant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 			print "OPV($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 			if ($type eq 'V') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 				$variant = 'B';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 				$variant = 'U';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 			substr($var, length($res), 1, $variant);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 			$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 		} elsif ($cur =~ /^($Operators)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 			print "OP($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 			if ($1 ne '++' && $1 ne '--') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 				$type = 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 		} elsif ($cur =~ /(^.)/o) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 			print "C($1)\n" if ($dbg_values > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		if (defined $1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 			$cur = substr($cur, length($1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 			$res .= $type x length($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	return ($res, $var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) sub possible {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	my ($possible, $line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	my $notPermitted = qr{(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 		^(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 			$Modifier|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 			$Storage|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 			$Type|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 			DEFINE_\S+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 		)$|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 		^(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 			goto|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 			return|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 			case|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 			else|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 			asm|__asm__|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 			do|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 			\#|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 			\#\#|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		)(?:\s|$)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 		^(?:typedef|struct|enum)\b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	    )}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	if ($possible !~ $notPermitted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		# Check for modifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		$possible =~ s/\s*$Storage\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		$possible =~ s/\s*$Sparse\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 		if ($possible =~ /^\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		} elsif ($possible =~ /\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 			$possible =~ s/\s*$Type\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 			for my $modifier (split(' ', $possible)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 				if ($modifier !~ $notPermitted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 					warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 					push(@modifierListFile, $modifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 			warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 			push(@typeListFile, $possible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		build_types();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) my $prefix = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) sub show_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	my ($type) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	$type =~ tr/[a-z]/[A-Z]/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	return defined $use_type{$type} if (scalar keys %use_type > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	return !defined $ignore_type{$type};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) sub report {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	my ($level, $type, $msg) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	if (!show_type($type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	    (defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	my $output = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	if ($color) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		if ($level eq 'ERROR') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 			$output .= RED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 		} elsif ($level eq 'WARNING') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 			$output .= YELLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 			$output .= GREEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	$output .= $prefix . $level . ':';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	if ($show_types) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		$output .= BLUE if ($color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		$output .= "$type:";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	$output .= RESET if ($color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	$output .= ' ' . $msg . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	if ($showfile) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 		my @lines = split("\n", $output, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 		splice(@lines, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		$output = join("\n", @lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	$output = (split('\n', $output))[0] . "\n" if ($terse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	push(our @report, $output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) sub report_dump {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	our @report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) sub fixup_current_range {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	my ($lineRef, $offset, $length) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		my $o = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		my $l = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		my $no = $o + $offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 		my $nl = $l + $length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 		$$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) sub fix_inserted_deleted_lines {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	my ($linesRef, $insertedRef, $deletedRef) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	my $range_last_linenr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	my $delta_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	my $old_linenr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	my $new_linenr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	my $next_insert = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	my $next_delete = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	my @lines = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	my $inserted = @{$insertedRef}[$next_insert++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	my $deleted = @{$deletedRef}[$next_delete++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	foreach my $old_line (@{$linesRef}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 		my $save_line = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 		my $line = $old_line;	#don't modify the array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 		if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) {	#new filename
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 			$delta_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 		} elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) {	#new hunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 			$range_last_linenr = $new_linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 			fixup_current_range(\$line, $delta_offset, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		while (defined($deleted) && ${$deleted}{'LINENR'} == $old_linenr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 			$deleted = @{$deletedRef}[$next_delete++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 			$save_line = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 			fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 		while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 			push(@lines, ${$inserted}{'LINE'});
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 			$inserted = @{$insertedRef}[$next_insert++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 			$new_linenr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 			fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		if ($save_line) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 			push(@lines, $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 			$new_linenr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		$old_linenr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	return @lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) sub fix_insert_line {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 	my ($linenr, $line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 	my $inserted = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		LINENR => $linenr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 		LINE => $line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 	push(@fixed_inserted, $inserted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) sub fix_delete_line {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	my ($linenr, $line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 	my $deleted = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		LINENR => $linenr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 		LINE => $line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	push(@fixed_deleted, $deleted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) sub ERROR {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	my ($type, $msg) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	if (report("ERROR", $type, $msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 		our $clean = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 		our $cnt_error++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) sub WARN {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	my ($type, $msg) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	if (report("WARNING", $type, $msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 		our $clean = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		our $cnt_warn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) sub CHK {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	my ($type, $msg) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	if ($check && report("CHECK", $type, $msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		our $clean = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		our $cnt_chk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) sub check_absolute_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	my ($absolute, $herecurr) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	my $file = $absolute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	##print "absolute<$absolute>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	# See if any suffix of this path is a path within the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	while ($file =~ s@^[^/]*/@@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		if (-f "$root/$file") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 			##print "file<$file>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 			last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	if (! -f _)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	# It is, so see if the prefix is acceptable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 	my $prefix = $absolute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	substr($prefix, -length($file)) = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 	##print "prefix<$prefix>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	if ($prefix ne ".../") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		WARN("USE_RELATIVE_PATH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		     "use relative pathname instead of absolute in changelog text\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) sub trim {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	my ($string) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	$string =~ s/^\s+|\s+$//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	return $string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) sub ltrim {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	my ($string) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 	$string =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 	return $string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) sub rtrim {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	my ($string) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	$string =~ s/\s+$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	return $string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) sub string_find_replace {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 	my ($string, $find, $replace) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	$string =~ s/$find/$replace/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	return $string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) sub tabify {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	my ($leading) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 	my $source_indent = $tabsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 	my $max_spaces_before_tab = $source_indent - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	my $spaces_to_tab = " " x $source_indent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	#convert leading spaces to tabs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	#Remove spaces before a tab
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 	1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 	return "$leading";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) sub pos_last_openparen {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 	my ($line) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	my $pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 	my $opens = $line =~ tr/\(/\(/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	my $closes = $line =~ tr/\)/\)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	my $last_openparen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	if (($opens == 0) || ($closes >= $opens)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	my $len = length($line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	for ($pos = 0; $pos < $len; $pos++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 		my $string = substr($line, $pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		if ($string =~ /^($FuncArg|$balanced_parens)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 			$pos += length($1) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		} elsif (substr($line, $pos, 1) eq '(') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 			$last_openparen = $pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 		} elsif (index($string, '(') == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 			last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) sub get_raw_comment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 	my ($line, $rawline) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 	my $comment = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 	for my $i (0 .. (length($line) - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 		if (substr($line, $i, 1) eq "$;") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 			$comment .= substr($rawline, $i, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	return $comment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) sub process {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 	my $filename = shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	my $linenr=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	my $prevline="";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 	my $prevrawline="";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	my $stashline="";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	my $stashrawline="";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	my $length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	my $indent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	my $previndent=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	my $stashindent=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	our $clean = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	my $signoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 	my $author = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	my $authorsignoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	my $author_sob = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	my $is_patch = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	my $is_binding_patch = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	my $in_header_lines = $file ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 	my $in_commit_log = 0;		#Scanning lines before patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	my $has_patch_separator = 0;	#Found a --- line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	my $has_commit_log = 0;		#Encountered lines before patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 	my $commit_log_lines = 0;	#Number of commit log lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 	my $commit_log_possible_stack_dump = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	my $commit_log_long_line = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	my $commit_log_has_diff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 	my $reported_maintainer_file = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	my $non_utf8_charset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	my $last_blank_line = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	my $last_coalesced_string_linenr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	our @report = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	our $cnt_lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	our $cnt_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	our $cnt_warn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	our $cnt_chk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	# Trace the real file/line as we go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	my $realfile = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	my $realline = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	my $realcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	my $here = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	my $context_function;		#undef'd unless there's a known function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	my $in_comment = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	my $comment_edge = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 	my $first_line = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	my $p1_prefix = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	my $prev_values = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	# suppression flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 	my %suppress_ifbraces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	my %suppress_whiletrailers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	my %suppress_export;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	my $suppress_statement = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 	my %signatures = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 	# Pre-scan the patch sanitizing the lines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	# Pre-scan the patch looking for any __setup documentation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 	#
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 	my @setup_docs = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 	my $setup_docs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	my $camelcase_file_seeded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	my $checklicenseline = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	sanitise_line_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 	my $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	foreach my $rawline (@rawlines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 		$linenr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 		$line = $rawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		push(@fixed, $rawline) if ($fix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 		if ($rawline=~/^\+\+\+\s+(\S+)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 			$setup_docs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 			if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 				$setup_docs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 			#next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 		if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 			$realline=$1-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 			if (defined $2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 				$realcnt=$3+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 				$realcnt=1+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 			$in_comment = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 			# Guestimate if this is a continuing comment.  Run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 			# the context looking for a comment "edge".  If this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 			# edge is a close comment then we must be in a comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 			# at context start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 			my $edge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 			my $cnt = $realcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 			for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 				next if (defined $rawlines[$ln - 1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 					 $rawlines[$ln - 1] =~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 				$cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 				#print "RAW<$rawlines[$ln - 1]>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 				last if (!defined $rawlines[$ln - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 				if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 				    $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 					($edge) = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 					last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 			if (defined $edge && $edge eq '*/') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 				$in_comment = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 			# Guestimate if this is a continuing comment.  If this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 			# is the start of a diff block and this line starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 			# ' *' then it is very likely a comment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 			if (!defined $edge &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 			    $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 				$in_comment = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 			##print "COMMENT:$in_comment edge<$edge> $rawline\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 			sanitise_line_reset($in_comment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 		} elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 			# Standardise the strings and chars within the input to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 			# simplify matching -- only bother with positive lines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 			$line = sanitise_line($rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		push(@lines, $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 		if ($realcnt > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 			$realcnt-- if ($line =~ /^(?:\+| |$)/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 			$realcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 		#print "==>$rawline\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 		#print "-->$line\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 		if ($setup_docs && $line =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 			push(@setup_docs, $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	$prefix = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	$realcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	$linenr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 	$fixlinenr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	foreach my $line (@lines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		$linenr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		$fixlinenr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 		my $sline = $line;	#copy of $line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 		$sline =~ s/$;/ /g;	#with comments as spaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		my $rawline = $rawlines[$linenr - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 		my $raw_comment = get_raw_comment($line, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) # check if it's a mode change, rename or start of a patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 		if (!$in_commit_log &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 		    ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 		    ($line =~ /^rename (?:from|to) \S+\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 		     $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 			$is_patch = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) #extract the line range in the file after the patch is applied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 		if (!$in_commit_log &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 		    $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 			my $context = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 			$is_patch = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 			$first_line = $linenr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 			$realline=$1-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 			if (defined $2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 				$realcnt=$3+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 				$realcnt=1+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 			annotate_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 			$prev_values = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 			%suppress_ifbraces = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 			%suppress_whiletrailers = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 			%suppress_export = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 			$suppress_statement = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 			if ($context =~ /\b(\w+)\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 				$context_function = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 				undef $context_function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) # track the line number as we move through the hunk, note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) # new versions of GNU diff omit the leading space on completely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) # blank context lines so we need to count that too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 		} elsif ($line =~ /^( |\+|$)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 			$realline++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 			$realcnt-- if ($realcnt != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 			# Measure the line length and indent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 			($length, $indent) = line_stats($rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 			# Track the previous line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 			($prevline, $stashline) = ($stashline, $line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 			($previndent, $stashindent) = ($stashindent, $indent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 			($prevrawline, $stashrawline) = ($stashrawline, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 			#warn "line<$line>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 		} elsif ($realcnt == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 			$realcnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 		my $hunk_line = ($realcnt != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 		$here = "#$linenr: " if (!$file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		$here = "#$realline: " if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		my $found_file = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		# extract the filename as it passes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		if ($line =~ /^diff --git.*?(\S+)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 			$realfile = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 			$realfile =~ s@^([^/]*)/@@ if (!$file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 			$in_commit_log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 			$found_file = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 			$realfile = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 			$realfile =~ s@^([^/]*)/@@ if (!$file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 			$in_commit_log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 			$p1_prefix = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 			if (!$file && $tree && $p1_prefix ne '' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 			    -e "$root/$p1_prefix") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 				WARN("PATCH_PREFIX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 				     "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 			if ($realfile =~ m@^include/asm/@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 				ERROR("MODIFIED_INCLUDE_ASM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 				      "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 			$found_file = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) #make up the handle for any error we report on this line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 		if ($showfile) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 			$prefix = "$realfile:$realline: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 		} elsif ($emacs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 			if ($file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 				$prefix = "$filename:$realline: ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 				$prefix = "$filename:$linenr: ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 		if ($found_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 			if (is_maintained_obsolete($realfile)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 				WARN("OBSOLETE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 				     "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy.  No unnecessary modifications please.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 			if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 				$check = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 				$check = $check_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 			$checklicenseline = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 			if ($realfile !~ /^MAINTAINERS/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 				my $last_binding_patch = $is_binding_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 				$is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 				if (($last_binding_patch != -1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 				    ($last_binding_patch ^ $is_binding_patch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 					WARN("DT_SPLIT_BINDING_PATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 					     "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 		$here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 		my $hereline = "$here\n$rawline\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 		my $herecurr = "$here\n$rawline\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 		my $hereprev = "$here\n$prevrawline\n$rawline\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 		$cnt_lines++ if ($realcnt != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) # Verify the existence of a commit log if appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) # 2 is used because a $signature is counted in $commit_log_lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 		if ($in_commit_log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 			if ($line !~ /^\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 				$commit_log_lines++;	#could be a $signature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 		} elsif ($has_commit_log && $commit_log_lines < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 			WARN("COMMIT_MESSAGE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 			     "Missing commit description - Add an appropriate one\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 			$commit_log_lines = 2;	#warn only once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) # Check if the commit log has what seems like a diff which can confuse patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 		if ($in_commit_log && !$commit_log_has_diff &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 		    (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 		      $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 		     $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 		     $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 			ERROR("DIFF_IN_COMMIT_MSG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 			      "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 			$commit_log_has_diff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) # Check for incorrect file permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 		if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 			my $permhere = $here . "FILE: $realfile\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 			if ($realfile !~ m@scripts/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 			    $realfile !~ /\.(py|pl|awk|sh)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 				ERROR("EXECUTE_PERMISSIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 				      "do not set execute permissions for source files\n" . $permhere);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) # Check the patch for a From:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 		if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 			$author = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 			my $curline = $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 			while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 				$author .= $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 			$author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 			$author =~ s/"//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 			$author = reformat_email($author);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) # Check the patch for a signoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 		if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 			$signoff++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 			$in_commit_log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 			if ($author ne ''  && $authorsignoff != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 				if (same_email_addresses($1, $author, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 					$authorsignoff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 					my $ctx = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 					my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 					my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 					if ($email_address eq $author_address && $email_name eq $author_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 						$author_sob = $ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 						$authorsignoff = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 					} elsif ($email_address eq $author_address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 						$author_sob = $ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 						$authorsignoff = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 					} elsif ($email_name eq $author_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 						$author_sob = $ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 						$authorsignoff = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 						my $address1 = $email_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 						my $address2 = $author_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 						if ($address1 =~ /(\S+)\+\S+(\@.*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 							$address1 = "$1$2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 						if ($address2 =~ /(\S+)\+\S+(\@.*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 							$address2 = "$1$2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 						if ($address1 eq $address2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 							$authorsignoff = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) # Check for patch separator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 		if ($line =~ /^---$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 			$has_patch_separator = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 			$in_commit_log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) # Check if MAINTAINERS is being updated.  If so, there's probably no need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) # emit the "does MAINTAINERS need updating?" message on file add/move/delete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 		if ($line =~ /^\s*MAINTAINERS\s*\|/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 			$reported_maintainer_file = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) # Check signature styles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 		if (!$in_header_lines &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 		    $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 			my $space_before = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 			my $sign_off = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 			my $space_after = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 			my $email = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 			my $ucfirst_sign_off = ucfirst(lc($sign_off));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 			if ($sign_off !~ /$signature_tags/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 				WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 				     "Non-standard signature: $sign_off\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 			if (defined $space_before && $space_before ne "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 				if (WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 					 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 					$fixed[$fixlinenr] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 					    "$ucfirst_sign_off $email";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 			if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 				if (WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 					 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 					$fixed[$fixlinenr] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 					    "$ucfirst_sign_off $email";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 			if (!defined $space_after || $space_after ne " ") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 				if (WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 					 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 					$fixed[$fixlinenr] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 					    "$ucfirst_sign_off $email";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 			my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 			my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 			if ($suggested_email eq "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 				ERROR("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 				      "Unrecognized email address: '$email'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 				my $dequoted = $suggested_email;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 				$dequoted =~ s/^"//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 				$dequoted =~ s/" </ </;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 				# Don't force email to have quotes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 				# Allow just an angle bracketed address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 				if (!same_email_addresses($email, $suggested_email, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 					WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 					     "email address '$email' might be better as '$suggested_email'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) # Check for duplicate signatures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 			my $sig_nospace = $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 			$sig_nospace =~ s/\s//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 			$sig_nospace = lc($sig_nospace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 			if (defined $signatures{$sig_nospace}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 				WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 				     "Duplicate signature\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 				$signatures{$sig_nospace} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 			if ($sign_off =~ /^co-developed-by:$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 				if ($email eq $author) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 					WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 					      "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 				if (!defined $lines[$linenr]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 					WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)                                              "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 				} elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 					WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 					     "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 				} elsif ($1 ne $email) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 					WARN("BAD_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 					     "Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) # Check email subject for common tools that don't need to be mentioned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 		if ($in_header_lines &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 		    $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 			WARN("EMAIL_SUBJECT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 			     "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) # Check for Gerrit Change-Ids not in any patch context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 		if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 			ERROR("GERRIT_CHANGE_ID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 			      "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) # Check if the commit log is in a possible stack dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 		if ($in_commit_log && !$commit_log_possible_stack_dump &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 		    ($line =~ /^\s*(?:WARNING:|BUG:)/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 		     $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 					# timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 		     $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 		     $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 		     $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 					# stack dump address styles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 			$commit_log_possible_stack_dump = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) # Check for line lengths > 75 in commit log, warn once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 		if ($in_commit_log && !$commit_log_long_line &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 		    length($line) > 75 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 		    !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 					# file delta changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 		      $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 					# filename then :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 		      $line =~ /^\s*(?:Fixes:|Link:)/i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 					# A Fixes: or Link: line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 		      $commit_log_possible_stack_dump)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 			WARN("COMMIT_LOG_LONG_LINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 			     "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 			$commit_log_long_line = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) # Reset possible stack dump if a blank line is found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 		if ($in_commit_log && $commit_log_possible_stack_dump &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 		    $line =~ /^\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 			$commit_log_possible_stack_dump = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) # Check for git id commit length and improperly formed commit descriptions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 		if ($in_commit_log && !$commit_log_possible_stack_dump &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 		    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 		    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 		    ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 		     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 		      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 		      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 			my $init_char = "c";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 			my $orig_commit = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 			my $short = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 			my $long = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 			my $case = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 			my $space = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 			my $hasdesc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 			my $hasparens = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 			my $id = '0123456789ab';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 			my $orig_desc = "commit description";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 			my $description = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 			if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 				$init_char = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 				$orig_commit = lc($2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 			} elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 				$orig_commit = lc($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 			$short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 			$long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 			$space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 			$case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 			if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 				$orig_desc = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 				$hasparens = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 				 defined $rawlines[$linenr] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 				 $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 				$orig_desc = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 				$hasparens = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 				 defined $rawlines[$linenr] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 				 $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 				$orig_desc = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 				$orig_desc .= " " . $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 				$hasparens = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 			($id, $description) = git_commit_info($orig_commit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 							      $id, $orig_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 			if (defined($id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 			   ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 				ERROR("GIT_COMMIT_ID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) # Check for added, moved or deleted files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 		if (!$reported_maintainer_file && !$in_commit_log &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 		    ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 		     $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 		     ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 		      (defined($1) || defined($2))))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 			$is_patch = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 			$reported_maintainer_file = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 			WARN("FILE_PATH_CHANGES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 			     "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) # Check for adding new DT bindings not in schema format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 		if (!$in_commit_log &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 		    ($line =~ /^new file mode\s*\d+\s*$/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 		    ($realfile =~ m@^Documentation/devicetree/bindings/.*\.txt$@)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 			WARN("DT_SCHEMA_BINDING_PATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 			     "DT bindings should be in DT schema format. See: Documentation/devicetree/writing-schema.rst\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) # Check for wrappage within a valid hunk of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 		if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 			ERROR("CORRUPTED_PATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 			      "patch seems to be corrupt (line wrapped?)\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 				$herecurr) if (!$emitted_corrupt++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 		if (($realfile =~ /^$/ || $line =~ /^\+/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 		    $rawline !~ m/^$UTF8*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 			my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 			my $blank = copy_spacing($rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 			my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 			my $hereptr = "$hereline$ptr\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 			CHK("INVALID_UTF8",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 			    "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) # Check if it's the start of a commit log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) # (not a header line and we haven't seen the patch filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 		if ($in_header_lines && $realfile =~ /^$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 		    !($rawline =~ /^\s+(?:\S|$)/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 		      $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 			$in_header_lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 			$in_commit_log = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 			$has_commit_log = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) # Check if there is UTF-8 in a commit log when a mail header has explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) # declined it, i.e defined some charset where it is missing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 		if ($in_header_lines &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		    $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 		    $1 !~ /utf-8/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 			$non_utf8_charset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 		if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 		    $rawline =~ /$NON_ASCII_UTF8/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 			WARN("UTF8_BEFORE_PATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 			    "8-bit UTF-8 used in possible commit log\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) # Check for absolute kernel paths in commit message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 		if ($tree && $in_commit_log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 			while ($line =~ m{(?:^|\s)(/\S*)}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 				my $file = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 				if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 				    check_absolute_file($1, $herecurr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 					#
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 					check_absolute_file($file, $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) # Check for various typo / spelling mistakes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 		if (defined($misspellings) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 		    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 			while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 				my $typo = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 				my $typo_fix = $spelling_fix{lc($typo)};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 				$typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 				$typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 				my $msg_level = \&WARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 				$msg_level = \&CHK if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 				if (&{$msg_level}("TYPO_SPELLING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 						  "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 					$fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) # check for invalid commit id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 		if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 			my $id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 			my $description;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 			($id, $description) = git_commit_info($2, undef, undef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 			if (!defined($id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 				WARN("UNKNOWN_COMMIT_ID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 				     "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) # check for repeated words separated by a single space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 		if ($rawline =~ /^\+/ || $in_commit_log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 			while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 				my $first = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 				my $second = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 				if ($first =~ /(?:struct|union|enum)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 					pos($rawline) += length($first) + length($second) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 					next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 				next if ($first ne $second);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 				next if ($first eq 'long');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 				if (WARN("REPEATED_WORD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 					 "Possible repeated word: '$first'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 					$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 			# if it's a repeated word on consecutive lines in a comment block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 			if ($prevline =~ /$;+\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 			    $prevrawline =~ /($word_pattern)\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 				my $last_word = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 				if ($rawline =~ /^\+\s*\*\s*$last_word /) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 					if (WARN("REPEATED_WORD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 						 "Possible repeated word: '$last_word'\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 					    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 						$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) # ignore non-hunk lines and lines being removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 		next if (!$hunk_line || $line =~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) #trailing whitespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 		if ($line =~ /^\+.*\015/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 			if (ERROR("DOS_LINE_ENDINGS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 				  "DOS line endings\n" . $herevet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 				$fixed[$fixlinenr] =~ s/[\s\015]+$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 		} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 			if (ERROR("TRAILING_WHITESPACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 				  "trailing whitespace\n" . $herevet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 				$fixed[$fixlinenr] =~ s/\s+$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 			$rpt_cleaners = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) # Check for FSF mailing addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 		if ($rawline =~ /\bwrite to the Free/i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 		    $rawline =~ /\b675\s+Mass\s+Ave/i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 		    $rawline =~ /\b59\s+Temple\s+Pl/i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 		    $rawline =~ /\b51\s+Franklin\s+St/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 			my $msg_level = \&ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 			$msg_level = \&CHK if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 			&{$msg_level}("FSF_MAILING_ADDRESS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 				      "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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) # check for Kconfig help text having a real description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) # Only applies when adding the entry originally, after that we do not have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) # sufficient context to determine whether it is indeed long enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 		if ($realfile =~ /Kconfig/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 		    # 'choice' is usually the last thing on the line (though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 		    # Kconfig supports named choices), so use a word boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 		    # (\b) rather than a whitespace character (\s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 		    $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 			my $length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 			my $cnt = $realcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 			my $ln = $linenr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 			my $f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 			my $is_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 			my $is_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 			for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 				$f = $lines[$ln - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 				$cnt-- if ($lines[$ln - 1] !~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 				$is_end = $lines[$ln - 1] =~ /^\+/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 				next if ($f =~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 				last if (!$file && $f =~ /^\@\@/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 				if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 					$is_start = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 				} elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 					$length = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 				$f =~ s/^.//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 				$f =~ s/#.*//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 				$f =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 				next if ($f =~ /^$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 				# This only checks context lines in the patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 				# and so hopefully shouldn't trigger false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 				# positives, even though some of these are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 				# common words in help texts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 				if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 						  if|endif|menu|endmenu|source)\b/x) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 					$is_end = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 					last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 				$length++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 			if ($is_start && $is_end && $length < $min_conf_desc_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 				WARN("CONFIG_DESCRIPTION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 				     "please write a paragraph that describes the config symbol fully\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 			#print "is_start<$is_start> is_end<$is_end> length<$length>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) # check MAINTAINERS entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 		if ($realfile =~ /^MAINTAINERS$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) # check MAINTAINERS entries for the right form
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 			if ($rawline =~ /^\+[A-Z]:/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 			    $rawline !~ /^\+[A-Z]:\t\S/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 				if (WARN("MAINTAINERS_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 					 "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 					$fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) # check MAINTAINERS entries for the right ordering too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 			my $preferred_order = 'MRLSWQBCPTFXNK';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 			if ($rawline =~ /^\+[A-Z]:/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 			    $prevrawline =~ /^[\+ ][A-Z]:/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 				$rawline =~ /^\+([A-Z]):\s*(.*)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 				my $cur = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 				my $curval = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 				$prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 				my $prev = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 				my $prevval = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 				my $curindex = index($preferred_order, $cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 				my $previndex = index($preferred_order, $prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 				if ($curindex < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 					WARN("MAINTAINERS_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 					     "Unknown MAINTAINERS entry type: '$cur'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 					if ($previndex >= 0 && $curindex < $previndex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 						WARN("MAINTAINERS_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 						     "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 					} elsif ((($prev eq 'F' && $cur eq 'F') ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 						  ($prev eq 'X' && $cur eq 'X')) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 						 ($prevval cmp $curval) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 						WARN("MAINTAINERS_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 						     "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) # discourage the use of boolean for type definition attributes of Kconfig options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 		if ($realfile =~ /Kconfig/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 		    $line =~ /^\+\s*\bboolean\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 			WARN("CONFIG_TYPE_BOOLEAN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 			     "Use of boolean is deprecated, please use bool instead.\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 		    ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 			my $flag = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 			my $replacement = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 				'EXTRA_AFLAGS' =>   'asflags-y',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 				'EXTRA_CFLAGS' =>   'ccflags-y',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 				'EXTRA_CPPFLAGS' => 'cppflags-y',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 				'EXTRA_LDFLAGS' =>  'ldflags-y',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 			};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 			WARN("DEPRECATED_VARIABLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 			     "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) # check for DT compatible documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 		if (defined $root &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 			(($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 			 ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 			my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 			my $dt_path = $root . "/Documentation/devicetree/bindings/";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 			my $vp_file = $dt_path . "vendor-prefixes.yaml";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 			foreach my $compat (@compats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 				my $compat2 = $compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 				$compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 				my $compat3 = $compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 				$compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 				`grep -Erq "$compat|$compat2|$compat3" $dt_path`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 				if ( $? >> 8 ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 					WARN("UNDOCUMENTED_DT_STRING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 					     "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 				next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 				my $vendor = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 				`grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 				if ( $? >> 8 ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 					WARN("UNDOCUMENTED_DT_STRING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 					     "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) # check for using SPDX license tag at beginning of files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 		if ($realline == $checklicenseline) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 			if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 				$checklicenseline = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 			} elsif ($rawline =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 				my $comment = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 				if ($realfile =~ /\.(h|s|S)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 					$comment = '/*';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 				} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 					$comment = '//';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 				} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 					$comment = '#';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 				} elsif ($realfile =~ /\.rst$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 					$comment = '..';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) # check SPDX comment style for .[chsS] files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 				if ($realfile =~ /\.[chsS]$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 				    $rawline =~ /SPDX-License-Identifier:/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 				    $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 					WARN("SPDX_LICENSE_TAG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 					     "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 				if ($comment !~ /^$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 				    $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 					WARN("SPDX_LICENSE_TAG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 					     "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 				} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 					my $spdx_license = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 					if (!is_SPDX_License_valid($spdx_license)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 						WARN("SPDX_LICENSE_TAG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 						     "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 					if ($realfile =~ m@^Documentation/devicetree/bindings/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 					    not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 						my $msg_level = \&WARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 						$msg_level = \&CHK if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 						if (&{$msg_level}("SPDX_LICENSE_TAG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 								  "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 						    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 							$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) # check for embedded filenames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 		if ($rawline =~ /^\+.*\Q$realfile\E/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 			WARN("EMBEDDED_FILENAME",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 			     "It's generally not useful to have the filename in the file\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) # check we are in a valid source file if not then ignore this hunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) # check for using SPDX-License-Identifier on the wrong line number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 		if ($realline != $checklicenseline &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 		    $rawline =~ /\bSPDX-License-Identifier:/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 		    substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 			WARN("SPDX_LICENSE_TAG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 			     "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) # line length limit (with some exclusions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) # There are a few types of lines that may extend beyond $max_line_length:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) #	logging functions like pr_info that end in a string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) #	lines with a single string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) #	#defines that are a single string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) #	lines with an RFC3986 like URL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) # There are 3 different line length message types:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) # LONG_LINE_COMMENT	a comment starts before but extends beyond $max_line_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) # LONG_LINE_STRING	a string starts before but extends beyond $max_line_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) # LONG_LINE		all other lines longer than $max_line_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) # if LONG_LINE is ignored, the other 2 types are also ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 		if ($line =~ /^\+/ && $length > $max_line_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 			my $msg_type = "LONG_LINE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 			# Check the allowed long line types first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 			# logging functions that end in a string that starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 			# before $max_line_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 			if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 			    length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 				$msg_type = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 			# lines with only strings (w/ possible termination)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 			# #defines with only strings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 			} elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 				 $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 				$msg_type = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 			# More special cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 			} elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 				 $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 				$msg_type = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 			# URL ($rawline is used in case the URL is in a comment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 			} elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 				$msg_type = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 			# Otherwise set the alternate message types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 			# a comment starts before $max_line_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 			} elsif ($line =~ /($;[\s$;]*)$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 				$msg_type = "LONG_LINE_COMMENT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 			# a quoted string starts before $max_line_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 			} elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 				$msg_type = "LONG_LINE_STRING"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 			if ($msg_type ne "" &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 			    (show_type("LONG_LINE") || show_type($msg_type))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 				my $msg_level = \&WARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 				$msg_level = \&CHK if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 				&{$msg_level}($msg_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 					      "line length of $length exceeds $max_line_length columns\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) # check for adding lines without a newline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 			WARN("MISSING_EOF_NEWLINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 			     "adding a line without newline at end of file\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) # check we are in a valid source file C or perl if not then ignore this hunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 		next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) # at the beginning of a line any tabs must come first and anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) # more than $tabsize must use tabs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 		if ($rawline =~ /^\+\s* \t\s*\S/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 		    $rawline =~ /^\+\s*        \s*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 			$rpt_cleaners = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 			if (ERROR("CODE_INDENT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 				  "code indent should use tabs where possible\n" . $herevet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 				$fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) # check for space before tabs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 		if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 			if (WARN("SPACE_BEFORE_TAB",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 				"please, no space before tabs\n" . $herevet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 				while ($fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 					   s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 				while ($fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 					   s/(^\+.*) +\t/$1\t/) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) # check for assignments on the start of a line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 		if ($sline =~ /^\+\s+($Assignment)[^=]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 			CHK("ASSIGNMENT_CONTINUATIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 			    "Assignment operator '$1' should be on the previous line\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) # check for && or || at the start of a line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 		if ($rawline =~ /^\+\s*(&&|\|\|)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 			CHK("LOGICAL_CONTINUATIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 			    "Logical continuations should be on the previous line\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) # check indentation starts on a tab stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 		    $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 			my $indent = length($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 			if ($indent % $tabsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 				if (WARN("TABSTOP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 					 "Statements should start on a tabstop\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 					$fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) # check multi-line statement indentation matches previous line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 		    $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 			$prevline =~ /^\+(\t*)(.*)$/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 			my $oldindent = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 			my $rest = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 			my $pos = pos_last_openparen($rest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 			if ($pos >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 				$line =~ /^(\+| )([ \t]*)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 				my $newindent = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 				my $goodtabindent = $oldindent .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 					"\t" x ($pos / $tabsize) .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 					" "  x ($pos % $tabsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 				my $goodspaceindent = $oldindent . " "  x $pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 				if ($newindent ne $goodtabindent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 				    $newindent ne $goodspaceindent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 					if (CHK("PARENTHESIS_ALIGNMENT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 						"Alignment should match open parenthesis\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 					    $fix && $line =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 						$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 						    s/^\+[ \t]*/\+$goodtabindent/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) # check for space after cast like "(int) foo" or "(struct foo) bar"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) # avoid checking a few false positives:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) #   "sizeof(<type>)" or "__alignof__(<type>)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) #   function pointer declarations like "(*foo)(int) = bar;"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) #   structure definitions like "(struct foo) { 0 };"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) #   multiline macros that define functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) #   known attributes or the __attribute__ keyword
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 		if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 		    (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 			if (CHK("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 				"No space is necessary after a cast\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 				    s/(\(\s*$Type\s*\))[ \t]+/$1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) # Block comment styles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) # Networking with an initial /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 		if ($realfile =~ m@^(drivers/net/|net/)@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 		    $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 		    $rawline =~ /^\+[ \t]*\*/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 		    $realline > 3) { # Do not warn about the initial copyright comment block after SPDX-License-Identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 			WARN("NETWORKING_BLOCK_COMMENT_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) # Block comments use * on subsequent lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 		    $prevrawline =~ /^\+.*?\/\*/ &&		#starting /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 		    $prevrawline !~ /\*\/[ \t]*$/ &&		#no trailing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 		    $rawline =~ /^\+/ &&			#line is new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 		    $rawline !~ /^\+[ \t]*\*/) {		#no leading *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 			WARN("BLOCK_COMMENT_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 			     "Block comments use * on subsequent lines\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) # Block comments use */ on trailing lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 		if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 		    $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ &&	#trailing **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 		    $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) {	#non blank */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 			WARN("BLOCK_COMMENT_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 			     "Block comments use a trailing */ on a separate line\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) # Block comment * alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 		    $line =~ /^\+[ \t]*$;/ &&			#leading comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 		    $rawline =~ /^\+[ \t]*\*/ &&		#leading *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 		    (($prevrawline =~ /^\+.*?\/\*/ &&		#leading /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 		      $prevrawline !~ /\*\/[ \t]*$/) ||		#no trailing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 		     $prevrawline =~ /^\+[ \t]*\*/)) {		#leading *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 			my $oldindent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 			$prevrawline =~ m@^\+([ \t]*/?)\*@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 			if (defined($1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 				$oldindent = expand_tabs($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 				$prevrawline =~ m@^\+(.*/?)\*@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 				$oldindent = expand_tabs($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 			$rawline =~ m@^\+([ \t]*)\*@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 			my $newindent = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 			$newindent = expand_tabs($newindent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 			if (length($oldindent) ne length($newindent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 				WARN("BLOCK_COMMENT_STYLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 				     "Block comments should align the * on each line\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) # check for missing blank lines after struct/union declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) # with exceptions for various attributes and macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 		if ($prevline =~ /^[\+ ]};?\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 		    $line =~ /^\+/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 		    !($line =~ /^\+\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 		      $line =~ /^\+\s*EXPORT_SYMBOL/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 		      $line =~ /^\+\s*MODULE_/i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 		      $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 		      $line =~ /^\+[a-z_]*init/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 		      $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 		      $line =~ /^\+\s*DECLARE/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 		      $line =~ /^\+\s*builtin_[\w_]*driver/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 		      $line =~ /^\+\s*__setup/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 			if (CHK("LINE_SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 				"Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 				fix_insert_line($fixlinenr, "\+");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) # check for multiple consecutive blank lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 		if ($prevline =~ /^[\+ ]\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 		    $line =~ /^\+\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 		    $last_blank_line != ($linenr - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 			if (CHK("LINE_SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 				"Please don't use multiple blank lines\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 			$last_blank_line = $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) # check for missing blank lines after declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 		if ($sline =~ /^\+\s+\S/ &&			#Not at char 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 			# actual declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 		    ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 			# function pointer declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 		     $prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 			# foo bar; where foo is some local typedef or #define
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 		     $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 			# known declaration macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 		     $prevline =~ /^\+\s+$declaration_macros/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 			# for "else if" which can look like "$Ident $Ident"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 		    !($prevline =~ /^\+\s+$c90_Keywords\b/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 			# other possible extensions of declaration lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 		      $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 			# not starting a section or a macro "\" extended line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 		      $prevline =~ /(?:\{\s*|\\)$/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 			# looks like a declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 		    !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 			# function pointer declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 		      $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 			# foo bar; where foo is some local typedef or #define
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 		      $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 			# known declaration macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 		      $sline =~ /^\+\s+$declaration_macros/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 			# start of struct or union or enum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 		      $sline =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 			# start or end of block or continuation of declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 		      $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 			# bitfield continuation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 		      $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 			# other possible extensions of declaration lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 		      $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 			# indentation of previous and current line are the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 		    (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 			if (WARN("LINE_SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 				 "Missing a blank line after declarations\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 				fix_insert_line($fixlinenr, "\+");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) # check for spaces at the beginning of a line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) # Exceptions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) #  1) within comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) #  2) indented preprocessor commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) #  3) hanging labels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 		if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 			if (WARN("LEADING_SPACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 				 "please, no spaces at the start of a line\n" . $herevet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 				$fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) # check we are in a valid C source file if not then ignore this hunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 		next if ($realfile !~ /\.(h|c)$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) # check for unusual line ending [ or (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 		if ($line =~ /^\+.*([\[\(])\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 			CHK("OPEN_ENDED_LINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 			    "Lines should not end with a '$1'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) # check if this appears to be the start function declaration, save the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 		if ($sline =~ /^\+\{\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 		    $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 			$context_function = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) # check if this appears to be the end of function declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 		if ($sline =~ /^\+\}\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 			undef $context_function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) # check indentation of any line with a bare else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) # (but not if it is a multiple line "if (foo) return bar; else return baz;")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) # if the previous line is a break or return and is indented 1 tab more...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 		if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 			my $tabs = length($1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 			if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 			    ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 			     defined $lines[$linenr] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 			     $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 				WARN("UNNECESSARY_ELSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 				     "else is not generally useful after a break or return\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) # check indentation of a line with a break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) # if the previous line is a goto or return and is indented the same # of tabs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 		if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 			my $tabs = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 			if ($prevline =~ /^\+$tabs(?:goto|return)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 				WARN("UNNECESSARY_BREAK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 				     "break is not useful after a goto or return\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) # check for RCS/CVS revision markers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 		if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 			WARN("CVS_KEYWORD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 			     "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) # check for old HOTPLUG __dev<foo> section markings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 		if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 			WARN("HOTPLUG_SECTION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 			     "Using $1 is unnecessary\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) # Check for potential 'bare' types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 		my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 		    $realline_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) #print "LINE<$line>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 		if ($linenr > $suppress_statement &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 		    $realcnt && $sline =~ /.\s*\S/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 				ctx_statement_block($linenr, $realcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 			$stat =~ s/\n./\n /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 			$cond =~ s/\n./\n /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) #print "linenr<$linenr> <$stat>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 			# If this statement has no statement boundaries within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 			# it there is no point in retrying a statement scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 			# until we hit end of it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 			my $frag = $stat; $frag =~ s/;+\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 			if ($frag !~ /(?:{|;)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) #print "skip<$line_nr_next>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 				$suppress_statement = $line_nr_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 			# Find the real next line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 			$realline_next = $line_nr_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 			if (defined $realline_next &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 			    (!defined $lines[$realline_next - 1] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 			     substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 				$realline_next++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 			my $s = $stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 			$s =~ s/{.*$//s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 			# Ignore goto labels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 			if ($s =~ /$Ident:\*$/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 			# Ignore functions being called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 			} elsif ($s =~ /^.\s*$Ident\s*\(/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 			} elsif ($s =~ /^.\s*else\b/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 			# declarations always start with types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 			} 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) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 				my $type = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 				$type =~ s/\s+/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 				possible($type, "A:" . $s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 			# definitions in global scope can only start with types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 			} elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 				possible($1, "B:" . $s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 			# any (foo ... *) is a pointer cast, and foo is a type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 			while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 				possible($1, "C:" . $s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 			# Check for any sort of function declaration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 			# int foo(something bar, other baz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 			# void (*store_gdt)(x86_descr_ptr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 			if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 				my ($name_len) = length($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 				my $ctx = $s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 				substr($ctx, 0, $name_len + 1, '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 				$ctx =~ s/\)[^\)]*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 				for my $arg (split(/\s*,\s*/, $ctx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 					if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 						possible($1, "D:" . $s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) # Checks which may be anchored in the context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) # Check for switch () and associated case and default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) # statements should be at the same indent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 		if ($line=~/\bswitch\s*\(.*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 			my $err = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 			my $sep = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 			my @ctx = ctx_block_outer($linenr, $realcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 			shift(@ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 			for my $ctx (@ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 				my ($clen, $cindent) = line_stats($ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 				if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 							$indent != $cindent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 					$err .= "$sep$ctx\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 					$sep = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 					$sep = "[...]\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 			if ($err ne '') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 				ERROR("SWITCH_CASE_INDENT_LEVEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 				      "switch and case should be at the same indent\n$hereline$err");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) # if/while/etc brace do not go on next line, unless defining a do while loop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) # or if that brace on the next line is for something else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 		if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 			my $pre_ctx = "$1$2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 			my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 			if ($line =~ /^\+\t{6,}/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 				WARN("DEEP_INDENTATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 				     "Too many leading tabs - consider code refactoring\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 			my $ctx_cnt = $realcnt - $#ctx - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 			my $ctx = join("\n", @ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 			my $ctx_ln = $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 			my $ctx_skip = $realcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 			while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 					defined $lines[$ctx_ln - 1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 					$lines[$ctx_ln - 1] =~ /^-/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 				##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 				$ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 				$ctx_ln++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 			#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 			#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 			if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 				ERROR("OPEN_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 				      "that open brace { should be on the previous line\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 					"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 			if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 			    $ctx =~ /\)\s*\;\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 			    defined $lines[$ctx_ln - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 				my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 				if ($nindent > $indent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 					WARN("TRAILING_SEMICOLON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 					     "trailing semicolon indicates no statements, indent implies otherwise\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 						"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) # Check relative indent for conditionals and blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 		if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 				ctx_statement_block($linenr, $realcnt, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 					if (!defined $stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 			my ($s, $c) = ($stat, $cond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 			substr($s, 0, length($c), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 			# remove inline comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 			$s =~ s/$;/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 			$c =~ s/$;/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 			# Find out how long the conditional actually is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 			my @newlines = ($c =~ /\n/gs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 			my $cond_lines = 1 + $#newlines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 			# Make sure we remove the line prefixes as we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 			# none on the first line, and are going to readd them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 			# where necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 			$s =~ s/\n./\n/gs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 			while ($s =~ /\n\s+\\\n/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 				$cond_lines += $s =~ s/\n\s+\\\n/\n/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 			# We want to check the first line inside the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 			# starting at the end of the conditional, so remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 			#  1) any blank line termination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 			#  2) any opening brace { on end of the line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 			#  3) any do (...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 			my $continuation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 			my $check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 			$s =~ s/^.*\bdo\b//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 			$s =~ s/^\s*{//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 			if ($s =~ s/^\s*\\//) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 				$continuation = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 			if ($s =~ s/^\s*?\n//) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 				$check = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 				$cond_lines++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 			# Also ignore a loop construct at the end of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 			# preprocessor statement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 			if (($prevline =~ /^.\s*#\s*define\s/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 			    $prevline =~ /\\\s*$/) && $continuation == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 				$check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 			my $cond_ptr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 			$continuation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 			while ($cond_ptr != $cond_lines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 				$cond_ptr = $cond_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 				# If we see an #else/#elif then the code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 				# is not linear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 				if ($s =~ /^\s*\#\s*(?:else|elif)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 					$check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 				# Ignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 				#  1) blank lines, they should be at 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 				#  2) preprocessor lines, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 				#  3) labels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 				if ($continuation ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 				    $s =~ /^\s*?\n/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 				    $s =~ /^\s*#\s*?/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 				    $s =~ /^\s*$Ident\s*:/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 					$continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 					if ($s =~ s/^.*?\n//) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 						$cond_lines++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 			my (undef, $sindent) = line_stats("+" . $s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 			my $stat_real = raw_line($linenr, $cond_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 			# Check if either of these lines are modified, else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 			# this is not this patch's fault.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 			if (!defined($stat_real) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 			    $stat !~ /^\+/ && $stat_real !~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 				$check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 			if (defined($stat_real) && $cond_lines > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 				$stat_real = "[...]\n$stat_real";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 			#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";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 			if ($check && $s ne '' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 			    (($sindent % $tabsize) != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 			     ($sindent < $indent) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 			     ($sindent == $indent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 			      ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 			     ($sindent > $indent + $tabsize))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 				WARN("SUSPECT_CODE_INDENT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 				     "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 		# Track the 'values' across context and added lines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 		my $opline = $line; $opline =~ s/^./ /;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 		my ($curr_values, $curr_vars) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 				annotate_values($opline . "\n", $prev_values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 		$curr_values = $prev_values . $curr_values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 		if ($dbg_values) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 			my $outline = $opline; $outline =~ s/\t/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 			print "$linenr > .$outline\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 			print "$linenr > $curr_values\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 			print "$linenr >  $curr_vars\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 		$prev_values = substr($curr_values, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) #ignore lines not being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 		next if ($line =~ /^[^\+]/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) # check for self assignments used to avoid compiler warnings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) # e.g.:	int foo = foo, *bar = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) #	struct foo bar = *(&(bar));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 			my $var = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 			if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 				WARN("SELF_ASSIGNMENT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 				     "Do not use self-assignments to avoid compiler warnings\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) # check for dereferences that span multiple lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 		if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 		    $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 			$prevline =~ /($Lval\s*(?:\.|->))\s*$/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 			my $ref = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 			$line =~ /^.\s*($Lval)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 			$ref .= $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 			$ref =~ s/\s//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 			WARN("MULTILINE_DEREFERENCE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 			     "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) # check for declarations of signed or unsigned without int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 		while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 			my $type = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 			my $var = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 			$var = "" if (!defined $var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 			if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 				my $sign = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 				my $pointer = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 				$pointer = "" if (!defined $pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 				if (WARN("UNSPECIFIED_INT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 					 "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 					my $decl = trim($sign) . " int ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 					my $comp_pointer = $pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 					$comp_pointer =~ s/\s//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 					$decl .= $comp_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 					$decl = rtrim($decl) if ($var eq "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 					$fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) # TEST: allow direct testing of the type matcher.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 		if ($dbg_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 			if ($line =~ /^.\s*$Declare\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 				ERROR("TEST_TYPE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) 				      "TEST: is type\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 			} elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 				ERROR("TEST_NOT_TYPE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 				      "TEST: is not type ($1 is)\n". $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) # TEST: allow direct testing of the attribute matcher.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 		if ($dbg_attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 			if ($line =~ /^.\s*$Modifier\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) 				ERROR("TEST_ATTR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 				      "TEST: is attr\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 			} elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 				ERROR("TEST_NOT_ATTR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 				      "TEST: is not attr ($1 is)\n". $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 			next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) # check for initialisation to aggregates open brace on the next line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 		if ($line =~ /^.\s*{/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 		    $prevline =~ /(?:^|[^=])=\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 			if (ERROR("OPEN_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 				  "that open brace { should be on the previous line\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) 			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 				fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 				my $fixedline = $prevrawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 				$fixedline =~ s/\s*=\s*$/ = {/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 				fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 				$fixedline = $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 				$fixedline =~ s/^(.\s*)\{\s*/$1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 				fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) # Checks which are anchored on the added line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) # check for malformed paths in #include statements (uses RAW line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 		if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 			my $path = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 			if ($path =~ m{//}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) 				ERROR("MALFORMED_INCLUDE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 				      "malformed #include filename\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) 			if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 				ERROR("UAPI_INCLUDE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 				      "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) # no C99 // comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 		if ($line =~ m{//}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 			if (ERROR("C99_COMMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 				  "do not use C99 // comments\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 				my $line = $fixed[$fixlinenr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 				if ($line =~ /\/\/(.*)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 					my $comment = trim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 					$fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 		# Remove C99 comments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 		$line =~ s@//.*@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 		$opline =~ s@//.*@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) # EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) # the whole statement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) #print "APW <$lines[$realline_next - 1]>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 		if (defined $realline_next &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 		    exists $lines[$realline_next - 1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 		    !defined $suppress_export{$realline_next} &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 		    ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) 		     $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 			# Handle definitions which produce identifiers with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 			# a prefix:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 			#   XXX(foo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 			#   EXPORT_SYMBOL(something_foo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 			my $name = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 			if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 			    $name =~ /^${Ident}_$2/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) #print "FOO C name<$name>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 				$suppress_export{$realline_next} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 			} elsif ($stat !~ /(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 				\n.}\s*$|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 				^.DEFINE_$Ident\(\Q$name\E\)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 				^.DECLARE_$Ident\(\Q$name\E\)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 				^.LIST_HEAD\(\Q$name\E\)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 				^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 				\b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 			    )/x) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 				$suppress_export{$realline_next} = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 				$suppress_export{$realline_next} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 		if (!defined $suppress_export{$linenr} &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 		    $prevline =~ /^.\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 		    ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 		     $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) #print "FOO B <$lines[$linenr - 1]>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 			$suppress_export{$linenr} = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 		if (defined $suppress_export{$linenr} &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 		    $suppress_export{$linenr} == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 			WARN("EXPORT_SYMBOL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 			     "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) # check for global initialisers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 		if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 			if (ERROR("GLOBAL_INITIALISERS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 				  "do not initialise globals to $1\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 				$fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) # check for static initialisers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 		if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 			if (ERROR("INITIALISED_STATIC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 				  "do not initialise statics to $1\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 				      $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 				$fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) # check for misordered declarations of char/short/int/long with signed/unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 		while ($sline =~ m{(\b$TypeMisordered\b)}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 			my $tmp = trim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 			WARN("MISORDERED_TYPE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 			     "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) # check for unnecessary <signed> int declarations of short/long/long long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 		while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 			my $type = trim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 			next if ($type !~ /\bint\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 			next if ($type !~ /\b(?:short|long\s+long|long)\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 			my $new_type = $type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 			$new_type =~ s/\b\s*int\s*\b/ /;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 			$new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 			$new_type =~ s/^const\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 			$new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 			$new_type = "const $new_type" if ($type =~ /^const\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 			$new_type =~ s/\s+/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 			$new_type = trim($new_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 			if (WARN("UNNECESSARY_INT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 				 "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 				$fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) # check for static const char * arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 		if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 			WARN("STATIC_CONST_CHAR_ARRAY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 			     "static const char * array should probably be static const char * const\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 				$herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) # check for initialized const char arrays that should be static const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 		if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 			if (WARN("STATIC_CONST_CHAR_ARRAY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 				 "const array should probably be static const\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 				$fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) # check for static char foo[] = "bar" declarations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 		if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 			WARN("STATIC_CONST_CHAR_ARRAY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 			     "static char array declaration should probably be static const char\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 				$herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) # check for const <foo> const where <foo> is not a pointer or array type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 		if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 			my $found = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 			if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 				WARN("CONST_CONST",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 				     "'const $found const *' should probably be 'const $found * const'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 			} elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 				WARN("CONST_CONST",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 				     "'const $found const' should probably be 'const $found'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) # check for non-global char *foo[] = {"bar", ...} declarations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 		if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 			WARN("STATIC_CONST_CHAR_ARRAY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 			     "char * array declaration might be better as static const\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 				$herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215)                }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) # check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 		if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 			my $array = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 			if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 				my $array_div = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 				if (WARN("ARRAY_SIZE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 					 "Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 					$fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) # check for function declarations without arguments like "int foo()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 		if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 			if (ERROR("FUNCTION_WITHOUT_ARGS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 				  "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 				$fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) # check for new typedefs, only function parameters and sparse annotations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) # make sense.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 		if ($line =~ /\btypedef\s/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 		    $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 		    $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 		    $line !~ /\b$typeTypedefs\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 		    $line !~ /\b__bitwise\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 			WARN("NEW_TYPEDEFS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 			     "do not add new typedefs\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) # * goes on variable not on type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 		# (char*[ const])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 		while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 			#print "AA<$1>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 			my ($ident, $from, $to) = ($1, $2, $2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 			# Should start with a space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 			$to =~ s/^(\S)/ $1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 			# Should not end with a space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 			$to =~ s/\s+$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 			# '*'s should not have spaces between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 			while ($to =~ s/\*\s+\*/\*\*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) ##			print "1: from<$from> to<$to> ident<$ident>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 			if ($from ne $to) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 				if (ERROR("POINTER_LOCATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 					  "\"(foo$from)\" should be \"(foo$to)\"\n" .  $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 					my $sub_from = $ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 					my $sub_to = $ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 					$sub_to =~ s/\Q$from\E/$to/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 					$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 					    s@\Q$sub_from\E@$sub_to@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 		while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 			#print "BB<$1>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 			my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 			# Should start with a space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 			$to =~ s/^(\S)/ $1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 			# Should not end with a space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 			$to =~ s/\s+$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 			# '*'s should not have spaces between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 			while ($to =~ s/\*\s+\*/\*\*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 			# Modifiers should have spaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 			$to =~ s/(\b$Modifier$)/$1 /;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) ##			print "2: from<$from> to<$to> ident<$ident>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 			if ($from ne $to && $ident !~ /^$Modifier$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 				if (ERROR("POINTER_LOCATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 					  "\"foo${from}bar\" should be \"foo${to}bar\"\n" .  $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 					my $sub_from = $match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 					my $sub_to = $match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 					$sub_to =~ s/\Q$from\E/$to/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 					$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 					    s@\Q$sub_from\E@$sub_to@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) # avoid BUG() or BUG_ON()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 		if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 			my $msg_level = \&WARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 			$msg_level = \&CHK if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 			&{$msg_level}("AVOID_BUG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 				      "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) # avoid LINUX_VERSION_CODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 		if ($line =~ /\bLINUX_VERSION_CODE\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 			WARN("LINUX_VERSION_CODE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 			     "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) # check for uses of printk_ratelimit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 		if ($line =~ /\bprintk_ratelimit\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 			WARN("PRINTK_RATELIMITED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 			     "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) # printk should use KERN_* levels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 		if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 			WARN("PRINTK_WITHOUT_KERN_LEVEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 			     "printk() should include KERN_<LEVEL> facility level\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 		if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 			my $orig = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 			my $level = lc($orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 			$level = "warn" if ($level eq "warning");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 			my $level2 = $level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 			$level2 = "dbg" if ($level eq "debug");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 			WARN("PREFER_PR_LEVEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 			     "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(...  to printk(KERN_$orig ...\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 		if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 			my $orig = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 			my $level = lc($orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 			$level = "warn" if ($level eq "warning");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 			$level = "dbg" if ($level eq "debug");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 			WARN("PREFER_DEV_LEVEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 			     "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) # trace_printk should not be used in production code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 		if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 			WARN("TRACE_PRINTK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 			     "Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) # ENOSYS means "bad syscall nr" and nothing else.  This will have a small
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) # number of false positives, but assembly files are not checked, so at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) # least the arch entry code will not trigger this warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 		if ($line =~ /\bENOSYS\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 			WARN("ENOSYS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 			     "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) # ENOTSUPP is not a standard error code and should be avoided in new patches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) # Folks usually mean EOPNOTSUPP (also called ENOTSUP), when they type ENOTSUPP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) # Similarly to ENOSYS warning a small number of false positives is expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 		if (!$file && $line =~ /\bENOTSUPP\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 			if (WARN("ENOTSUPP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 				 "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 				$fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) # function brace can't be on same line, except for #defines of do while,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) # or if closed on same line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 		    $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 		    $sline !~ /\#\s*define\b.*do\s*\{/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 		    $sline !~ /}/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 			if (ERROR("OPEN_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 				  "open brace '{' following function definitions go on the next line\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 				my $fixed_line = $rawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 				$fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 				my $line1 = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 				my $line2 = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 				fix_insert_line($fixlinenr, ltrim($line1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 				fix_insert_line($fixlinenr, "\+{");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 				if ($line2 !~ /^\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 					fix_insert_line($fixlinenr, "\+\t" . trim($line2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) # open braces for enum, union and struct go on the same line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 		if ($line =~ /^.\s*{/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 		    $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 			if (ERROR("OPEN_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 				  "open brace '{' following $1 go on the same line\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 				fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 				my $fixedline = rtrim($prevrawline) . " {";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 				fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 				$fixedline = $rawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 				$fixedline =~ s/^(.\s*)\{\s*/$1\t/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 				if ($fixedline !~ /^\+\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 					fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) # missing space after union, struct or enum definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 		if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 			if (WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 				 "missing space after $1 definition\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 				    s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) # Function pointer declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) # check spacing between type, funcptr, and args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) # canonical declaration is "type (*funcptr)(args...)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 		if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 			my $declare = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 			my $pre_pointer_space = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 			my $post_pointer_space = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 			my $funcname = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 			my $post_funcname_space = $5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 			my $pre_args_space = $6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) # the $Declare variable will capture all spaces after the type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) # so check it for a missing trailing missing space but pointer return types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) # don't need a space so don't warn for those.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 			my $post_declare_space = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 			if ($declare =~ /(\s+)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 				$post_declare_space = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 				$declare = rtrim($declare);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 			if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 				WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 				     "missing space after return type\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 				$post_declare_space = " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) # unnecessary space "type  (*funcptr)(args...)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) # This test is not currently implemented because these declarations are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) # equivalent to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) #	int  foo(int bar, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) # and this is form shouldn't/doesn't generate a checkpatch warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) #			elsif ($declare =~ /\s{2,}$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) #				WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) #				     "Multiple spaces after return type\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) #			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) # unnecessary space "type ( *funcptr)(args...)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 			if (defined $pre_pointer_space &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 			    $pre_pointer_space =~ /^\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 				WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 				     "Unnecessary space after function pointer open parenthesis\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) # unnecessary space "type (* funcptr)(args...)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 			if (defined $post_pointer_space &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 			    $post_pointer_space =~ /^\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) 				WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 				     "Unnecessary space before function pointer name\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) # unnecessary space "type (*funcptr )(args...)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 			if (defined $post_funcname_space &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 			    $post_funcname_space =~ /^\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 				WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 				     "Unnecessary space after function pointer name\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) # unnecessary space "type (*funcptr) (args...)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 			if (defined $pre_args_space &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 			    $pre_args_space =~ /^\s/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 				WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 				     "Unnecessary space before function pointer arguments\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 			if (show_type("SPACING") && $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 				    s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) # check for spacing round square brackets; allowed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) #  1. with a type on the left -- int [] a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) #  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) #  3. inside a curly brace -- = { [0...10] = 5 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) 		while ($line =~ /(.*?\s)\[/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 			my ($where, $prefix) = ($-[1], $1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 			if ($prefix !~ /$Type\s+$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 			    ($where != 0 || $prefix !~ /^.\s+$/) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 			    $prefix !~ /[{,:]\s+$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 				if (ERROR("BRACKET_SPACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 					  "space prohibited before open square bracket '['\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 				    $fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 					s/^(\+.*?)\s+\[/$1\[/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) # check for spaces between functions and their parentheses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 		while ($line =~ /($Ident)\s+\(/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 			my $name = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 			my $ctx_before = substr($line, 0, $-[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 			my $ctx = "$ctx_before$name";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 			# Ignore those directives where spaces _are_ permitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 			if ($name =~ /^(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 				if|for|while|switch|return|case|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 				volatile|__volatile__|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 				__attribute__|format|__extension__|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 				asm|__asm__)$/x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 			# cpp #define statements have non-optional spaces, ie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 			# if there is a space between the name and the open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 			# parenthesis it is simply not a parameter group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 			} elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 			# cpp #elif statement condition may start with a (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 			} elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 			# If this whole things ends with a type its most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 			# likely a typedef for a function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 			} elsif ($ctx =~ /$Type$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 				if (WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 					 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) 					     $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) 					$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 					    s/\b$name\s+\(/$name\(/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) # Check operator spacing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) 		if (!($line=~/\#\s*include/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 			my $fixed_line = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 			my $line_fixed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 			my $ops = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 				<<=|>>=|<=|>=|==|!=|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 				\+=|-=|\*=|\/=|%=|\^=|\|=|&=|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 				=>|->|<<|>>|<|>|=|!|~|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 				&&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 				\?:|\?|:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) 			}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) 			my @elements = split(/($ops|;)/, $opline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) ##			print("element count: <" . $#elements . ">\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) ##			foreach my $el (@elements) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) ##				print("el: <$el>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) ##			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 			my @fix_elements = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 			my $off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 			foreach my $el (@elements) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 				push(@fix_elements, substr($rawline, $off, length($el)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 				$off += length($el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 			$off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 			my $blank = copy_spacing($opline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 			my $last_after = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 			for (my $n = 0; $n < $#elements; $n += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 				my $good = $fix_elements[$n] . $fix_elements[$n + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) ##				print("n: <$n> good: <$good>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) 				$off += length($elements[$n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 				# Pick up the preceding and succeeding characters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 				my $ca = substr($opline, 0, $off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 				my $cc = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 				if (length($opline) >= ($off + length($elements[$n + 1]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 					$cc = substr($opline, $off + length($elements[$n + 1]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 				my $cb = "$ca$;$cc";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 				my $a = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 				$a = 'V' if ($elements[$n] ne '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 				$a = 'W' if ($elements[$n] =~ /\s$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 				$a = 'C' if ($elements[$n] =~ /$;$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 				$a = 'B' if ($elements[$n] =~ /(\[|\()$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 				$a = 'O' if ($elements[$n] eq '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 				$a = 'E' if ($ca =~ /^\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 				my $op = $elements[$n + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 				my $c = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 				if (defined $elements[$n + 2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 					$c = 'V' if ($elements[$n + 2] ne '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 					$c = 'W' if ($elements[$n + 2] =~ /^\s/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 					$c = 'C' if ($elements[$n + 2] =~ /^$;/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 					$c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 					$c = 'O' if ($elements[$n + 2] eq '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) 					$c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) 					$c = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 				my $ctx = "${a}x${c}";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 				my $at = "(ctx:$ctx)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 				my $ptr = substr($blank, 0, $off) . "^";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 				my $hereptr = "$hereline$ptr\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 				# Pull out the value of this operator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 				my $op_type = substr($curr_values, $off + 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 				# Get the full operator variant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 				my $opv = $op . substr($curr_vars, $off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 				# Ignore operators passed as parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 				if ($op_type ne 'V' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 				    $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) #				# Ignore comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) #				} elsif ($op =~ /^$;+$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 				# ; should have either the end of line or a space or \ after it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 				} elsif ($op eq ';') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 					if ($ctx !~ /.x[WEBC]/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 					    $cc !~ /^\\/ && $cc !~ /^;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 							  "space required after that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 				# // is a comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 				} elsif ($op eq '//') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 				#   :   when part of a bitfield
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 				} elsif ($opv eq ':B') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 					# skip the bitfield test for now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 				# No spaces for:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 				#   ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 				} elsif ($op eq '->') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 					if ($ctx =~ /Wx.|.xW/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 							  "spaces prohibited around that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 							if (defined $fix_elements[$n + 2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 								$fix_elements[$n + 2] =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 				# , must not have a space before and must have a space on the right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 				} elsif ($op eq ',') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 					my $rtrim_before = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 					my $space_after = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 					if ($ctx =~ /Wx./) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 							  "space prohibited before that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) 							$rtrim_before = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 					if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 							  "space required after that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) 							$last_after = $n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 							$space_after = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 					if ($rtrim_before || $space_after) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) 						if ($rtrim_before) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) 							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) 						} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) 							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) 						if ($space_after) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) 							$good .= " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 				# '*' as part of a type definition -- reported already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 				} elsif ($opv eq '*_') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 					#warn "'*' is part of type\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 				# unary operators should have a space before and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 				# none after.  May be left adjacent to another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 				# unary operator, or a cast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 				} elsif ($op eq '!' || $op eq '~' ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 					 $opv eq '*U' || $opv eq '-U' ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 					 $opv eq '&U' || $opv eq '&&U') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 					if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 							  "space required before that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 							if ($n != $last_after + 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 								$good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 								$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 					if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) 						# A unary '*' may be const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 					} elsif ($ctx =~ /.xW/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 							  "space prohibited after that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 							$good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 							if (defined $fix_elements[$n + 2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 								$fix_elements[$n + 2] =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 				# unary ++ and unary -- are allowed no space on one side.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 				} elsif ($op eq '++' or $op eq '--') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 					if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 							  "space required one side of that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 					if ($ctx =~ /Wx[BE]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 					    ($ctx =~ /Wx./ && $cc =~ /^;/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 							  "space prohibited before that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 					if ($ctx =~ /ExW/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 							  "space prohibited after that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 							if (defined $fix_elements[$n + 2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 								$fix_elements[$n + 2] =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 				# << and >> may either have or not have spaces both sides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 				} elsif ($op eq '<<' or $op eq '>>' or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 					 $op eq '&' or $op eq '^' or $op eq '|' or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 					 $op eq '+' or $op eq '-' or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 					 $op eq '*' or $op eq '/' or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 					 $op eq '%')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 				{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 					if ($check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 						if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 							if (CHK("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 								"spaces preferred around that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 								$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 								$fix_elements[$n + 2] =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 								$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 						} elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 							if (CHK("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 								"space preferred before that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 								$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 								$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 					} elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 							  "need consistent spacing around '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 							$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 							if (defined $fix_elements[$n + 2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 								$fix_elements[$n + 2] =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 				# A colon needs no spaces before when it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 				# terminating a case value or a label.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) 				} elsif ($opv eq ':C' || $opv eq ':L') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 					if ($ctx =~ /Wx./) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) 						if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 							  "space prohibited before that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) 							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) 				# All the others need spaces both sides.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) 				} elsif ($ctx !~ /[EWC]x[CWE]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) 					my $ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 					# Ignore email addresses <foo@bar>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 					if (($op eq '<' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 					     $cc =~ /^\S+\@\S+>/) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 					    ($op eq '>' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 					     $ca =~ /<\S+\@\S+$/))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) 					{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) 						$ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) 					# for asm volatile statements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 					# ignore a colon with another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) 					# colon immediately before or after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 					if (($op eq ':') &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 					    ($ca =~ /:$/ || $cc =~ /^:/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 						$ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 					# messages are ERROR, but ?: are CHK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) 					if ($ok == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 						my $msg_level = \&ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) 						$msg_level = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 						if (&{$msg_level}("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 								  "spaces required around that '$op' $at\n" . $hereptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) 							$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 							if (defined $fix_elements[$n + 2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) 								$fix_elements[$n + 2] =~ s/^\s+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) 							}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) 							$line_fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) 				$off += length($elements[$n + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) ##				print("n: <$n> GOOD: <$good>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) 				$fixed_line = $fixed_line . $good;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) 			if (($#elements % 2) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) 				$fixed_line = $fixed_line . $fix_elements[$#elements];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) 			if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) 				$fixed[$fixlinenr] = $fixed_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) # check for whitespace before a non-naked semicolon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 		if ($line =~ /^\+.*\S\s+;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 			if (WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 				 "space prohibited before semicolon\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 				1 while $fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 				    s/^(\+.*\S)\s+;/$1;/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) # check for multiple assignments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 		if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 			CHK("MULTIPLE_ASSIGNMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 			    "multiple assignments should be avoided\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) ## # check for multiple declarations, allowing for a function declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) ## # continuation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) ## 		if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) ## 		    $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) ##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) ## 			# Remove any bracketed sections to ensure we do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) ## 			# falsly report the parameters of functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) ## 			my $ln = $line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) ## 			while ($ln =~ s/\([^\(\)]*\)//g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) ## 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) ## 			if ($ln =~ /,/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) ## 				WARN("MULTIPLE_DECLARATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) ##				     "declaring multiple variables together should be avoided\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) ## 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) ## 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) #need space before brace following if, while, etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 		if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 		    $line =~ /\b(?:else|do)\{/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 				  "space required before the open brace '{'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 				$fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) ## # check for blank lines before declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) ##		if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) ##		    $prevrawline =~ /^.\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) ##			WARN("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) ##			     "No blank lines before declarations\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) ##		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) ##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) # closing brace should have a space following it when it has anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) # on the line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 		if ($line =~ /}(?!(?:,|;|\)|\}))\S/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 				  "space required after that close brace '}'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) 				    s/}((?!(?:,|;|\)))\S)/} $1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) # check spacing on square brackets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) 		if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) 				  "space prohibited after that open square bracket '['\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) 				    s/\[\s+/\[/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) 		if ($line =~ /\s\]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) 				  "space prohibited before that close square bracket ']'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) 				    s/\s+\]/\]/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) # check spacing on parentheses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) 		if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) 		    $line !~ /for\s*\(\s+;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) 				  "space prohibited after that open parenthesis '('\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) 				    s/\(\s+/\(/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) 		if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) 		    $line !~ /for\s*\(.*;\s+\)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) 		    $line !~ /:\s+\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) 				  "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) 				    s/\s+\)/\)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) # check unnecessary parentheses around addressof/dereference single $Lvals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) 		while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) 			my $var = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) 			if (CHK("UNNECESSARY_PARENTHESES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) 				"Unnecessary parentheses around $var\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) 				$fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) # check for unnecessary parentheses around function pointer uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) # ie: (foo->bar)(); should be foo->bar();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) # but not "if (foo->bar) (" to avoid some false positives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) 		if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 			my $var = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) 			if (CHK("UNNECESSARY_PARENTHESES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 				"Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 				my $var2 = deparenthesize($var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) 				$var2 =~ s/\s//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 				$fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) # check for unnecessary parentheses around comparisons in if uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) # when !drivers/staging or command-line uses --strict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) 		if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) 		    $perl_version_ok && defined($stat) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) 		    $stat =~ /(^.\s*if\s*($balanced_parens))/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) 			my $if_stat = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) 			my $test = substr($2, 1, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) 			my $herectx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) 			while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) 				my $match = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) 				# avoid parentheses around potential macro args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) 				next if ($match =~ /^\s*\w+\s*$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) 				if (!defined($herectx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) 					$herectx = $here . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) 					my $cnt = statement_rawlines($if_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) 					for (my $n = 0; $n < $cnt; $n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) 						my $rl = raw_line($linenr, $n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) 						$herectx .=  $rl . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) 						last if $rl =~ /^[ \+].*\{/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) 				CHK("UNNECESSARY_PARENTHESES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) 				    "Unnecessary parentheses around '$match'\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) #goto labels aren't indented, allow a single space however
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) 		if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) 		   !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 			if (WARN("INDENTED_LABEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 				 "labels should not be indented\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 				    s/^(.)\s+/$1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) # check if a statement with a comma should be two statements like:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) #	foo = bar(),	/* comma should be semicolon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) #	bar = baz();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 		if (defined($stat) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 		    $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 			my $cnt = statement_rawlines($stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 			my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 			WARN("SUSPECT_COMMA_SEMICOLON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 			     "Possible comma where semicolon could be used\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) # return is not a function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 		if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 			my $spacing = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 			if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 			    $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 				my $value = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 				$value = deparenthesize($value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) 				if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) 					ERROR("RETURN_PARENTHESES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 					      "return is not a function, parentheses are not required\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) 			} elsif ($spacing !~ /\s+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) 				ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 				      "space required before the open parenthesis '('\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) # unnecessary return in a void function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) # at end-of-function, with the previous line a single leading tab, then return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) # and the line before that not a goto label target like "out:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) 		if ($sline =~ /^[ \+]}\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) 		    $prevline =~ /^\+\treturn\s*;\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) 		    $linenr >= 3 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) 		    $lines[$linenr - 3] =~ /^[ +]/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) 		    $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) 			WARN("RETURN_VOID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) 			     "void function return statements are not generally useful\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061)                }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) # if statements using unnecessary parentheses - ie: if ((foo == bar))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) 		    $line =~ /\bif\s*((?:\(\s*){2,})/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) 			my $openparens = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) 			my $count = $openparens =~ tr@\(@\(@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) 			my $msg = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) 			if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) 				my $comp = $4;	#Not $1 because of $LvalOrFunc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) 				$msg = " - maybe == should be = ?" if ($comp eq "==");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 				WARN("UNNECESSARY_PARENTHESES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 				     "Unnecessary parentheses$msg\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) # comparisons with a constant or upper case identifier on the left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) #	avoid cases like "foo + BAR < baz"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) #	only fix matches surrounded by parentheses to avoid incorrect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) #	conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 		    $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) 			my $lead = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 			my $const = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) 			my $comp = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) 			my $to = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 			my $newcomp = $comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 			if ($lead !~ /(?:$Operators|\.)\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 			    $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 			    WARN("CONSTANT_COMPARISON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 				 "Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 				if ($comp eq "<") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) 					$newcomp = ">";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 				} elsif ($comp eq "<=") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) 					$newcomp = ">=";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 				} elsif ($comp eq ">") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 					$newcomp = "<";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 				} elsif ($comp eq ">=") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 					$newcomp = "<=";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 				$fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) # Return of what appears to be an errno should normally be negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 		if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) 			my $name = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) 			if ($name ne 'EOF' && $name ne 'ERROR') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) 				WARN("USE_NEGATIVE_ERRNO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) 				     "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) # Need a space before open parenthesis after if, while etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 		if ($line =~ /\b(if|while|for|switch)\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) 				  "space required before the open parenthesis '('\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) 				    s/\b(if|while|for|switch)\(/$1 \(/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) # Check for illegal assignment in if conditional -- and check for trailing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) # statements after the conditional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) 		if ($line =~ /do\s*(?!{)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) 			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) 				ctx_statement_block($linenr, $realcnt, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) 					if (!defined $stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 			my ($stat_next) = ctx_statement_block($line_nr_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) 						$remain_next, $off_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 			$stat_next =~ s/\n./\n /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) 			##print "stat<$stat> stat_next<$stat_next>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) 			if ($stat_next =~ /^\s*while\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) 				# If the statement carries leading newlines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) 				# then count those as offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) 				my ($whitespace) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) 					($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) 				my $offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) 					statement_rawlines($whitespace) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) 				$suppress_whiletrailers{$line_nr_next +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) 								$offset} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) 		if (!defined $suppress_whiletrailers{$linenr} &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) 		    defined($stat) && defined($cond) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) 		    $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) 			my ($s, $c) = ($stat, $cond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 			if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 				if (ERROR("ASSIGN_IN_IF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) 					  "do not use assignment in if condition\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 				    $fix && $perl_version_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) 					if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 						my $space = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 						my $not = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 						my $statement = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 						my $assigned = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 						my $test = $8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 						my $against = $9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) 						my $brace = $15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 						fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) 						fix_insert_line($fixlinenr, "$space$statement;");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) 						my $newline = "${space}if (";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) 						$newline .= '!' if defined($not);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) 						$newline .= '(' if (defined $not && defined($test) && defined($against));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 						$newline .= "$assigned";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) 						$newline .= " $test $against" if (defined($test) && defined($against));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) 						$newline .= ')' if (defined $not && defined($test) && defined($against));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) 						$newline .= ')';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) 						$newline .= " {" if (defined($brace));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) 						fix_insert_line($fixlinenr + 1, $newline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) 			# Find out what is on the end of the line after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) 			# conditional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) 			substr($s, 0, length($c), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) 			$s =~ s/\n.*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) 			$s =~ s/$;//g;	# Remove any comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) 			if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) 			    $c !~ /}\s*while\s*/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) 				# Find out how long the conditional actually is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) 				my @newlines = ($c =~ /\n/gs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) 				my $cond_lines = 1 + $#newlines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) 				my $stat_real = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 				$stat_real = raw_line($linenr, $cond_lines)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) 							. "\n" if ($cond_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 				if (defined($stat_real) && $cond_lines > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) 					$stat_real = "[...]\n$stat_real";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) 				ERROR("TRAILING_STATEMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) 				      "trailing statements should be on next line\n" . $herecurr . $stat_real);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) # Check for bitwise tests written as boolean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) 		if ($line =~ /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) 			(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) 				(?:\[|\(|\&\&|\|\|)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) 				\s*0[xX][0-9]+\s*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) 				(?:\&\&|\|\|)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) 			|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) 				(?:\&\&|\|\|)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) 				\s*0[xX][0-9]+\s*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) 				(?:\&\&|\|\||\)|\])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) 			)/x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 			WARN("HEXADECIMAL_BOOLEAN_TEST",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 			     "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) # if and else should not have general statements after it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) 		if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) 			my $s = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) 			$s =~ s/$;//g;	# Remove any comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) 			if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) 				ERROR("TRAILING_STATEMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) 				      "trailing statements should be on next line\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) # if should not continue a brace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) 		if ($line =~ /}\s*if\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 			ERROR("TRAILING_STATEMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) 			      "trailing statements should be on next line (or did you mean 'else if'?)\n" .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 				$herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) # case and default should not have general statements after them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 		if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 		    $line !~ /\G(?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 			(?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 			\s*return\s+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) 		    )/xg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) 			ERROR("TRAILING_STATEMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 			      "trailing statements should be on next line\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) 		# Check for }<nl>else {, these must be at the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 		# indent level to be relevant to each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) 		if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) 		    $previndent == $indent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) 			if (ERROR("ELSE_AFTER_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) 				  "else should follow close brace '}'\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) 			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) 				fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) 				my $fixedline = $prevrawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) 				$fixedline =~ s/}\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) 				if ($fixedline !~ /^\+\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) 					fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) 				$fixedline = $rawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) 				$fixedline =~ s/^(.\s*)else/$1} else/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) 				fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) 		if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 		    $previndent == $indent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) 			my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) 			# Find out what is on the end of the line after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) 			# conditional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) 			substr($s, 0, length($c), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 			$s =~ s/\n.*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 			if ($s =~ /^\s*;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) 				if (ERROR("WHILE_AFTER_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) 					  "while should follow close brace '}'\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) 				    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) 					fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) 					fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) 					my $fixedline = $prevrawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) 					my $trailing = $rawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) 					$trailing =~ s/^\+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) 					$trailing = trim($trailing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) 					$fixedline =~ s/}\s*$/} $trailing/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) 					fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) #Specific variable tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 		while ($line =~ m{($Constant|$Lval)}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 			my $var = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) #CamelCase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 			if ($var !~ /^$Constant$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) 			    $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) #Ignore Page<foo> variants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) 			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) #Ignore SI style variants like nS, mV and dB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) #(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) 			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) #Ignore some three character SI units explicitly, like MiB and KHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) 			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) 				while ($var =~ m{($Ident)}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) 					my $word = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) 					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) 					if ($check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) 						seed_camelcase_includes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) 						if (!$file && !$camelcase_file_seeded) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) 							seed_camelcase_file($realfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) 							$camelcase_file_seeded = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) 					if (!defined $camelcase{$word}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 						$camelcase{$word} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 						CHK("CAMELCASE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 						    "Avoid CamelCase: <$word>\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) #no spaces allowed after \ in define
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 		if ($line =~ /\#\s*define.*\\\s+$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) 			if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) 				 "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 				$fixed[$fixlinenr] =~ s/\s+$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) # warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) # itself <asm/foo.h> (uses RAW line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) 		if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) 			my $file = "$1.h";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) 			my $checkfile = "include/linux/$file";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) 			if (-f "$root/$checkfile" &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) 			    $realfile ne $checkfile &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) 			    $1 !~ /$allowed_asm_includes/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) 				my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) 				if ($asminclude > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) 					if ($realfile =~ m{^arch/}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) 						CHK("ARCH_INCLUDE_LINUX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) 						    "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) 						WARN("INCLUDE_LINUX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 						     "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) # multi-statement macros should be enclosed in a do while loop, grab the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) # first statement and ensure its the whole macro if its not enclosed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) # in a known good container
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) 		if ($realfile !~ m@/vmlinux.lds.h$@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) 		    $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) 			my $ln = $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) 			my $cnt = $realcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) 			my ($off, $dstat, $dcond, $rest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) 			my $ctx = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) 			my $has_flow_statement = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) 			my $has_arg_concat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) 			($dstat, $dcond, $ln, $cnt, $off) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) 				ctx_statement_block($linenr, $realcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) 			$ctx = $dstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) 			#print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) 			#print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) 			$has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) 			$has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) 			$dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) 			my $define_args = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) 			my $define_stmt = $dstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) 			my @def_args = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) 			if (defined $define_args && $define_args ne "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) 				$define_args = substr($define_args, 1, length($define_args) - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) 				$define_args =~ s/\s*//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) 				$define_args =~ s/\\\+?//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 				@def_args = split(",", $define_args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 			$dstat =~ s/$;//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 			$dstat =~ s/\\\n.//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) 			$dstat =~ s/^\s*//s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 			$dstat =~ s/\s*$//s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) 			# Flatten any parentheses and braces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 			while ($dstat =~ s/\([^\(\)]*\)/1u/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) 			       $dstat =~ s/\{[^\{\}]*\}/1u/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 			       $dstat =~ s/.\[[^\[\]]*\]/1u/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 			# Flatten any obvious string concatenation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 			while ($dstat =~ s/($String)\s*$Ident/$1/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 			       $dstat =~ s/$Ident\s*($String)/$1/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 			# Make asm volatile uses seem like a generic function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 			$dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) 			my $exceptions = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 				$Declare|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) 				module_param_named|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) 				MODULE_PARM_DESC|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) 				DECLARE_PER_CPU|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) 				DEFINE_PER_CPU|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) 				__typeof__\(|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) 				union|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 				struct|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 				\.$Ident\s*=\s*|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 				^\"|\"$|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 				^\[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 			}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) 			#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 			$ctx =~ s/\n*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) 			my $stmt_cnt = statement_rawlines($ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 			my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) 			if ($dstat ne '' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) 			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) 			    $dstat !~ /^(?:$Ident|-?$Constant);$/ &&			# foo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 			    $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ &&		# 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) 			    $dstat !~ /^'X'$/ && $dstat !~ /^'XX'$/ &&			# character constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) 			    $dstat !~ /$exceptions/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 			    $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&		# stringification #foo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 			    $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&	# do {...} while (...); // do {...} while (...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) 			    $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ &&		# while (...) {...}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) 			    $dstat !~ /^for\s*$Constant$/ &&				# for (...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) 			    $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ &&	# for (...) bar()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) 			    $dstat !~ /^do\s*{/ &&					# do {...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) 			    $dstat !~ /^\(\{/ &&						# ({...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) 			    $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) 				if ($dstat =~ /^\s*if\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 					ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) 					      "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) 				} elsif ($dstat =~ /;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) 					ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) 					      "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) 					ERROR("COMPLEX_MACRO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 					      "Macros with complex values should be enclosed in parentheses\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 			# Make $define_stmt single line, comment-free, etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) 			my @stmt_array = split('\n', $define_stmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 			my $first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 			$define_stmt = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 			foreach my $l (@stmt_array) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 				$l =~ s/\\$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) 				if ($first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 					$define_stmt = $l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) 					$first = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) 				} elsif ($l =~ /^[\+ ]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) 					$define_stmt .= substr($l, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) 			$define_stmt =~ s/$;//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) 			$define_stmt =~ s/\s+/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) 			$define_stmt = trim($define_stmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) # check if any macro arguments are reused (ignore '...' and 'type')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) 			foreach my $arg (@def_args) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) 			        next if ($arg =~ /\.\.\./);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 			        next if ($arg =~ /^type$/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 				my $tmp_stmt = $define_stmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 				$tmp_stmt =~ s/\b(sizeof|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 				$tmp_stmt =~ s/\#+\s*$arg\b//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 				$tmp_stmt =~ s/\b$arg\s*\#\#//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) 				my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 				if ($use_cnt > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 					CHK("MACRO_ARG_REUSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 					    "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 				    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) # check if any macro arguments may have other precedence issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 				if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 				    ((defined($1) && $1 ne ',') ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) 				     (defined($2) && $2 ne ','))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 					CHK("MACRO_ARG_PRECEDENCE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) 					    "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) # check for macros with flow control, but without ## concatenation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) # ## concatenation is commonly a macro that defines a function so ignore those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) 			if ($has_flow_statement && !$has_arg_concat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) 				my $cnt = statement_rawlines($ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) 				my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) 				WARN("MACRO_WITH_FLOW_CONTROL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) 				     "Macros with flow control statements should be avoided\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) # check for line continuations outside of #defines, preprocessor #, and asm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 			if ($prevline !~ /^..*\\$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 			    $line !~ /^\+\s*\#.*\\$/ &&		# preprocessor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 			    $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ &&	# asm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 			    $line =~ /^\+.*\\$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) 				WARN("LINE_CONTINUATIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) 				     "Avoid unnecessary line continuations\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) # do {} while (0) macro tests:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) # single-statement macros do not need to be enclosed in do while (0) loop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) # macro should not end with a semicolon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) 		    $realfile !~ m@/vmlinux.lds.h$@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) 		    $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 			my $ln = $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 			my $cnt = $realcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 			my ($off, $dstat, $dcond, $rest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 			my $ctx = '';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 			($dstat, $dcond, $ln, $cnt, $off) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 				ctx_statement_block($linenr, $realcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 			$ctx = $dstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) 			$dstat =~ s/\\\n.//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 			$dstat =~ s/$;/ /g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) 			if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) 				my $stmts = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 				my $semis = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) 				$ctx =~ s/\n*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) 				my $cnt = statement_rawlines($ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 				my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) 				if (($stmts =~ tr/;/;/) == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 				    $stmts !~ /^\s*(if|while|for|switch)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 					WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) 					     "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 				if (defined $semis && $semis ne "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) 					WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 					     "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 			} elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 				$ctx =~ s/\n*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 				my $cnt = statement_rawlines($ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 				my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 				WARN("TRAILING_SEMICOLON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 				     "macros should not use a trailing semicolon\n" . "$herectx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) # check for redundant bracing round if etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) 		if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) 			my ($level, $endln, @chunks) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) 				ctx_statement_full($linenr, $realcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) 			#print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) 			#print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) 			if ($#chunks > 0 && $level == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) 				my @allowed = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) 				my $allow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) 				my $seen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) 				my $herectx = $here . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) 				my $ln = $linenr - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) 				for my $chunk (@chunks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) 					my ($cond, $block) = @{$chunk};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) 					# If the condition carries leading newlines, then count those as offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) 					my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) 					my $offset = statement_rawlines($whitespace) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) 					$allowed[$allow] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) 					#print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) 					# We have looked at and allowed this specific line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 					$suppress_ifbraces{$ln + $offset} = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) 					$herectx .= "$rawlines[$ln + $offset]\n[...]\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 					$ln += statement_rawlines($block) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) 					substr($block, 0, length($cond), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 					$seen++ if ($block =~ /^\s*{/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 					#print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) 					if (statement_lines($cond) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) 						#print "APW: ALLOWED: cond<$cond>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) 						$allowed[$allow] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) 					if ($block =~/\b(?:if|for|while)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 						#print "APW: ALLOWED: block<$block>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) 						$allowed[$allow] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) 					if (statement_block_size($block) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) 						#print "APW: ALLOWED: lines block<$block>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) 						$allowed[$allow] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 					$allow++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 				if ($seen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) 					my $sum_allowed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 					foreach (@allowed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) 						$sum_allowed += $_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) 					if ($sum_allowed == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 						WARN("BRACES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 						     "braces {} are not necessary for any arm of this statement\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 					} elsif ($sum_allowed != $allow &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 						 $seen != $allow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 						CHK("BRACES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 						    "braces {} should be used on all arms of this statement\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) 		if (!defined $suppress_ifbraces{$linenr - 1} &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) 					$line =~ /\b(if|while|for|else)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) 			my $allowed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 			# Check the pre-context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 			if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) 				#print "APW: ALLOWED: pre<$1>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 				$allowed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) 			my ($level, $endln, @chunks) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 				ctx_statement_full($linenr, $realcnt, $-[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 			# Check the condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) 			my ($cond, $block) = @{$chunks[0]};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 			#print "CHECKING<$linenr> cond<$cond> block<$block>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) 			if (defined $cond) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) 				substr($block, 0, length($cond), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) 			if (statement_lines($cond) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) 				#print "APW: ALLOWED: cond<$cond>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) 				$allowed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) 			if ($block =~/\b(?:if|for|while)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) 				#print "APW: ALLOWED: block<$block>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) 				$allowed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) 			if (statement_block_size($block) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) 				#print "APW: ALLOWED: lines block<$block>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) 				$allowed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) 			# Check the post-context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) 			if (defined $chunks[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) 				my ($cond, $block) = @{$chunks[1]};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) 				if (defined $cond) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) 					substr($block, 0, length($cond), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) 				if ($block =~ /^\s*\{/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 					#print "APW: ALLOWED: chunk-1 block<$block>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) 					$allowed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 			if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) 				my $cnt = statement_rawlines($block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) 				my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) 				WARN("BRACES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) 				     "braces {} are not necessary for single statement blocks\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) # check for single line unbalanced braces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) 		if ($sline =~ /^.\s*\}\s*else\s*$/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) 		    $sline =~ /^.\s*else\s*\{\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) 			CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) # check for unnecessary blank lines around braces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 		if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 			if (CHK("BRACES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) 				"Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) 			    $fix && $prevrawline =~ /^\+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 				fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 		if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 			if (CHK("BRACES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 				"Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) # no volatiles please
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) 		my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 			WARN("VOLATILE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) 			     "Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) # Check for user-visible strings broken across lines, which breaks the ability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) # to grep for the string.  Make exceptions when the previous string ends in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) # newline (multiple lines in one string constant) or '\t', '\r', ';', or '{'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) 		if ($line =~ /^\+\s*$String/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) 		    $prevline =~ /"\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) 		    $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) 			if (WARN("SPLIT_STRING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) 				 "quoted string split across lines\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) 				     $fix &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 				     $prevrawline =~ /^\+.*"\s*$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) 				     $last_coalesced_string_linenr != $linenr - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) 				my $extracted_string = get_quoted_string($line, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) 				my $comma_close = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) 				if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) 					$comma_close = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 				fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) 				fix_delete_line($fixlinenr, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 				my $fixedline = $prevrawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) 				$fixedline =~ s/"\s*$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) 				$fixedline .= substr($extracted_string, 1) . trim($comma_close);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 				fix_insert_line($fixlinenr - 1, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) 				$fixedline = $rawline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 				$fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) 				if ($fixedline !~ /\+\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) 					fix_insert_line($fixlinenr, $fixedline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) 				$last_coalesced_string_linenr = $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) # check for missing a space in a string concatenation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) 		if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 			WARN('MISSING_SPACE',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) 			     "break quoted strings at a space character\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) # check for an embedded function name in a string when the function is known
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) # This does not work very well for -f --file checking as it depends on patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) # context providing the function name or a single line form for in-file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) # function declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) 		if ($line =~ /^\+.*$String/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) 		    defined($context_function) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) 		    get_quoted_string($line, $rawline) =~ /\b$context_function\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) 		    length(get_quoted_string($line, $rawline)) != (length($context_function) + 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) 			WARN("EMBEDDED_FUNCTION_NAME",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) 			     "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) # check for spaces before a quoted newline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) 		if ($rawline =~ /^.*\".*\s\\n/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) 			if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) 				 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) 				$fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) # concatenated string without spaces between elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) 		if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 			if (CHK("CONCATENATED_STRING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 				"Concatenated strings should use spaces between elements\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 				while ($line =~ /($String)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 					my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) 					$fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) 					$fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) # uncoalesced string fragments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) 		if ($line =~ /$String\s*"/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) 			if (WARN("STRING_FRAGMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) 				 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) 				while ($line =~ /($String)(?=\s*")/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) 					my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) 					$fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) # check for non-standard and hex prefixed decimal printf formats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) 		my $show_L = 1;	#don't show the same defect twice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) 		my $show_Z = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) 		while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) 			my $string = substr($rawline, $-[1], $+[1] - $-[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) 			$string =~ s/%%/__/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) 			# check for %L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) 			if ($show_L && $string =~ /%[\*\d\.\$]*L([diouxX])/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) 				WARN("PRINTF_L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 				     "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) 				$show_L = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) 			# check for %Z
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 			if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) 				WARN("PRINTF_Z",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 				     "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) 				$show_Z = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) 			# check for 0x<decimal>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) 			if ($string =~ /0x%[\*\d\.\$\Llzth]*[diou]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) 				ERROR("PRINTF_0XDECIMAL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) 				      "Prefixing 0x with decimal output is defective\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) # check for line continuations in quoted strings with odd counts of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 		if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 			WARN("LINE_CONTINUATIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 			     "Avoid line continuations in quoted strings\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) # warn about #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) 		if ($line =~ /^.\s*\#\s*if\s+0\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 			WARN("IF_0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 			     "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) # warn about #if 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 		if ($line =~ /^.\s*\#\s*if\s+1\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 			WARN("IF_1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 			     "Consider removing the #if 1 and its #endif\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) # check for needless "if (<foo>) fn(<foo>)" uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 		if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 			my $tested = quotemeta($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 			my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 			if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 				my $func = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 				if (WARN('NEEDLESS_IF',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 					 "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 					my $do_fix = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) 					my $leading_tabs = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) 					my $new_leading_tabs = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) 					if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) 						$leading_tabs = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) 						$do_fix = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) 					if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) 						$new_leading_tabs = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) 						if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) 							$do_fix = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) 						$do_fix = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) 					if ($do_fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) 						fix_delete_line($fixlinenr - 1, $prevrawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) 						$fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) # check for unnecessary "Out of Memory" messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) 		if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) 		    $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) 		    (defined $1 || defined $3) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) 		    $linenr > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 			my $testval = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) 			my $testline = $lines[$linenr - 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 			my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) #			print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) 			if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) 			    $s !~ /\b__GFP_NOWARN\b/ ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) 				WARN("OOM_MESSAGE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) 				     "Possible unnecessary 'out of memory' message\n" . $hereprev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) # check for logging functions with KERN_<LEVEL>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 		if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 		    $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 			my $level = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 			if (WARN("UNNECESSARY_KERN_LEVEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 				 "Possible unnecessary $level\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 				$fixed[$fixlinenr] =~ s/\s*$level\s*//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) # check for logging continuations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) 		if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) 			WARN("LOGGING_CONTINUATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) 			     "Avoid logging continuation uses where feasible\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) # check for mask then right shift without a parentheses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) 		    $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) 		    $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) 			WARN("MASK_THEN_SHIFT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) 			     "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) # check for pointer comparisons to NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) 		if ($perl_version_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) 			while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) 				my $val = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) 				my $equal = "!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) 				$equal = "" if ($4 eq "!=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) 				if (CHK("COMPARISON_TO_NULL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 					"Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) 					    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 					$fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) # check for bad placement of section $InitAttribute (e.g.: __initdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 		if ($line =~ /(\b$InitAttribute\b)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 			my $attr = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 			if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 				my $ptr = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 				my $var = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 				if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 				      ERROR("MISPLACED_INIT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 					    "$attr should be placed after $var\n" . $herecurr)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 				     ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 				      WARN("MISPLACED_INIT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 					   "$attr should be placed after $var\n" . $herecurr))) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 					$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;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) # check for $InitAttributeData (ie: __initdata) with const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 		if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 			my $attr = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 			$attr =~ /($InitAttributePrefix)(.*)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 			my $attr_prefix = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 			my $attr_type = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 			if (ERROR("INIT_ATTRIBUTE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 				  "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 				    s/$InitAttributeData/${attr_prefix}initconst/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) # check for $InitAttributeConst (ie: __initconst) without const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 		if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 			my $attr = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 			if (ERROR("INIT_ATTRIBUTE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 				  "Use of $attr requires a separate use of const\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 				my $lead = $fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 				    /(^\+\s*(?:static\s+))/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 				$lead = rtrim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 				$lead = "$lead " if ($lead !~ /^\+$/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 				$lead = "${lead}const ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 				$fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) # check for __read_mostly with const non-pointer (should just be const)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 		if ($line =~ /\b__read_mostly\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 		    $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 			if (ERROR("CONST_READ_MOSTLY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 				  "Invalid use of __read_mostly with const type\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) 				$fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) # don't use __constant_<foo> functions outside of include/uapi/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) 		if ($realfile !~ m@^include/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) 		    $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) 			my $constant_func = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) 			my $func = $constant_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 			$func =~ s/^__constant_//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 			if (WARN("CONSTANT_CONVERSION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) 				 "$constant_func should be $func\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) 				$fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) # prefer usleep_range over udelay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 		if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 			my $delay = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 			# ignore udelay's < 10, however
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 			if (! ($delay < 10) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 				CHK("USLEEP_RANGE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) 				    "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) 			if ($delay > 2000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) 				WARN("LONG_UDELAY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) 				     "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) # warn about unexpectedly long msleep's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) 		if ($line =~ /\bmsleep\s*\((\d+)\);/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 			if ($1 < 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 				WARN("MSLEEP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) 				     "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) # check for comparisons of jiffies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 		if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) 			WARN("JIFFIES_COMPARISON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) 			     "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) # check for comparisons of get_jiffies_64()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) 		if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) 			WARN("JIFFIES_COMPARISON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) 			     "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) # warn about #ifdefs in C files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) #		if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) #			print "#ifdef in C files should be avoided\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) #			print "$herecurr";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) #			$clean = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) #		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) # warn about spacing in #ifdefs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 		if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 			if (ERROR("SPACING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 				  "exactly one space required after that #$1\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 				$fixed[$fixlinenr] =~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 				    s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) # check for spinlock_t definitions without a comment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 		if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 		    $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) 			my $which = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) 			if (!ctx_has_comment($first_line, $linenr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) 				CHK("UNCOMMENTED_DEFINITION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) 				    "$1 definition without comment\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) # check for memory barriers without a comment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) 		my $barriers = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 			mb|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) 			rmb|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 			wmb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) 		}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) 		my $barrier_stems = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) 			mb__before_atomic|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) 			mb__after_atomic|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 			store_release|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 			load_acquire|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 			store_mb|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 			(?:$barriers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 		}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 		my $all_barriers = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) 			(?:$barriers)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 			smp_(?:$barrier_stems)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 			virt_(?:$barrier_stems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) 		}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) 		if ($line =~ /\b(?:$all_barriers)\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) 			if (!ctx_has_comment($first_line, $linenr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) 				WARN("MEMORY_BARRIER",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) 				     "memory barrier without comment\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 		my $underscore_smp_barriers = qr{__smp_(?:$barrier_stems)}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) 		if ($realfile !~ m@^include/asm-generic/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) 		    $realfile !~ m@/barrier\.h$@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) 		    $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 		    $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) 			WARN("MEMORY_BARRIER",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) 			     "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) # check for waitqueue_active without a comment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) 		if ($line =~ /\bwaitqueue_active\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 			if (!ctx_has_comment($first_line, $linenr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 				WARN("WAITQUEUE_ACTIVE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 				     "waitqueue_active without comment\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) # check for data_race without a comment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 		if ($line =~ /\bdata_race\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 			if (!ctx_has_comment($first_line, $linenr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 				WARN("DATA_RACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 				     "data_race without comment\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) # check of hardware specific defines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 		if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 			CHK("ARCH_DEFINES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 			    "architecture specific defines should be avoided\n" .  $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) # check that the storage class is not after a type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 		if ($line =~ /\b($Type)\s+($Storage)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 			WARN("STORAGE_CLASS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) 			     "storage class '$2' should be located before type '$1'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) # Check that the storage class is at the beginning of a declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) 		if ($line =~ /\b$Storage\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) 		    $line !~ /^.\s*$Storage/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 		    $line =~ /^.\s*(.+?)\$Storage\s/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) 		    $1 !~ /[\,\)]\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 			WARN("STORAGE_CLASS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) 			     "storage class should be at the beginning of the declaration\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) # check the location of the inline attribute, that it is between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) # storage class and type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) 		if ($line =~ /\b$Type\s+$Inline\b/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) 		    $line =~ /\b$Inline\s+$Storage\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) 			ERROR("INLINE_LOCATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) 			      "inline keyword should sit between storage class and type\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) # Check for __inline__ and __inline, prefer inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 		    $line =~ /\b(__inline__|__inline)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) 			if (WARN("INLINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 				 "plain inline is preferred over $1\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) 				$fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) # Check for __attribute__ packed, prefer __packed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) 		    $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) 			WARN("PREFER_PACKED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) 			     "__packed is preferred over __attribute__((packed))\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) # Check for __attribute__ aligned, prefer __aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 		    $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) 			WARN("PREFER_ALIGNED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) 			     "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) # Check for __attribute__ section, prefer __section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) 		    $line =~ /\b__attribute__\s*\(\s*\(.*_*section_*\s*\(\s*("[^"]*")/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) 			my $old = substr($rawline, $-[1], $+[1] - $-[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) 			my $new = substr($old, 1, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) 			if (WARN("PREFER_SECTION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) 				 "__section($new) is preferred over __attribute__((section($old)))\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) 				$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) # Check for __attribute__ format(printf, prefer __printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) 		    $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) 			if (WARN("PREFER_PRINTF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 				 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 				$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) # Check for __attribute__ format(scanf, prefer __scanf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) 		    $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) 			if (WARN("PREFER_SCANF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) 				 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) 				$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) # Check for __attribute__ weak, or __weak declarations (may have link issues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) 		    $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 		    ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 		     $line =~ /\b__weak\b/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 			ERROR("WEAK_DECLARATION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 			      "Using weak declarations can have unintended link defects\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) # check for c99 types like uint8_t used outside of uapi/ and tools/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) 		if ($realfile !~ m@\binclude/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) 		    $realfile !~ m@\btools/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) 		    $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 			my $type = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) 			if ($type =~ /\b($typeC99Typedefs)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) 				$type = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) 				my $kernel_type = 'u';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) 				$kernel_type = 's' if ($type =~ /^_*[si]/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 				$type =~ /(\d+)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) 				$kernel_type .= $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) 				if (CHK("PREFER_KERNEL_TYPES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) 					"Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) 					$fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) # check for cast of C90 native int or longer types constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 		if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) 			my $cast = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) 			my $const = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 			if (WARN("TYPECAST_INT_CONSTANT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 				 "Unnecessary typecast of c90 int constant\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 				my $suffix = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 				my $newconst = $const;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) 				$newconst =~ s/${Int_type}$//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) 				$suffix .= 'U' if ($cast =~ /\bunsigned\b/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) 				if ($cast =~ /\blong\s+long\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) 					$suffix .= 'LL';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 				} elsif ($cast =~ /\blong\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 					$suffix .= 'L';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 				$fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) # check for sizeof(&)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) 		if ($line =~ /\bsizeof\s*\(\s*\&/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) 			WARN("SIZEOF_ADDRESS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) 			     "sizeof(& should be avoided\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) # check for sizeof without parenthesis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) 		if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 			if (WARN("SIZEOF_PARENTHESIS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 				 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) 				$fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) # check for struct spinlock declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) 		if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) 			WARN("USE_SPINLOCK_T",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) 			     "struct spinlock should be spinlock_t\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) # check for seq_printf uses that could be seq_puts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) 		if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) 			my $fmt = get_quoted_string($line, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) 			$fmt =~ s/%%//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) 			if ($fmt !~ /%/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 				if (WARN("PREFER_SEQ_PUTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) 					 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 					$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) # check for vsprintf extension %p<foo> misuses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) 		    $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) 		    $1 !~ /^_*volatile_*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) 			my $stat_real;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 			my $lc = $stat =~ tr@\n@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) 			$lc = $lc + $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 		        for (my $count = $linenr; $count <= $lc; $count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 				my $specifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 				my $extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 				my $qualifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 				my $bad_specifier = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 				my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 				$fmt =~ s/%%//g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) 				while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*))/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 					$specifier = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) 					$extension = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 					$qualifier = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 					if ($extension !~ /[SsBKRraEehMmIiUDdgVCbGNOxtf]/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) 					    ($extension eq "f" &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 					     defined $qualifier && $qualifier !~ /^w/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 						$bad_specifier = $specifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 						last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 					if ($extension eq "x" && !defined($stat_real)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 						if (!defined($stat_real)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 							$stat_real = get_stat_real($linenr, $lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 						WARN("VSPRINTF_SPECIFIER_PX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 						     "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");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) 				if ($bad_specifier ne "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 					my $stat_real = get_stat_real($linenr, $lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) 					my $ext_type = "Invalid";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 					my $use = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 					if ($bad_specifier =~ /p[Ff]/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) 						$use = " - use %pS instead";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 						$use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) 					WARN("VSPRINTF_POINTER_EXTENSION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) 					     "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) # Check for misused memsets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 		    $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) 			my $ms_addr = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 			my $ms_val = $7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) 			my $ms_size = $12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) 			if ($ms_size =~ /^(0x|)0$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) 				ERROR("MEMSET",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) 				      "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 			} elsif ($ms_size =~ /^(0x|)1$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) 				WARN("MEMSET",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 				     "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) #		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) #		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) #		    $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) #			if (WARN("PREFER_ETHER_ADDR_COPY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) #				 "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) #			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) #				$fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) #			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) #		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) #		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) #		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) #		    $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) #			WARN("PREFER_ETHER_ADDR_EQUAL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) #			     "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) #		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) # check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) # check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) #		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) #		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) #		    $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) #			my $ms_val = $7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) #			if ($ms_val =~ /^(?:0x|)0+$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) #				if (WARN("PREFER_ETH_ZERO_ADDR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) #					 "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) #				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) #					$fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) #				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) #			} elsif ($ms_val =~ /^(?:0xff|255)$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) #				if (WARN("PREFER_ETH_BROADCAST_ADDR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) #					 "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) #				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) #					$fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) #				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) #			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) #		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) # typecasts on min/max could be min_t/max_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 		    $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 			if (defined $2 || defined $7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 				my $call = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 				my $cast1 = deparenthesize($2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) 				my $arg1 = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 				my $cast2 = deparenthesize($7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) 				my $arg2 = $8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) 				my $cast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 				if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 					$cast = "$cast1 or $cast2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 				} elsif ($cast1 ne "") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) 					$cast = $cast1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 					$cast = $cast2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 				WARN("MINMAX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 				     "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) # check usleep_range arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) 		    $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) 			my $min = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) 			my $max = $7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) 			if ($min eq $max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) 				WARN("USLEEP_RANGE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) 				     "usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) 			} elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) 				 $min > $max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 				WARN("USLEEP_RANGE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 				     "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) # check for naked sscanf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 		    $line =~ /\bsscanf\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 		    ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) 		     $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 		     $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) 			my $lc = $stat =~ tr@\n@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) 			$lc = $lc + $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) 			my $stat_real = get_stat_real($linenr, $lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) 			WARN("NAKED_SSCANF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) 			     "unchecked sscanf return value\n" . "$here\n$stat_real\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) # check for simple sscanf that should be kstrto<foo>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) 		    $line =~ /\bsscanf\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 			my $lc = $stat =~ tr@\n@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 			$lc = $lc + $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) 			my $stat_real = get_stat_real($linenr, $lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 			if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) 				my $format = $6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 				my $count = $format =~ tr@%@%@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) 				if ($count == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 				    $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) 					WARN("SSCANF_TO_KSTRTO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 					     "Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) # check for new externs in .h files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) 		if ($realfile =~ /\.h$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) 		    $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) 			if (CHK("AVOID_EXTERNS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) 				"extern prototypes should be avoided in .h files\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464) 				$fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) # check for new externs in .c files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) 		if ($realfile =~ /\.c$/ && defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) 		    $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 			my $function_name = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 			my $paren_space = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 			my $s = $stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) 			if (defined $cond) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) 				substr($s, 0, length($cond), '');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) 			if ($s =~ /^\s*;/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) 				WARN("AVOID_EXTERNS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) 				     "externs should be avoided in .c files\n" .  $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 			if ($paren_space =~ /\n/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) 				WARN("FUNCTION_ARGUMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) 				     "arguments for function declarations should follow identifier\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) 		} elsif ($realfile =~ /\.c$/ && defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) 		    $stat =~ /^.\s*extern\s+/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) 			WARN("AVOID_EXTERNS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) 			     "externs should be avoided in .c files\n" .  $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) # check for function declarations that have arguments without identifier names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) 		if (defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) 		    $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) 		    $1 ne "void") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) 			my $args = trim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) 			while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) 				my $arg = trim($1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 				if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) 					WARN("FUNCTION_ARGUMENTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 					     "function definition argument '$arg' should also have an identifier name\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) # check for function definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 		    $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 			$context_function = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) # check for multiline function definition with misplaced open brace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 			my $ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 			my $cnt = statement_rawlines($stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 			my $herectx = $here . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 			for (my $n = 0; $n < $cnt; $n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 				my $rl = raw_line($linenr, $n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) 				$herectx .=  $rl . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 				$ok = 1 if ($rl =~ /^[ \+]\{/);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) 				$ok = 1 if ($rl =~ /\{/ && $n == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) 				last if $rl =~ /^[ \+].*\{/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 			if (!$ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) 				ERROR("OPEN_BRACE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) 				      "open brace '{' following function definitions go on the next line\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) # checks for new __setup's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) 		if ($rawline =~ /\b__setup\("([^"]*)"/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) 			my $name = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) 			if (!grep(/$name/, @setup_docs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) 				CHK("UNDOCUMENTED_SETUP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) 				    "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) # check for pointless casting of alloc functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) 		if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 			WARN("UNNECESSARY_CASTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 			     "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) # alloc style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) # p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) 		    $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) 			CHK("ALLOC_SIZEOF_STRUCT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 			    "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) # check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 		    $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) 			my $oldfunc = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) 			my $a1 = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) 			my $a2 = $10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) 			my $newfunc = "kmalloc_array";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) 			$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 			my $r1 = $a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) 			my $r2 = $a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 			if ($a1 =~ /^sizeof\s*\S/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 				$r1 = $a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 				$r2 = $a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) 			if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) 			    !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) 				my $cnt = statement_rawlines($stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) 				my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) 				if (WARN("ALLOC_WITH_MULTIPLY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) 					 "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) 				    $cnt == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) 					$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;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) # check for krealloc arg reuse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) 		    $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) 		    $1 eq $3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) 			WARN("KREALLOC_ARG_REUSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) 			     "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) # check for alloc argument mismatch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) 		if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597) 			WARN("ALLOC_ARRAY_ARGS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) 			     "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) # check for multiple semicolons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) 		if ($line =~ /;\s*;\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) 			if (WARN("ONE_SEMICOLON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) 				 "Statements terminations use 1 semicolon\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) 				$fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) # check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) 		if ($realfile !~ m@^include/uapi/@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) 		    $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) 			my $ull = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) 			$ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) 			if (CHK("BIT_MACRO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) 				"Prefer using the BIT$ull macro\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) 				$fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) # check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) 		if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) 			WARN("IS_ENABLED_CONFIG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) 			     "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) # check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) 		if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) 			my $config = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) 			if (WARN("PREFER_IS_ENABLED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) 				 "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) 				$fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) # check for /* fallthrough */ like comment, prefer fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) 		my @fallthroughs = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) 			'fallthrough',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) 			'@fallthrough@',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) 			'lint -fallthrough[ \t]*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) 			'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644) 			'(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) 			'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) 			'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) 		    );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) 		if ($raw_comment ne '') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649) 			foreach my $ft (@fallthroughs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) 				if ($raw_comment =~ /$ft/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) 					my $msg_level = \&WARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) 					$msg_level = \&CHK if ($file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) 					&{$msg_level}("PREFER_FALLTHROUGH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) 						      "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) 					last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) # check for switch/default statements without a break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) 		    $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) 			my $cnt = statement_rawlines($stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) 			my $herectx = get_stat_here($linenr, $cnt, $here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667) 			WARN("DEFAULT_NO_BREAK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) 			     "switch default: should use break\n" . $herectx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) # check for gcc specific __FUNCTION__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) 		if ($line =~ /\b__FUNCTION__\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) 			if (WARN("USE_FUNC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) 				 "__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676) 				$fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) # check for uses of __DATE__, __TIME__, __TIMESTAMP__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) 		while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) 			ERROR("DATE_TIME",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) 			      "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) # check for use of yield()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) 		if ($line =~ /\byield\s*\(\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) 			WARN("YIELD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) 			     "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n"  . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) # check for comparisons against true and false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) 		if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) 			my $lead = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) 			my $arg = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) 			my $test = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) 			my $otype = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) 			my $trail = $5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) 			my $op = "!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) 			($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) 			my $type = lc($otype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) 			if ($type =~ /^(?:true|false)$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) 				if (("$test" eq "==" && "$type" eq "true") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) 				    ("$test" eq "!=" && "$type" eq "false")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) 					$op = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) 				CHK("BOOL_COMPARISON",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) 				    "Using comparison to $otype is error prone\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) ## maybe suggesting a correct construct would better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) ##				    "Using comparison to $otype is error prone.  Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719) # check for semaphores initialized locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) 		if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) 			WARN("CONSIDER_COMPLETION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) 			     "consider using a completion\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725) # recommend kstrto* over simple_strto* and strict_strto*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) 		if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) 			WARN("CONSIDER_KSTRTO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) 			     "$1 is obsolete, use k$3 instead\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) # check for __initcall(), use device_initcall() explicitly or more appropriate function please
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) 		if ($line =~ /^.\s*__initcall\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) 			WARN("USE_DEVICE_INITCALL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) 			     "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) # check for spin_is_locked(), suggest lockdep instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) 		if ($line =~ /\bspin_is_locked\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) 			WARN("USE_LOCKDEP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) 			     "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) # check for deprecated apis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) 		if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) 			my $deprecated_api = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746) 			my $new_api = $deprecated_apis{$deprecated_api};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) 			WARN("DEPRECATED_API",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) 			     "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) # check for various structs that are normally const (ops, kgdb, device_tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) # and avoid what seem like struct definitions 'struct foo {'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) 		if (defined($const_structs) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) 		    $line !~ /\bconst\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) 		    $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) 			WARN("CONST_STRUCT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) 			     "struct $1 should normally be const\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) # use of NR_CPUS is usually wrong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) # ignore definitions of NR_CPUS and usage to define arrays as likely right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) 		if ($line =~ /\bNR_CPUS\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) 		    $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) 		    $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) 		    $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) 		    $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767) 		    $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769) 			WARN("NR_CPUS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) 			     "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) # Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) 		if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775) 			ERROR("DEFINE_ARCH_HAS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) 			      "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) # likely/unlikely comparisons similar to "(likely(foo) > 0)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781) 		    $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) 			WARN("LIKELY_MISUSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) 			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) # nested likely/unlikely calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) 		if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788) 			WARN("LIKELY_MISUSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) 			     "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) # whine mightly about in_atomic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793) 		if ($line =~ /\bin_atomic\s*\(/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794) 			if ($realfile =~ m@^drivers/@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) 				ERROR("IN_ATOMIC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) 				      "do not use in_atomic in drivers\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) 			} elsif ($realfile !~ m@^kernel/@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) 				WARN("IN_ATOMIC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) 				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) # check for mutex_trylock_recursive usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804) 		if ($line =~ /mutex_trylock_recursive/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) 			ERROR("LOCKING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) 			      "recursive locking is bad, do not use this ever.\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) # check for lockdep_set_novalidate_class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) 		if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) 		    $line =~ /__lockdep_no_validate__\s*\)/ ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812) 			if ($realfile !~ m@^kernel/lockdep@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) 			    $realfile !~ m@^include/linux/lockdep@ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) 			    $realfile !~ m@^drivers/base/core@) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) 				ERROR("LOCKDEP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816) 				      "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) 		if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) 		    $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822) 			WARN("EXPORTED_WORLD_WRITABLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) 			     "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) # check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827) # and whether or not function naming is typical and if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) # DEVICE_ATTR permissions uses are unusual too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) 		    $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*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832) 			my $var = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) 			my $perms = $2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) 			my $show = $3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) 			my $store = $4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) 			my $octal_perms = perms_to_octal($perms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) 			if ($show =~ /^${var}_show$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) 			    $store =~ /^${var}_store$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) 			    $octal_perms eq "0644") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840) 				if (WARN("DEVICE_ATTR_RW",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) 					 "Use DEVICE_ATTR_RW\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843) 					$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) 			} elsif ($show =~ /^${var}_show$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846) 				 $store =~ /^NULL$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847) 				 $octal_perms eq "0444") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848) 				if (WARN("DEVICE_ATTR_RO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849) 					 "Use DEVICE_ATTR_RO\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851) 					$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853) 			} elsif ($show =~ /^NULL$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854) 				 $store =~ /^${var}_store$/ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) 				 $octal_perms eq "0200") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) 				if (WARN("DEVICE_ATTR_WO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) 					 "Use DEVICE_ATTR_WO\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858) 				    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859) 					$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) 			} elsif ($octal_perms eq "0644" ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) 				 $octal_perms eq "0444" ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863) 				 $octal_perms eq "0200") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) 				my $newshow = "$show";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) 				$newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) 				my $newstore = $store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867) 				$newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) 				my $rename = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) 				if ($show ne $newshow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) 					$rename .= " '$show' to '$newshow'";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872) 				if ($store ne $newstore) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) 					$rename .= " '$store' to '$newstore'";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) 				WARN("DEVICE_ATTR_FUNCTIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) 				     "Consider renaming function(s)$rename\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) 				WARN("DEVICE_ATTR_PERMS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) 				     "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) # Mode permission misuses where it seems decimal should be octal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884) # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885) # o Ignore module_param*(...) uses with a decimal 0 permission as that has a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886) #   specific definition of not visible in sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) # o Ignore proc_create*(...) uses with a decimal 0 permission as that means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888) #   use the default permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) 		if ($perl_version_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) 		    defined $stat &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891) 		    $line =~ /$mode_perms_search/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) 			foreach my $entry (@mode_permission_funcs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) 				my $func = $entry->[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) 				my $arg_pos = $entry->[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) 				my $lc = $stat =~ tr@\n@@;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897) 				$lc = $lc + $linenr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) 				my $stat_real = get_stat_real($linenr, $lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) 				my $skip_args = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) 				if ($arg_pos > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) 					$arg_pos--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) 					$skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) 				my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) 				if ($stat =~ /$test/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6907) 					my $val = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6908) 					$val = $6 if ($skip_args ne "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6909) 					if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6910) 					    (($val =~ /^$Int$/ && $val !~ /^$Octal$/) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6911) 					     ($val =~ /^$Octal$/ && length($val) ne 4))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6912) 						ERROR("NON_OCTAL_PERMISSIONS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6913) 						      "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6914) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6915) 					if ($val =~ /^$Octal$/ && (oct($val) & 02)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6916) 						ERROR("EXPORTED_WORLD_WRITABLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6917) 						      "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\n" . $stat_real);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6918) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6919) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6920) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6921) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6923) # check for uses of S_<PERMS> that could be octal for readability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6924) 		while ($line =~ m{\b($multi_mode_perms_string_search)\b}g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6925) 			my $oval = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6926) 			my $octal = perms_to_octal($oval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6927) 			if (WARN("SYMBOLIC_PERMS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6928) 				 "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6929) 			    $fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6930) 				$fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6931) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6932) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6934) # validate content of MODULE_LICENSE against list from include/linux/module.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6935) 		if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6936) 			my $extracted_string = get_quoted_string($line, $rawline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6937) 			my $valid_licenses = qr{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6938) 						GPL|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6939) 						GPL\ v2|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6940) 						GPL\ and\ additional\ rights|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6941) 						Dual\ BSD/GPL|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6942) 						Dual\ MIT/GPL|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6943) 						Dual\ MPL/GPL|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6944) 						Proprietary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6945) 					}x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6946) 			if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6947) 				WARN("MODULE_LICENSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6948) 				     "unknown module license " . $extracted_string . "\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6949) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6950) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6952) # check for sysctl duplicate constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6953) 		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6954) 			WARN("DUPLICATED_SYSCTL_CONST",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6955) 				"duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6956) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6959) 	# If we have no input at all, then there is nothing to report on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6960) 	# so just keep quiet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6961) 	if ($#rawlines == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6962) 		exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6963) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6965) 	# In mailback mode only produce a report in the negative, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6966) 	# things that appear to be patches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6967) 	if ($mailback && ($clean == 1 || !$is_patch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6968) 		exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6969) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6971) 	# This is not a patch, and we are are in 'no-patch' mode so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6972) 	# just keep quiet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6973) 	if (!$chk_patch && !$is_patch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6974) 		exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6975) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6977) 	if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6978) 		ERROR("NOT_UNIFIED_DIFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6979) 		      "Does not appear to be a unified-diff format patch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6980) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6981) 	if ($is_patch && $has_commit_log && $chk_signoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6982) 		if ($signoff == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6983) 			ERROR("MISSING_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6984) 			      "Missing Signed-off-by: line(s)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6985) 		} elsif ($authorsignoff != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6986) 			# authorsignoff values:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6987) 			# 0 -> missing sign off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6988) 			# 1 -> sign off identical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6989) 			# 2 -> names and addresses match, comments mismatch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6990) 			# 3 -> addresses match, names different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6991) 			# 4 -> names match, addresses different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6992) 			# 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6994) 			my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6996) 			if ($authorsignoff == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6997) 				ERROR("NO_AUTHOR_SIGN_OFF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6998) 				      "Missing Signed-off-by: line by nominal patch author '$author'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6999) 			} elsif ($authorsignoff == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7000) 				CHK("FROM_SIGN_OFF_MISMATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7001) 				    "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7002) 			} elsif ($authorsignoff == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7003) 				WARN("FROM_SIGN_OFF_MISMATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7004) 				     "From:/Signed-off-by: email name mismatch: $sob_msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7005) 			} elsif ($authorsignoff == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7006) 				WARN("FROM_SIGN_OFF_MISMATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7007) 				     "From:/Signed-off-by: email address mismatch: $sob_msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7008) 			} elsif ($authorsignoff == 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7009) 				WARN("FROM_SIGN_OFF_MISMATCH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7010) 				     "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7011) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7012) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7015) 	print report_dump();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7016) 	if ($summary && !($clean == 1 && $quiet == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7017) 		print "$filename " if ($summary_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7018) 		print "total: $cnt_error errors, $cnt_warn warnings, " .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7019) 			(($check)? "$cnt_chk checks, " : "") .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7020) 			"$cnt_lines lines checked\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7021) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7023) 	if ($quiet == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7024) 		# If there were any defects found and not already fixing them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7025) 		if (!$clean and !$fix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7026) 			print << "EOM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7028) NOTE: For some of the reported defects, checkpatch may be able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7029)       mechanically convert to the typical style using --fix or --fix-inplace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7030) EOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7031) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7032) 		# If there were whitespace errors which cleanpatch can fix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7033) 		# then suggest that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7034) 		if ($rpt_cleaners) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7035) 			$rpt_cleaners = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7036) 			print << "EOM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7038) NOTE: Whitespace errors detected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7039)       You may wish to use scripts/cleanpatch or scripts/cleanfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7040) EOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7041) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7044) 	if ($clean == 0 && $fix &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7045) 	    ("@rawlines" ne "@fixed" ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7046) 	     $#fixed_inserted >= 0 || $#fixed_deleted >= 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7047) 		my $newfile = $filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7048) 		$newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7049) 		my $linecount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7050) 		my $f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7052) 		@fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7054) 		open($f, '>', $newfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7055) 		    or die "$P: Can't open $newfile for write\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7056) 		foreach my $fixed_line (@fixed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7057) 			$linecount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7058) 			if ($file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7059) 				if ($linecount > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7060) 					$fixed_line =~ s/^\+//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7061) 					print $f $fixed_line . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7062) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7063) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7064) 				print $f $fixed_line . "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7065) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7066) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7067) 		close($f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7069) 		if (!$quiet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7070) 			print << "EOM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7072) Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7074) Do _NOT_ trust the results written to this file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7075) Do _NOT_ submit these changes without inspecting them for correctness.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7077) This EXPERIMENTAL file is simply a convenience to help rewrite patches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7078) No warranties, expressed or implied...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7079) EOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7080) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7081) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7083) 	if ($quiet == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7084) 		print "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7085) 		if ($clean == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7086) 			print "$vname has no obvious style problems and is ready for submission.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7087) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7088) 			print "$vname has style problems, please review.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7089) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7090) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7091) 	return $clean;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7092) }