Lines Matching +full:a +full:- +full:za +full:- +full:z

2 # SPDX-License-Identifier: GPL-2.0
7 # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
8 # (c) 2010-2018 Joe Perches <joe@perches.com>
69 my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
72 my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
74 my $git_command ='export LANGUAGE=en_US.UTF-8; git';
88 -q, --quiet quiet
89 -v, --verbose verbose mode
90 --no-tree run without a kernel tree
91 --no-signoff do not check for 'Signed-off-by' line
92 --no-fixes-tag do not check for 'Fixes:' tag
93 --patch treat FILE as patchfile (default)
94 --emacs emacs compile window format
95 --terse one line per report
96 --showfile emit diffed file position, not input file position
97 -g, --git treat FILE as a single commit or git revision range
105 <rev>-<count>
107 -f, --file treat FILE as regular source file
108 --subjective, --strict enable more subjective tests
109 --list-types list the possible message types
110 --types TYPE(,TYPE2...) show only these comma separated message types
111 --ignore TYPE(,TYPE2...) ignore various comma separated message types
112 --show-types show the specific message type in the output
113 --max-line-length=n set the maximum line length, (default $max_line_length)
115 requires --strict for use with --file
116 --min-conf-desc-length=n set the minimum description length for config symbols
118 --tab-size=n set the number of spaces for tab (default $tabsize)
119 --root=PATH PATH to the kernel tree root
120 --no-summary suppress the per-file summary
121 --mailback only produce a report in case of warnings/errors
122 --summary-file include the filename in summary
123 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
126 --test-only=WORD report only warnings/errors containing WORD
128 --fix EXPERIMENTAL - may create horrible results
129 If correctable single-line errors exist, create
130 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
133 --fix-inplace EXPERIMENTAL - may create horrible results
134 Is the same as --fix, but overwrites the input
136 --ignore-perl-version override checking of perl version. expect
138 --codespell Use the codespell dictionary for spelling/typos
140 --codespellfile Use this codespell dictionary
141 --typedefsfile Read additional types from this file
142 --color[=WHEN] Use colors 'always', 'never', or only when output
143 is a terminal ('auto'). Default is 'auto'.
144 --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
146 -h, --help, --version display this help and exit
148 When FILE is - read standard input.
155 do {} while (0) advice is over-stated in a few situations:
158 file-scope, where C disallows code (it must be in functions). See
162 like DECLARE_PER_CPU. These might just compile with a do-while-0
167 expression. These cannot do-while, and need a ({}) wrapper.
191 # Also catch when type or level is passed through a variable
241 if (-f $conf) {
244 or warn "$P: Can't find a readable $configuration_file file $!\n";
306 # Perl's Getopt::Long allows options to take optional arguments after a space.
307 # Prevent --color by itself from consuming other arguments
309 if ($_ eq "--color" || $_ eq "-color") {
310 $_ = "--color=$color";
319 'fixes-tag!' => \$chk_fixes_tag,
330 'show-types!' => \$show_types,
331 'list-types!' => \$list_types,
332 'max-line-length=i' => \$max_line_length,
333 'min-conf-desc-length=i' => \$min_conf_desc_length,
334 'tab-size=i' => \$tabsize,
338 'summary-file!' => \$summary_file,
340 'fix-inplace!' => \$fix_inplace,
341 'ignore-perl-version!' => \$ignore_perl_version,
343 'test-only=s' => \$tst_only,
348 'no-color' => \$color, #keep old behaviors of -nocolor
349 'nocolor' => \$color, #keep old behaviors of -nocolor
350 'kconfig-prefix=s' => \${CONFIG_},
358 } elsif (!(-f $codespellfile)) {
371 my $codespell_dict = `python3 -c "$python_codespell_dict" 2> /dev/null`;
372 $codespellfile = $codespell_dict if (-f $codespell_dict);
376 # $help is 1 if either -h, --help or --version is passed as option - exitcode: 0
377 # $help is 2 if invalid option is passed - exitcode: 1
378 help($help - 1) if ($help);
380 die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
381 die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);
390 $color = (-t STDOUT);
410 #if no filenames are given, push '-' to read patch from stdin
412 push(@ARGV, '-');
415 # skip TAB size 1 to avoid additional checks on $tabsize - 1
426 $word =~ tr/[a-z]/[A-Z]/;
431 $hashRef->{$word}++;
470 die "$P: $root: --root does not point at a valid tree\n";
482 print "Must be run from the top-level dir. of a kernel tree\n";
490 [A-Za-z_][A-Za-z\d_]*
491 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
514 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
546 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
551 our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
552 our $Int = qr{[0-9]+$Int_type?};
553 our $Octal = qr{0[0-7]+$Int_type?};
555 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
556 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
557 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
560 our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
561 our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
562 our $Arithmetic = qr{\+|-|\*|\/|%};
565 =>|->|<<|>>|<|>|!|~|
566 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
581 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
582 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
583 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
584 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
585 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
586 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
587 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
591 [\x09\x0A\x0D\x20-\x7E] # ASCII
618 …(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|co…
622 MODULE_[A-Z_]+|
637 Signed-off-by:|
638 Co-developed-by:|
639 Acked-by:|
640 Tested-by:|
641 Reviewed-by:|
642 Reported-by:|
643 Suggested-by:|
650 #Create a search and print patterns for all these strings to be used directly below
665 [=-]*> |
666 <[=-]* |
696 for my $i (0 .. ($len-1)) {
708 $str1 =~ s/-//g;
709 $str2 =~ s/-//g;
720 } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) {
721 $distance[$i][$j] = $distance[$i - 1][$j - 1];
723 my $dist1 = $distance[$i][$j - 1]; #insert distance
724 my $dist2 = $distance[$i - 1][$j]; # remove
725 my $dist3 = $distance[$i - 1][$j - 1]; #replace
736 'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:',
737 'Reviewed-by:', 'Reported-by:', 'Suggested-by:'
747 \Qfreedesktop.org/archives/dri-devel\E |
750 \Qmail-archive.com\E |
751 \Qmailman.alsa-project.org/pipermail\E |
839 ["IIO_DEV_ATTR_[A-Z_]+", 1],
845 my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
847 #Create a search pattern for all these functions to speed up a loop below
851 $mode_perms_search .= $entry->[0];
864 #Create a search pattern for all these strings to speed up a loop below
877 0[0-7][0-7][2367]
899 #Create a search pattern for all these strings to speed up a loop below
914 return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
925 last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
943 # memory.h: ARM has a custom one
965 warn "No typos will be found - file '$spelling_file': $!\n";
982 my ($suspect, $fix) = split(/->/, $line);
988 warn "No codespell typos will be found - file '$codespellfile': $!\n";
1007 print("$file: '$line' invalid - ignored\n");
1024 or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
1030 or warn "No additional types will be considered - file '$typedefsfile': $!\n";
1090 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
1095 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
1125 return if (!(-f $file));
1137 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
1138 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
1140 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
1142 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
1153 return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
1156 …s{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback…
1165 …return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitr…
1168 my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
1183 if (-e "$gitroot") {
1184 …my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include…
1186 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
1189 $files = `find $root/include -name "*.h"`;
1196 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
1199 if ($camelcase_cache ne "" && -f $camelcase_cache) {
1211 if (-e "$gitroot") {
1212 $files = `${git_command} ls-files "include/*.h"`;
1221 unlink glob ".checkpatch-camelcase.*";
1224 foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
1234 return 0 if ((which("git") eq "") || !(-e "$gitroot"));
1236 my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
1244 return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
1246 my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
1257 # git rev-list --remotes | grep -i "^$1" |
1259 # git log --format='%H %s' -1 $line |
1260 # echo "commit $(cut -c 1-12,41-)"
1281 my $fixlinenr = -1;
1284 # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
1285 die "$P: No git repository found\n" if ($git && !-e "$gitroot");
1291 if ($commit_expr =~ m/^(.*)-(\d+)$/) {
1292 $git_range = "-$2 $1";
1296 $git_range = "-1 $commit_expr";
1298 my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
1300 $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
1320 open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
1321 die "$P: $filename: git format-patch failed - $!\n";
1323 open($FILE, '-|', "diff -u /dev/null $filename") ||
1324 die "$P: $filename: diff failed - $!\n";
1325 } elsif ($filename eq '-') {
1329 die "$P: $filename: open failed - $!\n";
1331 if ($filename eq '-') {
1341 $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
1346 print '-' x length($vname) . "\n";
1348 print '-' x length($vname) . "\n";
1359 $fixlinenr = -1;
1398 if (! -e $root . '/' . $check) {
1428 # If there's a name left after stripping spaces and
1442 # "John D. (Doe)" - Do not extract
1456 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1473 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1515 if (-e "$path/$bin") {
1527 if (-e "$path/$conf") {
1623 # A \ in a string means ignore the next character.
1658 # The pathname on a #include may be surrounded by '<' and '>'.
1663 # The whole of a #error is a string.
1682 return substr($rawline, $-[0], $+[0] - $-[0]);
1687 my $line = $linenr - 1;
1690 my $coff = $off - 1;
1704 @stack = (['', 0]) if ($#stack == -1);
1712 next if ($lines[$line] =~ /^-/);
1713 $remain--;
1740 ($type, $level) = @{$stack[$#stack - 1]};
1745 # Statement ends at the ';' or a close '}' at the
1751 # An else is really a conditional as long as its not else if
1756 $coff = $off + length($1) - 1;
1759 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
1767 $level--;
1781 $level--;
1793 $level--;
1804 $remain--;
1807 my $statement = substr($blk, $soff, $off - $soff + 1);
1808 my $condition = substr($blk, $soff, $coff - $soff + 1);
1816 $line, $remain + 1, $off - $loff + 1, $level);
1873 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
1883 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1894 my $start = $linenr - 1;
1903 next if ($rawlines[$line] =~ /^-/);
1904 $remain--;
1912 $level = $stack[$#stack - 1];
1920 $off--;
1925 $level--;
1974 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
1976 ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
1981 # Catch a comment on the end of the line itself.
1982 ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
1985 # Look through the context and try and figure out if there is a
1990 my $line = $rawlines[$linenr - 1];
2014 ##print "LINE: $rawlines[$end_line - 1 ]\n";
2023 my $offset = $linenr - 1;
2029 next if (defined($line) && $line =~ /^-/);
2030 $cnt--;
2200 print "PAREN('$1') -> $type\n"
2256 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
2271 if ($1 ne '++' && $1 ne '--') {
2339 $type =~ tr/[a-z]/[A-Z]/;
2372 my @lines = split("\n", $output, -1);
2399 if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
2428 if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
2430 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
2438 fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
2517 # See if any suffix of this path is a path within the tree.
2519 if (-f "$root/$file") {
2524 if (! -f _) {
2530 substr($prefix, -length($file)) = '';
2575 my $max_spaces_before_tab = $source_indent - 1;
2580 #Remove spaces before a tab
2597 return -1;
2605 $pos += length($1) - 1;
2608 } elsif (index($string, '(') == -1) {
2620 for my $i (0 .. (length($line) - 1)) {
2661 my $is_binding_patch = -1;
2664 my $has_patch_separator = 0; #Found a --- line
2673 my $last_git_commit_id_linenr = -1;
2676 my $last_coalesced_string_linenr = -1;
2689 my $context_function; #undef'd unless there's a known function
2705 # Pre-scan the patch sanitizing the lines.
2706 # Pre-scan the patch looking for any __setup documentation.
2725 if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
2730 if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
2731 $realline=$1-1;
2739 # Guestimate if this is a continuing comment. Run
2740 # the context looking for a comment "edge". If this
2741 # edge is a close comment then we must be in a comment
2746 next if (defined $rawlines[$ln - 1] &&
2747 $rawlines[$ln - 1] =~ /^-/);
2748 $cnt--;
2749 #print "RAW<$rawlines[$ln - 1]>\n";
2750 last if (!defined $rawlines[$ln - 1]);
2751 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
2752 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
2761 # Guestimate if this is a continuing comment. If this
2762 # is the start of a diff block and this line starts
2763 # ' *' then it is very likely a comment.
2775 # simplify matching -- only bother with positive lines.
2781 $realcnt-- if ($line =~ /^(?:\+| |$)/);
2787 #print "-->$line\n";
2798 $fixlinenr = -1;
2805 my $rawline = $rawlines[$linenr - 1];
2808 # check if it's a mode change, rename or start of a patch
2810 ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
2812 $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
2818 $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
2822 $realline=$1-1;
2847 $realcnt-- if ($realcnt != 0);
2860 $realcnt--;
2870 if ($line =~ /^diff --git.*?(\S+)$/) {
2882 -e "$root/$p1_prefix") {
2884 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
2920 $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
2922 if (($last_binding_patch != -1) &&
2925 …"DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/s…
2940 # Verify the existence of a commit log if appropriate
2941 # 2 is used because a $signature is counted in $commit_log_lines
2944 $commit_log_lines++; #could be a $signature
2948 "Missing commit description - Add an appropriate one\n");
2952 # Check if the commit log has what seems like a diff which can confuse patch
2954 (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
2955 $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
2956 $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
2957 $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
2959 "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
2973 # Check the patch for a From:
2974 if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
2980 $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
2985 # Check the patch for a signoff:
2986 if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
3025 if ($line =~ /^---$/) {
3038 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
3049 "Non-standard signature: $sign_off\n" . $herecurr);
3052 "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) &&
3066 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
3077 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
3118 "Use a single name comment in email: '$email'\n" . $herecurr);
3124 # begin with a #
3130 $cur_name =~ s/[a-zA-Z\s\-\"]+//g;
3157 … $new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo
3180 # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
3181 if ($sign_off =~ /^co-developed-by:$/i) {
3184 … "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . $herecurr);
3188 "Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr);
3189 } elsif ($rawlines[$linenr] !~ /^signed-off-by:\s*(.*)/i) {
3191 …"Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr . $rawlines[$linen…
3194 …"Co-developed-by and Signed-off-by: name/email do not match\n" . $herecurr . $rawlines[$linenr] . …
3198 # check if Reported-by: is followed by a Closes: tag
3199 if ($sign_off =~ /^reported(?:|-and-tested)-by:$/i) {
3202 …"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . …
3205 …"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . …
3210 # These indicate a bug fix
3223 $line =~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})(?:\s*($balanced_parens))?/i) {
3231 $title = substr($3, 1, -1);
3233 $title = substr($title, 1, -1);
3242 my $tag_space = not ($line =~ /^fixes:? [0-9a-f]{5,40} ($balanced_parens)/i);
3244 my $id_length = not ($orig_commit =~ /^[0-9a-f]{12,40}$/i);
3245 my $id_case = not ($orig_commit !~ /[A-F]/);
3254 …"Please use correct Fixes: style 'Fixes: <12+ chars of sha1> (\"<title line>\")' - ie: '$fixed'\n"…
3265 "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
3268 # Check for Gerrit Change-Ids not in any patch context
3269 if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
3271 "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
3277 # Check if the commit log is in a possible stack dump
3282 $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
3283 $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
3284 $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
3292 !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
3294 $line =~ /^\s*(?:[\w\.\-\+]*\/)++[\w\.\-\+]+:/ ||
3297 # A Fixes:, link or signature tag line
3300 … "Prefer a maximum 75 chars per line (possible unwrapped commit description?)\n" . $herecurr);
3304 # Reset possible stack dump if a blank line is found
3310 # Check for odd tags before a URI/URL
3315 "Patch version information should be after the --- line\n" . $herecurr);
3329 "'$tag' should be followed by a public http(s) link\n" . $herecurr);
3333 # Check for lines starting with a #
3343 # A correctly formed commit description is:
3344 # commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
3346 # This is a fairly compilicated block as it tests for what appears to be
3347 # bare SHA-1 hash with minimum length of 5. It also avoids several types of
3348 # possible SHA-1 matches.
3349 # A commit match can span multiple lines so this block attempts to find a
3350 # complete typical commit on a maximum of 3 lines
3353 $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
3354 $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
3355 (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
3356 … /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
3357 ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
3358 $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
3359 $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
3374 if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
3376 if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
3380 $orig_desc = substr($orig_desc, 1, -1);
3382 $orig_desc = substr($orig_desc, 1, -1);
3394 if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
3397 $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
3398 $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
3399 $space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
3400 $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
3401 } elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
3410 $last_git_commit_id_linenr != $linenr - 1) {
3412 …it commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}omm…
3421 …"Use lore.kernel.org archive links when possible - see https://lore.kernel.org/lists.html\n" . $he…
3427 $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
3428 ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
3441 …"DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.…
3444 # Check for wrappage within a valid hunk of the file
3445 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
3451 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
3461 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
3464 # Check if it's the start of a commit log
3465 # (not a header line and we haven't seen the patch filename)
3468 $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
3474 # Check if there is UTF-8 in a commit log when a mail header has explicitly
3477 $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
3478 $1 !~ /utf-8/i) {
3485 "8-bit UTF-8 used in possible commit log\n" . $herecurr);
3505 while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
3508 my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
3511 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
3512 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
3516 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) &&
3518 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
3524 if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
3534 # check for repeated words separated by a single space
3535 # avoid false positive from list command eg, '-rw-r--r-- 1 root root'
3537 $rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) {
3543 my $start_pos = $-[1];
3556 $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1));
3560 next if (index(" \t.,;?!", $end_char) == -1);
3563 if ($first =~ /\b[0-9a-f]{2,}\b/i) {
3574 # if it's a repeated word on consecutive lines in a comment block
3588 # ignore non-hunk lines and lines being removed
3589 next if (!$hunk_line || $line =~ /^-/);
3619 … changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" …
3622 # check for Kconfig help text having a real description
3627 # Kconfig supports named choices), so use a word boundary
3628 # (\b) rather than a whitespace character (\s)
3637 next if ($f =~ /^-/);
3667 my $stat_real = get_stat_real($linenr, $ln - 1);
3669 …"please write a help paragraph that fully describes the config symbol with at least $min_conf_desc…
3676 if ($rawline =~ /^\+[A-Z]:/ &&
3677 $rawline !~ /^\+[A-Z]:\t\S/) {
3681 $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3686 if ($rawline =~ /^\+[A-Z]:/ &&
3687 $prevrawline =~ /^[\+ ][A-Z]:/) {
3688 $rawline =~ /^\+([A-Z]):\s*(.*)/;
3691 $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
3702 "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
3707 "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
3718 my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
3721 my $vp_file = $dt_path . "vendor-prefixes.yaml";
3725 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
3727 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
3728 `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
3731 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
3734 next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
3736 `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
3739 … "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
3762 $rawline =~ /SPDX-License-Identifier:/ &&
3769 $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
3771 … "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
3772 } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
3779 $spdx_license !~ /GPL-2\.0(?:-only)? OR BSD-2-Clause/) {
3784 "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
3786 …$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-
3789 if ($realfile =~ m@^include/dt-bindings/@ &&
3790 $spdx_license !~ /GPL-2\.0(?:-only)? OR \S+/) {
3792 "DT binding headers should be licensed (GPL-2.0-only OR .*)\n" . $herecurr);
3804 # check we are in a valid source file if not then ignore this hunk
3807 # check for using SPDX-License-Identifier on the wrong line number
3809 $rawline =~ /\bSPDX-License-Identifier:/ &&
3810 substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
3812 "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
3817 # There are a few types of lines that may extend beyond $max_line_length:
3818 # logging functions like pr_info that end in a string
3819 # lines with a single string
3820 # #defines that are a single string
3824 # LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length
3825 # LONG_LINE_STRING a string starts before but extends beyond $max_line_length
3836 # logging functions that end in a string that starts
3839 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3853 # URL ($rawline is used in case the URL is in a comment)
3854 } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
3859 # a comment starts before $max_line_length
3861 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3864 # a quoted string starts before $max_line_length
3866 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3879 # check for adding lines without a newline.
3882 "adding a line without newline at end of file\n" . $herecurr) &&
3890 $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
3892 …ed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Document…
3895 # check we are in a valid source file C or perl if not then ignore this hunk
3898 # at the beginning of a line any tabs must come first and anything
3924 # check for assignments on the start of a line
3931 $fixed[$fixlinenr - 1] .= " $operator";
3936 # check for && or || at the start of a line
3942 # insert logical operator at last non-comment, non-whitepsace char on previous line
3944 my $line_end = substr($prevrawline, $-[0]);
3945 $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/;
3950 # check indentation starts on a tab stop
3956 "Statements should start on a tabstop\n" . $herecurr) &&
3963 # check multi-line statement indentation matches previous line
3994 # avoid checking a few false positives:
4003 "No space is necessary after a cast\n" . $herecurr) &&
4026 "Block comments use a trailing */ on a separate line\n" . $herecurr);
4061 $line =~ /^\+[a-z_]*init/ ||
4062 $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
4067 "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
4076 $last_blank_line != ($linenr - 1)) {
4106 # not starting a section or a macro "\" extended line
4108 # looks like a declaration
4125 "Missing a blank line after declarations\n" . $hereprev) &&
4132 # check for spaces at the beginning of a line.
4140 "please, no spaces at the start of a line\n" . $herevet) &&
4146 # check we are in a valid C source file if not then ignore this hunk
4152 "Lines should not end with a '$1'\n" . $herecurr);
4166 # check indentation of any line with a bare else
4167 # (but not if it is a multiple line "if (foo) return bar; else return baz;")
4168 # if the previous line is a break or return and is indented 1 tab more...
4176 "else is not generally useful after a break or return\n" . $hereprev);
4180 # check indentation of a line with a break;
4181 # if the previous line is a goto, return or break
4187 "break is not useful after a $1\n" . $hereprev) &&
4219 # it there is no point in retrying a statement scan
4230 (!defined $lines[$realline_next - 1] ||
4231 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
4250 possible($type, "A:" . $s);
4257 # any (foo ... *) is a pointer cast, and foo is a type
4309 # if/while/etc brace do not go on next line, unless defining a do while loop,
4311 …if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $li…
4318 "Too many leading tabs - consider code refactoring\n" . $herecurr);
4321 my $ctx_cnt = $realcnt - $#ctx - 1;
4328 defined $lines[$ctx_ln - 1] &&
4329 $lines[$ctx_ln - 1] =~ /^-/)) {
4331 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
4336 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
4338 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
4341 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4345 defined $lines[$ctx_ln - 1])
4347 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
4351 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4357 …if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /…
4398 # Also ignore a loop construct at the end of a
4405 my $cond_ptr = -1;
4468 $prev_values = substr($curr_values, -1);
4476 if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
4480 "Do not use self-assignments to avoid compiler warnings\n" . $herecurr);
4485 if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
4487 $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
4493 "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
4549 fix_delete_line($fixlinenr - 1, $prevrawline);
4573 "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
4595 #print "APW <$lines[$realline_next - 1]>\n";
4597 exists $lines[$realline_next - 1] &&
4599 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
4601 # a prefix:
4606 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
4619 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
4628 #print "FOO B <$lines[$linenr - 1]>\n";
4706 # check for const <foo> const where <foo> is not a pointer or array type
4723 "Move const after static - use 'static const $1'\n" . $herecurr) &&
4730 # check for non-global char *foo[] = {"bar", ...} declarations.
4753 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
4776 # Should start with a space.
4778 # Should not end with a space.
4801 # Should start with a space.
4803 # Should not end with a space.
4827 …if ($line =~ /\b(?!AA_|BUILD_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)…
4831 …"Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery cod…
4847 if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
4853 if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
4869 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
4881 …"Do not use $1() in production code (this can be ignored if built only with a debug config option)…
4884 # ENOSYS means "bad syscall nr" and nothing else. This will have a small
4892 # ENOTSUPP is not a standard error code and should be avoided in new patches.
4894 # Similarly to ENOSYS warning a small number of false positives is expected.
4897 "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP\n" . $herecurr) &&
4931 fix_delete_line($fixlinenr - 1, $prevrawline);
4965 # so check it for a missing trailing missing space but pointer return types
4966 # don't need a space so don't warn for those.
4982 # and this is form shouldn't/doesn't generate a checkpatch warning.
5024 # 1. with a type on the left -- int [] a;
5025 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
5026 # 3. inside a curly brace -- = { [0...10] = 5 }
5028 my ($where, $prefix) = ($-[1], $1);
5044 my $ctx_before = substr($line, 0, $-[1]);
5054 # cpp #define statements have non-optional spaces, ie
5055 # if there is a space between the name and the open
5056 # parenthesis it is simply not a parameter group.
5059 # cpp #elif statement condition may start with a (
5062 # If this whole things ends with a type its most
5063 # likely a typedef for a function.
5083 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
5084 =>|->|<<|>>|<|>|=|!|~|
5085 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
5106 my $last_after = -1;
5124 my $a = '';
5125 $a = 'V' if ($elements[$n] ne '');
5126 $a = 'W' if ($elements[$n] =~ /\s$/);
5127 $a = 'C' if ($elements[$n] =~ /$;$/);
5128 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
5129 $a = 'O' if ($elements[$n] eq '');
5130 $a = 'E' if ($ca =~ /^\s*$/);
5146 my $ctx = "${a}x${c}";
5166 # ; should have either the end of line or a space or \ after it
5177 # // is a comment
5180 # : when part of a bitfield
5185 # ->
5186 } elsif ($op eq '->') {
5198 # , must not have a space before and must have a space on the right.
5228 # '*' as part of a type definition -- reported already.
5232 # unary operators should have a space before and
5234 # unary operator, or a cast
5236 $opv eq '*U' || $opv eq '-U' ||
5238 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
5248 # A unary '*' may be const
5261 # unary ++ and unary -- are allowed no space on one side.
5262 } elsif ($op eq '++' or $op eq '--') {
5292 $op eq '+' or $op eq '-' or
5322 # A colon needs no spaces before when it is
5323 # terminating a case value or a label.
5347 # ignore a colon with another
5387 # check for whitespace before a non-naked semicolon
5403 ## # check for multiple declarations, allowing for a function declaration
5437 # closing brace should have a space following it when it has anything
5488 # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
5500 # ie: (foo->bar)(); should be foo->bar();
5501 # but not "if (foo->bar) (" to avoid some false positives
5519 my $test = substr($2, 1, -1);
5539 # check that goto labels aren't indented (allow a single space indentation)
5543 if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
5544 $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
5554 # check if a statement with a comma should be two statements like:
5565 # return is not a function
5574 "return is not a function, parentheses are not required\n" . $herecurr);
5582 # unnecessary return in a void function
5583 # at end-of-function, with the previous line a single leading tab, then return;
5584 # and the line before that not a goto label target like "out:"
5588 $lines[$linenr - 3] =~ /^[ +]/ &&
5589 $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
5594 # if statements using unnecessary parentheses - ie: if ((foo == bar))
5602 $msg = " - maybe == should be = ?" if ($comp eq "==");
5608 # comparisons with a constant or upper case identifier on the left
5613 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
5620 $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
5638 if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
5642 "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
5646 # Need a space before open parenthesis after if, while etc
5656 # Check for illegal assignment in if conditional -- and check for trailing
5671 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
5673 statement_rawlines($whitespace) - 1;
5753 \s*0[xX][0-9]+\s*
5757 \s*0[xX][0-9]+\s*
5774 # if should not continue a brace
5798 fix_delete_line($fixlinenr - 1, $prevrawline);
5824 fix_delete_line($fixlinenr - 1, $prevrawline);
5842 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
5846 $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
5848 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
5853 $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
5855 $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
5858 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
5889 if (-f "$root/$checkfile" &&
5893 my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
5906 # Usually multi-statement macros should be enclosed in a do {} while
5908 # if its not enclosed in a known good container
5921 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
5932 $define_args = substr($define_args, 1, length($define_args) - 2);
5956 # Make asm volatile uses seem like a generic function
5982 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
5983 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
5984 …$dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // f…
5993 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
6000 …"Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic d…
6003 …"Non-declarative macros with multiple statements should be enclosed in a do - while loop\n" . "$he…
6011 # Make $define_stmt single line, comment-free, etc
6039 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
6052 "Argument '$arg' is not used in function-like macro\n" . "$herectx");
6057 # ## concatenation is commonly a macro that defines a function so ignore those
6082 # single-statement macros do not need to be enclosed in do while (0) loop,
6083 # macro should not end with a semicolon
6109 "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
6121 "macros should not use a trailing semicolon\n" . "$herectx");
6136 my $ln = $linenr - 1;
6141 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
6142 my $offset = statement_rawlines($whitespace) - 1;
6151 $ln += statement_rawlines($block) - 1;
6188 if (!defined $suppress_ifbraces{$linenr - 1} &&
6192 # Check the pre-context.
6193 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
6199 ctx_statement_full($linenr, $realcnt, $-[0]);
6219 # Check the post-context.
6226 #print "APW: ALLOWED: chunk-1 block<$block>\n";
6248 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
6250 fix_delete_line($fixlinenr - 1, $prevrawline);
6265 …"Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . …
6268 # Check for user-visible strings broken across lines, which breaks the ability
6269 # to grep for the string. Make exceptions when the previous string ends in a
6271 # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
6274 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
6279 $last_coalesced_string_linenr != $linenr - 1) {
6286 fix_delete_line($fixlinenr - 1, $prevrawline);
6291 fix_insert_line($fixlinenr - 1, $fixedline);
6301 # check for missing a space in a string concatenation
6304 "break quoted strings at a space character\n" . $hereprev);
6307 # check for an embedded function name in a string when the function is known
6308 # This does not work very well for -f --file checking as it depends on patch
6309 # context providing the function name or a single line form for in-file
6316 …\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecur…
6324 "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
6330 # check for spaces before a quoted newline
6333 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
6341 if ($line =~ /$String[A-Z_]/ ||
6342 ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
6347 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
6348 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
6349 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
6357 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
6360 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
6361 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
6366 # check for non-standard and hex prefixed decimal printf formats
6370 my $string = substr($rawline, $-[1], $+[1] - $-[1]);
6375 "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
6378 # check for %Z
6379 if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) {
6381 "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
6421 if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
6426 if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
6435 fix_delete_line($fixlinenr - 1, $prevrawline);
6448 my $testline = $lines[$linenr - 3];
6450 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
6462 $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
6485 while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) {
6488 my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
6499 # check for mask then right shift without a parentheses
6504 … "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
6557 "Use of $attr requires a separate use of const\n" . $herecurr) &&
6568 # check for __read_mostly with const non-pointer (should just be const)
6601 "long udelay - prefer mdelay; see function description of mdelay().\n" . $herecurr);
6643 # check for spinlock_t definitions without a comment.
6652 # check for memory barriers without a comment.
6682 if ($realfile !~ m@^include/asm-generic/@ &&
6687 "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
6690 # check for waitqueue_active without a comment.
6698 # check for data_race without a comment.
6707 … m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
6712 # check that the storage class is not after a type
6717 # Check that the storage class is at the beginning of a declaration
6852 …"Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr)…
6906 my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
6935 $use = " - use %pS instead";
6938 $use = " - '%pA' is only intended to be used from Rust code";
7011 "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
7017 "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
7023 …"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/iss…
7160 "found a file-scoped extern type:$st_type name:$st_name in .c file\n"
7161 . "is this a linker symbol ?\n" . $herecurr);
7214 …"__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $here…
7221 … "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
7250 !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
7268 "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
7305 …if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:…
7318 'lint -fallthrough[ \t]*',
7319 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
7320 '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
7321 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7322 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7336 # check for switch/default statements without a break;
7359 "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
7365 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
7389 ## maybe suggesting a correct construct would better
7398 "consider using a completion\n" . $herecurr);
7448 …"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_po…
7454 … "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
7466 substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) {
7467 my $offset = $+[6] - 1;
7469 "return sysfs_emit(...) formats should include a terminating newline\n" . $herecurr) &&
7479 …"Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one
7481 $fixed[$fixlinenr - 1] =~ s/\[\s*0\s*\]/[]/;
7533 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
7548 …E_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*…
7601 # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
7602 # o Ignore module_param*(...) uses with a decimal 0 permission as that has a
7604 # o Ignore proc_create*(...) uses with a decimal 0 permission as that means
7610 my $func = $entry->[0];
7611 my $arg_pos = $entry->[1];
7619 $arg_pos--;
7669 …"Prefer \"GPL\" over \"GPL v2\" - see commit bf7fbeeae6db (\"module: Cure the MODULE_LICENSE \"GPL…
7685 if ($#rawlines == -1) {
7689 # In mailback mode only produce a report in the negative, for
7695 # This is not a patch, and we are in 'no-patch' mode so
7701 if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
7703 "Does not appear to be a unified-diff format patch\n");
7708 "The commit message has '$needs_fixes_tag', perhaps it also needs a 'Fixes:' tag?\n");
7714 "Missing Signed-off-by: line(s)\n");
7717 # 0 -> missing sign off
7718 # 1 -> sign off identical
7719 # 2 -> names and addresses match, comments mismatch
7720 # 3 -> addresses match, names different
7721 # 4 -> names match, addresses different
7722 # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
7724 my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
7728 "Missing Signed-off-by: line by nominal patch author '$author'\n");
7731 "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
7734 "From:/Signed-off-by: email name mismatch: $sob_msg\n");
7737 "From:/Signed-off-by: email address mismatch: $sob_msg\n");
7740 "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
7759 mechanically convert to the typical style using --fix or --fix-inplace.
7778 $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
7802 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
7807 This EXPERIMENTAL file is simply a convenience to help rewrite patches.