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>
64 my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
66 my $git_command ='export LANGUAGE=en_US.UTF-8; git';
76 -q, --quiet quiet
77 --no-tree run without a kernel tree
78 --no-signoff do not check for 'Signed-off-by' line
79 --patch treat FILE as patchfile (default)
80 --emacs emacs compile window format
81 --terse one line per report
82 --showfile emit diffed file position, not input file position
83 -g, --git treat FILE as a single commit or git revision range
91 <rev>-<count>
93 -f, --file treat FILE as regular source file
94 --subjective, --strict enable more subjective tests
95 --list-types list the possible message types
96 --types TYPE(,TYPE2...) show only these comma separated message types
97 --ignore TYPE(,TYPE2...) ignore various comma separated message types
98 --show-types show the specific message type in the output
99 --max-line-length=n set the maximum line length, if exceeded, warn
100 --min-conf-desc-length=n set the min description length, if shorter, warn
101 --root=PATH PATH to the kernel tree root
102 --no-summary suppress the per-file summary
103 --mailback only produce a report in case of warnings/errors
104 --summary-file include the filename in summary
105 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
108 --test-only=WORD report only warnings/errors containing WORD
110 --fix EXPERIMENTAL - may create horrible results
111 If correctable single-line errors exist, create
112 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
115 --fix-inplace EXPERIMENTAL - may create horrible results
116 Is the same as --fix, but overwrites the input
118 --ignore-perl-version override checking of perl version. expect
120 --codespell Use the codespell dictionary for spelling/typos
122 --codespellfile Use this codespell dictionary
123 --typedefsfile Read additional types from this file
124 --color[=WHEN] Use colors 'always', 'never', or only when output
125 is a terminal ('auto'). Default is 'auto'.
126 -h, --help, --version display this help and exit
128 When FILE is - read standard input.
153 # Also catch when type or level is passed through a variable
167 if (-f $conf) {
170 or warn "$P: Can't find a readable $configuration_file file $!\n";
192 # Perl's Getopt::Long allows options to take optional arguments after a space.
193 # Prevent --color by itself from consuming other arguments
195 if ($_ eq "--color" || $_ eq "-color") {
196 $_ = "--color=$color";
214 'show-types!' => \$show_types,
215 'list-types!' => \$list_types,
216 'max-line-length=i' => \$max_line_length,
217 'min-conf-desc-length=i' => \$min_conf_desc_length,
221 'summary-file!' => \$summary_file,
223 'fix-inplace!' => \$fix_inplace,
224 'ignore-perl-version!' => \$ignore_perl_version,
226 'test-only=s' => \$tst_only,
231 'no-color' => \$color, #keep old behaviors of -nocolor
232 'nocolor' => \$color, #keep old behaviors of -nocolor
253 #if no filenames are given, push '-' to read patch from stdin
255 push(@ARGV, '-');
265 $color = (-t STDOUT);
278 $word =~ tr/[a-z]/[A-Z]/;
283 $hashRef->{$word}++;
322 die "$P: $root: --root does not point at a valid tree\n";
334 print "Must be run from the top-level dir. of a kernel tree\n";
342 [A-Za-z_][A-Za-z\d_]*
343 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
366 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
395 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
400 our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
401 our $Int = qr{[0-9]+$Int_type?};
402 our $Octal = qr{0[0-7]+$Int_type?};
404 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
405 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
406 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
409 our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
410 our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
411 our $Arithmetic = qr{\+|-|\*|\/|%};
414 =>|->|<<|>>|<|>|!|~|
415 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
430 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
431 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
432 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
433 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
434 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
435 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
436 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
440 [\x09\x0A\x0D\x20-\x7E] # ASCII
463 …(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|co…
467 MODULE_[A-Z_]+|
482 Signed-off-by:|
483 Co-developed-by:|
484 Acked-by:|
485 Tested-by:|
486 Reviewed-by:|
487 Reported-by:|
488 Suggested-by:|
575 ["IIO_DEV_ATTR_[A-Z_]+", 1],
581 #Create a search pattern for all these functions to speed up a loop below
585 $mode_perms_search .= $entry->[0];
602 #Create a search pattern for all these strings to speed up a loop below
615 0[0-7][0-7][2367]
637 #Create a search pattern for all these strings to speed up a loop below
652 return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
663 last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
681 # memory.h: ARM has a custom one
703 warn "No typos will be found - file '$spelling_file': $!\n";
720 my ($suspect, $fix) = split(/->/, $line);
726 warn "No codespell typos will be found - file '$codespellfile': $!\n";
745 print("$file: '$line' invalid - ignored\n");
761 or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
766 or warn "No additional types will be considered - file '$typedefsfile': $!\n";
826 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
831 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
854 return if (!(-f $file));
866 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
867 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
869 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
871 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
880 return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
882 …my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -
890 …return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/…
893 my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
908 if (-e ".git") {
909 …my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include…
911 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
914 $files = `find $root/include -name "*.h"`;
921 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
924 if ($camelcase_cache ne "" && -f $camelcase_cache) {
936 if (-e ".git") {
937 $files = `${git_command} ls-files "include/*.h"`;
946 unlink glob ".checkpatch-camelcase.*";
949 foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
959 return ($id, $desc) if ((which("git") eq "") || !(-e ".git"));
961 my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
972 # git rev-list --remotes | grep -i "^$1" |
974 # git log --format='%H %s' -1 $line |
975 # echo "commit $(cut -c 1-12,41-)"
994 my $fixlinenr = -1;
997 # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
998 die "$P: No git repository found\n" if ($git && !-e ".git");
1004 if ($commit_expr =~ m/^(.*)-(\d+)$/) {
1005 $git_range = "-$2 $1";
1009 $git_range = "-1 $commit_expr";
1011 my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
1013 $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
1030 open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
1031 die "$P: $filename: git format-patch failed - $!\n";
1033 open($FILE, '-|', "diff -u /dev/null $filename") ||
1034 die "$P: $filename: diff failed - $!\n";
1035 } elsif ($filename eq '-') {
1039 die "$P: $filename: open failed - $!\n";
1041 if ($filename eq '-') {
1055 print '-' x length($vname) . "\n";
1057 print '-' x length($vname) . "\n";
1068 $fixlinenr = -1;
1106 if (! -e $root . '/' . $check) {
1134 # If there's a name left after stripping spaces and
1152 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1169 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1187 if (-e "$path/$bin") {
1199 if (-e "$path/$conf") {
1295 # A \ in a string means ignore the next character.
1330 # The pathname on a #include may be surrounded by '<' and '>'.
1335 # The whole of a #error is a string.
1354 return substr($rawline, $-[0], $+[0] - $-[0]);
1359 my $line = $linenr - 1;
1362 my $coff = $off - 1;
1376 @stack = (['', 0]) if ($#stack == -1);
1384 next if ($lines[$line] =~ /^-/);
1385 $remain--;
1412 ($type, $level) = @{$stack[$#stack - 1]};
1417 # Statement ends at the ';' or a close '}' at the
1423 # An else is really a conditional as long as its not else if
1428 $coff = $off + length($1) - 1;
1431 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
1439 $level--;
1453 $level--;
1465 $level--;
1476 $remain--;
1479 my $statement = substr($blk, $soff, $off - $soff + 1);
1480 my $condition = substr($blk, $soff, $coff - $soff + 1);
1488 $line, $remain + 1, $off - $loff + 1, $level);
1545 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
1555 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1566 my $start = $linenr - 1;
1575 next if ($rawlines[$line] =~ /^-/);
1576 $remain--;
1584 $level = $stack[$#stack - 1];
1592 $off--;
1597 $level--;
1645 # Catch a comment on the end of the line itself.
1646 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
1649 # Look through the context and try and figure out if there is a
1654 my $line = $rawlines[$linenr - 1];
1678 ##print "LINE: $rawlines[$end_line - 1 ]\n";
1687 my $offset = $linenr - 1;
1693 next if (defined($line) && $line =~ /^-/);
1694 $cnt--;
1864 print "PAREN('$1') -> $type\n"
1920 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
1935 if ($1 ne '++' && $1 ne '--') {
2003 $type =~ tr/[a-z]/[A-Z]/;
2036 my @lines = split("\n", $output, -1);
2054 if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
2083 if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
2085 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
2093 fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
2172 # See if any suffix of this path is a path within the tree.
2174 if (-f "$root/$file") {
2179 if (! -f _) {
2185 substr($prefix, -length($file)) = '';
2230 my $max_spaces_before_tab = $source_indent - 1;
2235 #Remove spaces before a tab
2252 return -1;
2260 $pos += length($1) - 1;
2263 } elsif (index($string, '(') == -1) {
2290 my $is_binding_patch = -1;
2302 my $last_coalesced_string_linenr = -1;
2315 my $context_function; #undef'd unless there's a known function
2331 # Pre-scan the patch sanitizing the lines.
2332 # Pre-scan the patch looking for any __setup documentation.
2351 if ($1 =~ m@Documentation/admin-guide/kernel-parameters.rst$@) {
2356 if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
2357 $realline=$1-1;
2365 # Guestimate if this is a continuing comment. Run
2366 # the context looking for a comment "edge". If this
2367 # edge is a close comment then we must be in a comment
2372 next if (defined $rawlines[$ln - 1] &&
2373 $rawlines[$ln - 1] =~ /^-/);
2374 $cnt--;
2375 #print "RAW<$rawlines[$ln - 1]>\n";
2376 last if (!defined $rawlines[$ln - 1]);
2377 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
2378 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
2387 # Guestimate if this is a continuing comment. If this
2388 # is the start of a diff block and this line starts
2389 # ' *' then it is very likely a comment.
2401 # simplify matching -- only bother with positive lines.
2407 $realcnt-- if ($line =~ /^(?:\+| |$)/);
2413 #print "-->$line\n";
2424 $fixlinenr = -1;
2431 my $rawline = $rawlines[$linenr - 1];
2433 # check if it's a mode change, rename or start of a patch
2435 ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
2437 $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
2443 $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
2447 $realline=$1-1;
2472 $realcnt-- if ($realcnt != 0);
2485 $realcnt--;
2495 if ($line =~ /^diff --git.*?(\S+)$/) {
2507 -e "$root/$p1_prefix") {
2509 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
2514 …"do not modify files in include/asm, change architecture specific files in include/asm-<architectu…
2545 $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
2547 if (($last_binding_patch != -1) &&
2550 …"DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/s…
2565 # Verify the existence of a commit log if appropriate
2566 # 2 is used because a $signature is counted in $commit_log_lines
2569 $commit_log_lines++; #could be a $signature
2573 "Missing commit description - Add an appropriate one\n");
2577 # Check if the commit log has what seems like a diff which can confuse patch
2579 (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
2580 $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
2581 $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
2582 $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
2584 "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
2598 # Check the patch for a From:
2599 if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
2601 $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
2605 # Check the patch for a signoff:
2606 if ($line =~ /^\s*signed-off-by:/i) {
2612 if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) {
2626 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
2635 "Non-standard signature: $sign_off\n" . $herecurr);
2645 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
2656 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
2693 # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
2694 if ($sign_off =~ /^co-developed-by:$/i) {
2697 …"Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . …
2701 … "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
2702 } elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
2704 …"Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" …
2707 …"Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$ra…
2716 "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
2720 if ($in_commit_log && $line =~ /^\s*change-id:/i) {
2722 "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr);
2725 # Check if the commit log is in a possible stack dump
2730 $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
2731 $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
2732 $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
2740 !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
2742 $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
2745 # A Fixes: or Link: line
2748 "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
2752 # Reset possible stack dump if a blank line is found
2761 $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
2762 ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
2763 ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
2764 $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
2765 $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
2778 if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
2781 } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
2785 $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
2786 $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
2787 $space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
2788 $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
2789 if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
2792 } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
2797 } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
2800 $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
2813 …it commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}omm…
2820 $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
2821 ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
2829 # Check for wrappage within a valid hunk of the file
2830 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
2836 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
2846 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
2849 # Check if it's the start of a commit log
2850 # (not a header line and we haven't seen the patch filename)
2853 $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
2859 # Check if there is UTF-8 in a commit log when a mail header has explicitly
2862 $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
2863 $1 !~ /utf-8/i) {
2870 "8-bit UTF-8 used in possible commit log\n" . $herecurr);
2890 while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
2893 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
2894 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
2898 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
2900 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
2906 if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
2916 # ignore non-hunk lines and lines being removed
2917 next if (!$hunk_line || $line =~ /^-/);
2947 … changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" …
2950 # check for Kconfig help text having a real description
2955 # Kconfig supports named choices), so use a word boundary
2956 # (\b) rather than a whitespace character (\s)
2964 for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
2965 $f = $lines[$ln - 1];
2966 $cnt-- if ($lines[$ln - 1] !~ /^-/);
2967 $is_end = $lines[$ln - 1] =~ /^\+/;
2969 next if ($f =~ /^-/);
2972 if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
2974 } elsif ($lines[$ln - 1] =~ /^\+\s*(?:help|---help---)\s*$/) {
2975 if ($lines[$ln - 1] =~ "---help---") {
2977 "prefer 'help' over '---help---' for new help texts\n" . $herecurr);
2979 $length = -1;
3000 "please write a paragraph that describes the config symbol fully\n" . $herecurr);
3007 $rawline =~ /^\+[A-Z]:/ &&
3008 $rawline !~ /^\+[A-Z]:\t\S/) {
3012 $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3024 ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
3027 'EXTRA_AFLAGS' => 'asflags-y',
3028 'EXTRA_CFLAGS' => 'ccflags-y',
3029 'EXTRA_CPPFLAGS' => 'cppflags-y',
3030 'EXTRA_LDFLAGS' => 'ldflags-y',
3034 … of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacem…
3042 my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
3045 my $vp_file = $dt_path . "vendor-prefixes.yaml";
3049 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
3051 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
3052 `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
3055 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
3058 next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
3060 `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
3063 … "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
3086 $rawline =~ /SPDX-License-Identifier:/ &&
3093 $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
3095 … "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
3096 } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
3106 # check we are in a valid source file if not then ignore this hunk
3109 # check for using SPDX-License-Identifier on the wrong line number
3111 $rawline =~ /\bSPDX-License-Identifier:/ &&
3112 substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
3114 "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
3119 # There are a few types of lines that may extend beyond $max_line_length:
3120 # logging functions like pr_info that end in a string
3121 # lines with a single string
3122 # #defines that are a single string
3126 # LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length
3127 # LONG_LINE_STRING a string starts before but extends beyond $max_line_length
3138 # logging functions that end in a string that starts
3141 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3155 # URL ($rawline is used in case the URL is in a comment)
3156 } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
3161 # a comment starts before $max_line_length
3163 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3166 # a quoted string starts before $max_line_length
3168 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3179 # check for adding lines without a newline.
3182 "adding a line without newline at end of file\n" . $herecurr);
3185 # check we are in a valid source file C or perl if not then ignore this hunk
3188 # at the beginning of a line any tabs must come first and anything
3214 # check for assignments on the start of a line
3220 # check for && or || at the start of a line
3226 # check indentation starts on a tab stop
3232 "Statements should start on a tabstop\n" . $herecurr) &&
3239 # check multi-line statement indentation matches previous line
3270 # avoid checking a few false positives:
3279 "No space is necessary after a cast\n" . $herecurr) &&
3312 "Block comments use a trailing */ on a separate line\n" . $herecurr);
3347 $line =~ /^\+[a-z_]*init/ ||
3348 $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
3353 "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
3362 $last_blank_line != ($linenr - 1)) {
3386 # not starting a section or a macro "\" extended line
3388 # looks like a declaration
3407 "Missing a blank line after declarations\n" . $hereprev) &&
3413 # check for spaces at the beginning of a line.
3421 "please, no spaces at the start of a line\n" . $herevet) &&
3427 # check we are in a valid C source file if not then ignore this hunk
3433 "Lines should not end with a '$1'\n" . $herecurr);
3447 # check indentation of any line with a bare else
3448 # (but not if it is a multiple line "if (foo) return bar; else return baz;")
3449 # if the previous line is a break or return and is indented 1 tab more...
3457 "else is not generally useful after a break or return\n" . $hereprev);
3461 # check indentation of a line with a break;
3462 # if the previous line is a goto or return and is indented the same # of tabs
3467 "break is not useful after a goto or return\n" . $hereprev);
3496 # it there is no point in retrying a statement scan
3507 (!defined $lines[$realline_next - 1] ||
3508 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
3527 possible($type, "A:" . $s);
3534 # any (foo ... *) is a pointer cast, and foo is a type
3586 # if/while/etc brace do not go on next line, unless defining a do while loop,
3588 …if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $li…
3595 "Too many leading tabs - consider code refactoring\n" . $herecurr);
3598 my $ctx_cnt = $realcnt - $#ctx - 1;
3605 defined $lines[$ctx_ln - 1] &&
3606 $lines[$ctx_ln - 1] =~ /^-/)) {
3608 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
3613 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
3615 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
3618 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
3622 defined $lines[$ctx_ln - 1])
3624 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
3628 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
3634 …if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /…
3675 # Also ignore a loop construct at the end of a
3682 my $cond_ptr = -1;
3745 $prev_values = substr($curr_values, -1);
3751 if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
3753 $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
3759 "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
3815 fix_delete_line($fixlinenr - 1, $prevrawline);
3839 "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
3861 #print "APW <$lines[$realline_next - 1]>\n";
3863 exists $lines[$realline_next - 1] &&
3865 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
3866 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
3868 # a prefix:
3872 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
3885 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
3895 #print "FOO B <$lines[$linenr - 1]>\n";
3972 # check for const <foo> const where <foo> is not a pointer or array type
3984 # check for non-global char *foo[] = {"bar", ...} declarations.
4007 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
4030 # Should start with a space.
4032 # Should not end with a space.
4055 # Should start with a space.
4057 # Should not end with a space.
4085 …"Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . …
4101 if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
4106 if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
4125 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
4134 # ENOSYS means "bad syscall nr" and nothing else. This will have a small
4170 fix_delete_line($fixlinenr - 1, $prevrawline);
4204 # so check it for a missing trailing missing space but pointer return types
4205 # don't need a space so don't warn for those.
4221 # and this is form shouldn't/doesn't generate a checkpatch warning.
4263 # 1. with a type on the left -- int [] a;
4264 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
4265 # 3. inside a curly brace -- = { [0...10] = 5 }
4267 my ($where, $prefix) = ($-[1], $1);
4283 my $ctx_before = substr($line, 0, $-[1]);
4293 # cpp #define statements have non-optional spaces, ie
4294 # if there is a space between the name and the open
4295 # parenthesis it is simply not a parameter group.
4298 # cpp #elif statement condition may start with a (
4301 # If this whole things ends with a type its most
4302 # likely a typedef for a function.
4322 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
4323 =>|->|<<|>>|<|>|=|!|~|
4324 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
4345 my $last_after = -1;
4363 my $a = '';
4364 $a = 'V' if ($elements[$n] ne '');
4365 $a = 'W' if ($elements[$n] =~ /\s$/);
4366 $a = 'C' if ($elements[$n] =~ /$;$/);
4367 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
4368 $a = 'O' if ($elements[$n] eq '');
4369 $a = 'E' if ($ca =~ /^\s*$/);
4385 my $ctx = "${a}x${c}";
4405 # ; should have either the end of line or a space or \ after it
4416 # // is a comment
4419 # : when part of a bitfield
4424 # ->
4425 } elsif ($op eq '->') {
4437 # , must not have a space before and must have a space on the right.
4467 # '*' as part of a type definition -- reported already.
4471 # unary operators should have a space before and
4473 # unary operator, or a cast
4475 $opv eq '*U' || $opv eq '-U' ||
4477 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
4487 # A unary '*' may be const
4500 # unary ++ and unary -- are allowed no space on one side.
4501 } elsif ($op eq '++' or $op eq '--') {
4531 $op eq '+' or $op eq '-' or
4561 # A colon needs no spaces before when it is
4562 # terminating a case value or a label.
4586 # ignore a colon with another
4626 # check for whitespace before a non-naked semicolon
4642 ## # check for multiple declarations, allowing for a function declaration
4676 # closing brace should have a space following it when it has anything
4727 # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
4739 # ie: (foo->bar)(); should be foo->bar();
4740 # but not "if (foo->bar) (" to avoid some false positives
4753 # when !drivers/staging or command-line uses --strict
4758 my $test = substr($2, 1, -1);
4778 #goto labels aren't indented, allow a single space however
4779 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
4780 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
4789 # return is not a function
4798 "return is not a function, parentheses are not required\n" . $herecurr);
4806 # unnecessary return in a void function
4807 # at end-of-function, with the previous line a single leading tab, then return;
4808 # and the line before that not a goto label target like "out:"
4812 $lines[$linenr - 3] =~ /^[ +]/ &&
4813 $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
4818 # if statements using unnecessary parentheses - ie: if ((foo == bar))
4826 $msg = " - maybe == should be = ?" if ($comp eq "==");
4832 # comparisons with a constant or upper case identifier on the left
4837 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
4844 $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
4862 if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
4866 "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
4870 # Need a space before open parenthesis after if, while etc
4880 # Check for illegal assignment in if conditional -- and check for trailing
4895 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
4897 statement_rawlines($whitespace) - 1;
4941 \s*0[xX][0-9]+\s*
4945 \s*0[xX][0-9]+\s*
4962 # if should not continue a brace
4986 fix_delete_line($fixlinenr - 1, $prevrawline);
5012 fix_delete_line($fixlinenr - 1, $prevrawline);
5030 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
5032 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
5034 $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ &&
5036 $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
5039 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
5070 if (-f "$root/$checkfile" &&
5074 my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
5087 # multi-statement macros should be enclosed in a do while loop, grab the
5089 # in a known good container
5102 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
5113 $define_args = substr($define_args, 1, length($define_args) - 2);
5137 # Make asm volatile uses seem like a generic function
5160 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
5161 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
5162 …$dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // f…
5169 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
5176 …"Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic d…
5179 … "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
5187 # Make $define_stmt single line, comment-free, etc
5215 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
5227 # ## concatenation is commonly a macro that defines a function so ignore those
5249 # single-statement macros do not need to be enclosed in do while (0) loop,
5250 # macro should not end with a semicolon
5276 "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
5288 "macros should not use a trailing semicolon\n" . "$herectx");
5303 my $ln = $linenr - 1;
5308 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
5309 my $offset = statement_rawlines($whitespace) - 1;
5318 $ln += statement_rawlines($block) - 1;
5355 if (!defined $suppress_ifbraces{$linenr - 1} &&
5359 # Check the pre-context.
5360 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
5366 ctx_statement_full($linenr, $realcnt, $-[0]);
5386 # Check the post-context.
5393 #print "APW: ALLOWED: chunk-1 block<$block>\n";
5415 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
5417 fix_delete_line($fixlinenr - 1, $prevrawline);
5432 …"Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . …
5435 # Check for user-visible strings broken across lines, which breaks the ability
5436 # to grep for the string. Make exceptions when the previous string ends in a
5438 # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
5441 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
5446 $last_coalesced_string_linenr != $linenr - 1) {
5453 fix_delete_line($fixlinenr - 1, $prevrawline);
5458 fix_insert_line($fixlinenr - 1, $fixedline);
5468 # check for missing a space in a string concatenation
5471 "break quoted strings at a space character\n" . $hereprev);
5474 # check for an embedded function name in a string when the function is known
5475 # This does not work very well for -f --file checking as it depends on patch
5476 # context providing the function name or a single line form for in-file
5483 …\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecur…
5486 # check for spaces before a quoted newline
5489 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
5497 if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
5502 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
5503 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
5504 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
5512 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
5515 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
5516 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
5521 # check for non-standard and hex prefixed decimal printf formats
5525 my $string = substr($rawline, $-[1], $+[1] - $-[1]);
5530 "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
5533 # check for %Z
5534 if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) {
5536 "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
5576 if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
5581 if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
5590 fix_delete_line($fixlinenr - 1, $prevrawline);
5603 my $testline = $lines[$linenr - 3];
5605 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
5617 $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
5632 # check for mask then right shift without a parentheses
5637 … "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
5690 "Use of $attr requires a separate use of const\n" . $herecurr) &&
5701 # check for __read_mostly with const non-pointer (should just be const)
5730 … "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr);
5734 "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
5742 …"msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr);
5776 # check for spinlock_t definitions without a comment.
5785 # check for memory barriers without a comment.
5816 if ($realfile !~ m@^include/asm-generic/@ &&
5821 "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
5824 # check for waitqueue_active without a comment.
5839 … m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
5844 # check that the storage class is not after a type
5849 # Check that the storage class is at the beginning of a declaration
5894 my $old = substr($rawline, $-[1], $+[1] - $-[1]);
5895 my $new = substr($old, 1, -1);
5907 …"__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-ind…
5918 …"__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index…
6019 my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
6043 $use = " - use %pS instead";
6145 …"usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$her…
6149 …"usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$he…
6268 …"__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.rst\n" . $here…
6275 … "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
6302 !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
6320 "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
6351 …if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*…
6367 $prevline--;
6368 my $rline = $rawlines[$prevline - 1];
6369 my $fline = $lines[$prevline - 1];
6371 next if ($fline =~ /^\-/);
6373 $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i);
6385 # check for switch/default statements without a break;
6408 "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
6414 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
6438 ## maybe suggesting a correct construct would better
6447 "consider using a completion\n" . $herecurr);
6494 …"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_po…
6500 … "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
6540 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
6555 …E_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*…
6608 # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
6609 # o Ignore module_param*(...) uses with a decimal 0 permission as that has a
6611 # o Ignore proc_create*(...) uses with a decimal 0 permission as that means
6617 my $func = $entry->[0];
6618 my $arg_pos = $entry->[1];
6626 $arg_pos--;
6685 if ($#rawlines == -1) {
6689 # In mailback mode only produce a report in the negative, for
6695 # This is not a patch, and we are are in 'no-patch' mode so
6701 if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
6703 "Does not appear to be a unified-diff format patch\n");
6708 "Missing Signed-off-by: line(s)\n");
6711 "Missing Signed-off-by: line by nominal patch author '$author'\n");
6729 mechanically convert to the typical style using --fix or --fix-inplace.
6748 $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
6772 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
6777 This EXPERIMENTAL file is simply a convenience to help rewrite patches.