Lines Matching +full:check +full:- +full:patch
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>
44 my $check = 0;
73 my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
76 my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
78 my $git_command ='export LANGUAGE=en_US.UTF-8; git';
92 -q, --quiet quiet
93 -v, --verbose verbose mode
94 --no-tree run without a kernel tree
95 --no-signoff do not check for 'Signed-off-by' line
96 --no-fixes-tag do not check for 'Fixes:' tag
97 --patch treat FILE as patchfile (default)
98 --emacs emacs compile window format
99 --terse one line per report
100 --showfile emit diffed file position, not input file position
101 -g, --git treat FILE as a single commit or git revision range
109 <rev>-<count>
111 -f, --file treat FILE as regular source file
112 --subjective, --strict enable more subjective tests
113 --list-types list the possible message types
114 --types TYPE(,TYPE2...) show only these comma separated message types
115 --ignore TYPE(,TYPE2...) ignore various comma separated message types
116 --show-types show the specific message type in the output
117 --max-line-length=n set the maximum line length, (default $max_line_length)
119 requires --strict for use with --file
120 --min-conf-desc-length=n set the min description length, if shorter, warn
121 --tab-size=n set the number of spaces for tab (default $tabsize)
122 --root=PATH PATH to the kernel tree root
123 --no-summary suppress the per-file summary
124 --mailback only produce a report in case of warnings/errors
125 --summary-file include the filename in summary
126 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
129 --test-only=WORD report only warnings/errors containing WORD
131 --fix EXPERIMENTAL - may create horrible results
132 If correctable single-line errors exist, create
133 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
136 --fix-inplace EXPERIMENTAL - may create horrible results
137 Is the same as --fix, but overwrites the input
139 --ignore-perl-version override checking of perl version. expect
141 --codespell Use the codespell dictionary for spelling/typos
143 --codespellfile Use this codespell dictionary
144 --typedefsfile Read additional types from this file
145 --color[=WHEN] Use colors 'always', 'never', or only when output
147 --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
149 -h, --help, --version display this help and exit
151 When FILE is - read standard input.
196 print(GREEN . "CHECK" . RESET);
226 if (-f $conf) {
292 # Prevent --color by itself from consuming other arguments
294 if ($_ eq "--color" || $_ eq "-color") {
295 $_ = "--color=$color";
304 'fixes-tag!' => \$chk_fixes_tag,
305 'patch!' => \$chk_patch,
311 'subjective!' => \$check,
312 'strict!' => \$check,
315 'show-types!' => \$show_types,
316 'list-types!' => \$list_types,
317 'max-line-length=i' => \$max_line_length,
318 'min-conf-desc-length=i' => \$min_conf_desc_length,
319 'tab-size=i' => \$tabsize,
323 'summary-file!' => \$summary_file,
325 'fix-inplace!' => \$fix_inplace,
326 'ignore-perl-version!' => \$ignore_perl_version,
328 'test-only=s' => \$tst_only,
333 'no-color' => \$color, #keep old behaviors of -nocolor
334 'nocolor' => \$color, #keep old behaviors of -nocolor
335 'kconfig-prefix=s' => \${CONFIG_},
343 } elsif (!(-f $codespellfile)) {
356 my $codespell_dict = `python3 -c "$python_codespell_dict" 2> /dev/null`;
357 $codespellfile = $codespell_dict if (-f $codespell_dict);
361 # $help is 1 if either -h, --help or --version is passed as option - exitcode: 0
362 # $help is 2 if invalid option is passed - exitcode: 1
363 help($help - 1) if ($help);
365 die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
366 die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);
375 $color = (-t STDOUT);
384 $check_orig = $check;
395 #if no filenames are given, push '-' to read patch from stdin
397 push(@ARGV, '-');
400 # skip TAB size 1 to avoid additional checks on $tabsize - 1
411 $word =~ tr/[a-z]/[A-Z]/;
416 $hashRef->{$word}++;
455 die "$P: $root: --root does not point at a valid tree\n";
467 print "Must be run from the top-level dir. of a kernel tree\n";
475 [A-Za-z_][A-Za-z\d_]*
476 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
499 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
531 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
536 our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
537 our $Int = qr{[0-9]+$Int_type?};
538 our $Octal = qr{0[0-7]+$Int_type?};
540 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
541 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
542 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
545 our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
546 our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
547 our $Arithmetic = qr{\+|-|\*|\/|%};
550 =>|->|<<|>>|<|>|!|~|
551 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
566 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
567 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
568 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
569 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
570 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
571 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
572 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
576 [\x09\x0A\x0D\x20-\x7E] # ASCII
603 …(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|co…
607 MODULE_[A-Z_]+|
622 Signed-off-by:|
623 Co-developed-by:|
624 Acked-by:|
625 Tested-by:|
626 Reviewed-by:|
627 Reported-by:|
628 Suggested-by:|
650 [=-]*> |
651 <[=-]* |
681 for my $i (0 .. ($len-1)) {
693 $str1 =~ s/-//g;
694 $str2 =~ s/-//g;
705 } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) {
706 $distance[$i][$j] = $distance[$i - 1][$j - 1];
708 my $dist1 = $distance[$i][$j - 1]; #insert distance
709 my $dist2 = $distance[$i - 1][$j]; # remove
710 my $dist3 = $distance[$i - 1][$j - 1]; #replace
721 'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:',
722 'Reviewed-by:', 'Reported-by:', 'Suggested-by:'
732 \Qfreedesktop.org/archives/dri-devel\E |
735 \Qmail-archive.com\E |
736 \Qmailman.alsa-project.org/pipermail\E |
824 ["IIO_DEV_ATTR_[A-Z_]+", 1],
830 my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
836 $mode_perms_search .= $entry->[0];
870 0[0-7][0-7][2367]
907 return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
918 last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
958 warn "No typos will be found - file '$spelling_file': $!\n";
975 my ($suspect, $fix) = split(/->/, $line);
981 warn "No codespell typos will be found - file '$codespellfile': $!\n";
1000 print("$file: '$line' invalid - ignored\n");
1017 or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
1023 or warn "No additional types will be considered - file '$typedefsfile': $!\n";
1083 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
1088 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
1118 return if (!(-f $file));
1130 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
1131 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
1133 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
1135 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
1146 return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
1149 …s{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback…
1158 …return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitr…
1161 my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
1176 if (-e "$gitroot") {
1177 …my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include…
1179 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
1182 $files = `find $root/include -name "*.h"`;
1189 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
1192 if ($camelcase_cache ne "" && -f $camelcase_cache) {
1204 if (-e "$gitroot") {
1205 $files = `${git_command} ls-files "include/*.h"`;
1214 unlink glob ".checkpatch-camelcase.*";
1227 return 0 if ((which("git") eq "") || !(-e "$gitroot"));
1229 my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
1237 return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
1239 my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
1250 # git rev-list --remotes | grep -i "^$1" |
1252 # git log --format='%H %s' -1 $line |
1253 # echo "commit $(cut -c 1-12,41-)"
1274 my $fixlinenr = -1;
1277 # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
1278 die "$P: No git repository found\n" if ($git && !-e "$gitroot");
1284 if ($commit_expr =~ m/^(.*)-(\d+)$/) {
1285 $git_range = "-$2 $1";
1289 $git_range = "-1 $commit_expr";
1291 my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
1293 $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
1313 open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
1314 die "$P: $filename: git format-patch failed - $!\n";
1316 open($FILE, '-|', "diff -u /dev/null $filename") ||
1317 die "$P: $filename: diff failed - $!\n";
1318 } elsif ($filename eq '-') {
1322 die "$P: $filename: open failed - $!\n";
1324 if ($filename eq '-') {
1325 $vname = 'Your patch';
1334 $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
1339 print '-' x length($vname) . "\n";
1341 print '-' x length($vname) . "\n";
1352 $fixlinenr = -1;
1390 foreach my $check (@tree_check) {
1391 if (! -e $root . '/' . $check) {
1435 # "John D. (Doe)" - Do not extract
1449 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1466 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1508 if (-e "$path/$bin") {
1520 if (-e "$path/$conf") {
1675 return substr($rawline, $-[0], $+[0] - $-[0]);
1680 my $line = $linenr - 1;
1683 my $coff = $off - 1;
1697 @stack = (['', 0]) if ($#stack == -1);
1705 next if ($lines[$line] =~ /^-/);
1706 $remain--;
1733 ($type, $level) = @{$stack[$#stack - 1]};
1749 $coff = $off + length($1) - 1;
1752 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
1760 $level--;
1774 $level--;
1786 $level--;
1797 $remain--;
1800 my $statement = substr($blk, $soff, $off - $soff + 1);
1801 my $condition = substr($blk, $soff, $coff - $soff + 1);
1809 $line, $remain + 1, $off - $loff + 1, $level);
1866 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
1876 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1887 my $start = $linenr - 1;
1896 next if ($rawlines[$line] =~ /^-/);
1897 $remain--;
1905 $level = $stack[$#stack - 1];
1913 $off--;
1918 $level--;
1967 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
1969 ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
1975 ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
1983 my $line = $rawlines[$linenr - 1];
2007 ##print "LINE: $rawlines[$end_line - 1 ]\n";
2016 my $offset = $linenr - 1;
2022 next if (defined($line) && $line =~ /^-/);
2023 $cnt--;
2193 print "PAREN('$1') -> $type\n"
2249 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
2264 if ($1 ne '++' && $1 ne '--') {
2301 warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
2303 # Check for modifiers.
2332 $type =~ tr/[a-z]/[A-Z]/;
2365 my @lines = split("\n", $output, -1);
2392 if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
2421 if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
2423 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
2431 fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
2496 if ($check && report("CHECK", $type, $msg)) {
2512 if (-f "$root/$file") {
2517 if (! -f _) {
2523 substr($prefix, -length($file)) = '';
2568 my $max_spaces_before_tab = $source_indent - 1;
2590 return -1;
2598 $pos += length($1) - 1;
2601 } elsif (index($string, '(') == -1) {
2613 for my $i (0 .. (length($line) - 1)) {
2625 …# Do not check for BPF programs (tools/testing/selftests/bpf/progs/*.c, samples/bpf/*_kern.c, *.bp…
2654 my $is_binding_patch = -1;
2656 my $in_commit_log = 0; #Scanning lines before patch
2657 my $has_patch_separator = 0; #Found a --- line
2658 my $has_commit_log = 0; #Encountered lines before patch
2666 my $last_git_commit_id_linenr = -1;
2669 my $last_coalesced_string_linenr = -1;
2698 # Pre-scan the patch sanitizing the lines.
2699 # Pre-scan the patch looking for any __setup documentation.
2718 if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
2723 if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
2724 $realline=$1-1;
2739 next if (defined $rawlines[$ln - 1] &&
2740 $rawlines[$ln - 1] =~ /^-/);
2741 $cnt--;
2742 #print "RAW<$rawlines[$ln - 1]>\n";
2743 last if (!defined $rawlines[$ln - 1]);
2744 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
2745 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
2768 # simplify matching -- only bother with positive lines.
2774 $realcnt-- if ($line =~ /^(?:\+| |$)/);
2780 #print "-->$line\n";
2791 $fixlinenr = -1;
2798 my $rawline = $rawlines[$linenr - 1];
2801 # check if it's a mode change, rename or start of a patch
2803 ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
2805 $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
2809 #extract the line range in the file after the patch is applied
2811 $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
2815 $realline=$1-1;
2840 $realcnt-- if ($realcnt != 0);
2853 $realcnt--;
2863 if ($line =~ /^diff --git.*?(\S+)$/) {
2875 -e "$root/$p1_prefix") {
2877 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
2882 …"do not modify files in include/asm, change architecture specific files in include/asm-<architectu…
2904 $check = 1;
2906 $check = $check_orig;
2913 $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
2915 if (($last_binding_patch != -1) &&
2918 … binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/subm…
2941 "Missing commit description - Add an appropriate one\n");
2945 # Check if the commit log has what seems like a diff which can confuse patch
2949 $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
2950 $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
2952 "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
2956 # Check for incorrect file permissions
2966 # Check the patch for a From:
2967 if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
2973 $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
2978 # Check the patch for a signoff:
2979 if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
3017 # Check for patch separator
3018 if ($line =~ /^---$/) {
3023 # Check if MAINTAINERS is being updated. If so, there's probably no need to
3029 # Check signature styles
3031 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
3042 "Non-standard signature: $sign_off\n" . $herecurr);
3045 "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) &&
3059 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
3123 $cur_name =~ s/[a-zA-Z\s\-\"]+//g;
3162 # Check for duplicate signatures
3173 # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
3174 if ($sign_off =~ /^co-developed-by:$/i) {
3177 … "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . $herecurr);
3181 "Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr);
3182 } elsif ($rawlines[$linenr] !~ /^signed-off-by:\s*(.*)/i) {
3184 …"Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr . $rawlines[$linen…
3187 …"Co-developed-by and Signed-off-by: name/email do not match\n" . $herecurr . $rawlines[$linenr] . …
3191 # check if Reported-by: is followed by a Closes: tag
3192 if ($sign_off =~ /^reported(?:|-and-tested)-by:$/i) {
3195 …"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . …
3198 …"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . …
3214 # Check Fixes: styles is correct
3216 $line =~ /^\s*fixes:?\s*(?:commit\s*)?[0-9a-f]{5,}\b/i) {
3227 if ($line =~ /(\s*fixes:?)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) {
3233 $tag_space = 0 if ($line =~ /^fixes:? [0-9a-f]{5,} ($balanced_parens)/i);
3235 $id_length = 0 if ($orig_commit =~ /^[0-9a-f]{12}$/i);
3236 $id_case = 0 if ($orig_commit !~ /[A-F]/);
3239 $title = substr($title, 1, -1);
3241 $title = substr($title, 1, -1);
3252 …"Please use correct Fixes: style 'Fixes: <12 chars of sha1> (\"<title line>\")' - ie: 'Fixes: $cid…
3259 # Check email subject for common tools that don't need to be mentioned
3263 "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
3266 # Check for Gerrit Change-Ids not in any patch context
3267 if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
3269 "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
3275 # Check if the commit log is in a possible stack dump
3280 $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
3281 $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
3282 $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
3287 # Check for line lengths > 75 in commit log, warn once
3290 !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
3292 $line =~ /^\s*(?:[\w\.\-\+]*\/)++[\w\.\-\+]+:/ ||
3308 # Check for odd tags before a URI/URL
3313 "Patch version information should be after the --- line\n" . $herecurr);
3320 # Check for misuse of the link tags
3331 # Check for lines starting with a #
3340 # Check for git id commit length and improperly formed commit descriptions
3342 # commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
3345 # bare SHA-1 hash with minimum length of 5. It also avoids several types of
3346 # possible SHA-1 matches.
3351 $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
3352 $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
3353 (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
3354 … /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
3355 ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
3356 $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
3357 $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
3372 if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
3374 if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
3378 $orig_desc = substr($orig_desc, 1, -1);
3380 $orig_desc = substr($orig_desc, 1, -1);
3392 if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
3395 $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
3396 $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
3397 $space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
3398 $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
3399 } elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
3408 $last_git_commit_id_linenr != $linenr - 1) {
3410 …it commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}omm…
3416 # Check for mailing list archives other than lore.kernel.org
3419 …"Use lore.kernel.org archive links when possible - see https://lore.kernel.org/lists.html\n" . $he…
3422 # Check for added, moved or deleted files
3425 $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
3426 ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
3434 # Check for adding new DT bindings not in schema format
3439 …"DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.…
3442 # Check for wrappage within a valid hunk of the file
3443 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
3445 "patch seems to be corrupt (line wrapped?)\n" .
3449 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
3459 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
3462 # Check if it's the start of a commit log
3463 # (not a header line and we haven't seen the patch filename)
3466 $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
3472 # Check if there is UTF-8 in a commit log when a mail header has explicitly
3475 $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
3476 $1 !~ /utf-8/i) {
3483 "8-bit UTF-8 used in possible commit log\n" . $herecurr);
3486 # Check for absolute kernel paths in commit message
3500 # Check for various typo / spelling mistakes
3503 while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
3506 my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
3509 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
3510 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
3514 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) &&
3516 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
3521 # check for invalid commit id
3522 if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
3532 # check for repeated words separated by a single space
3533 # avoid false positive from list command eg, '-rw-r--r-- 1 root root'
3535 $rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) {
3541 my $start_pos = $-[1];
3551 # check for character before and after the word matches
3554 $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1));
3558 next if (index(" \t.,;?!", $end_char) == -1);
3561 if ($first =~ /\b[0-9a-f]{2,}\b/i) {
3586 # ignore non-hunk lines and lines being removed
3587 next if (!$hunk_line || $line =~ /^-/);
3608 # Check for FSF mailing addresses.
3620 # check for Kconfig help text having a real description
3635 next if ($f =~ /^-/);
3636 last if ($f !~ /^[\+ ]/); # !patch context
3647 $f =~ s/^.//; # strip patch context [+ ]
3653 # This only checks context lines in the patch
3665 my $stat_real = get_stat_real($linenr, $ln - 1);
3671 # check MAINTAINERS entries
3673 # check MAINTAINERS entries for the right form
3674 if ($rawline =~ /^\+[A-Z]:/ &&
3675 $rawline !~ /^\+[A-Z]:\t\S/) {
3679 $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3682 # check MAINTAINERS entries for the right ordering too
3684 if ($rawline =~ /^\+[A-Z]:/ &&
3685 $prevrawline =~ /^[\+ ][A-Z]:/) {
3686 $rawline =~ /^\+([A-Z]):\s*(.*)/;
3689 $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
3700 "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
3705 "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
3712 ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
3715 'EXTRA_AFLAGS' => 'asflags-y',
3716 'EXTRA_CFLAGS' => 'ccflags-y',
3717 'EXTRA_CPPFLAGS' => 'cppflags-y',
3718 'EXTRA_LDFLAGS' => 'ldflags-y',
3722 … of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacem…
3725 # check for DT compatible documentation
3730 my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
3733 my $vp_file = $dt_path . "vendor-prefixes.yaml";
3737 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
3739 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
3740 `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
3743 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
3746 next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
3748 `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
3751 … "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
3756 # check for using SPDX license tag at beginning of files
3772 # check SPDX comment style for .[chsS] files
3774 $rawline =~ /SPDX-License-Identifier:/ &&
3781 $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
3783 … "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
3784 } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
3791 $spdx_license !~ /GPL-2\.0(?:-only)? OR BSD-2-Clause/) {
3796 "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
3798 …$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-…
3801 if ($realfile =~ m@^include/dt-bindings/@ &&
3802 $spdx_license !~ /GPL-2\.0(?:-only)? OR \S+/) {
3804 "DT binding headers should be licensed (GPL-2.0-only OR .*)\n" . $herecurr);
3810 # check for embedded filenames
3816 # check we are in a valid source file if not then ignore this hunk
3819 # check for using SPDX-License-Identifier on the wrong line number
3821 $rawline =~ /\bSPDX-License-Identifier:/ &&
3822 substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
3824 "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
3846 # Check the allowed long line types first
3851 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3866 } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
3873 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3878 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3891 # check for adding lines without a newline.
3900 # check for .L prefix local symbols in .S files
3902 $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
3904 … range of code via 'SYM_*_START/END' annotations; see Documentation/core-api/asm-annotations.rst\n…
3907 # check we are in a valid source file C or perl if not then ignore this hunk
3923 # check for space before tabs.
3936 # check for assignments on the start of a line
3943 $fixed[$fixlinenr - 1] .= " $operator";
3948 # check for && or || at the start of a line
3954 # insert logical operator at last non-comment, non-whitepsace char on previous line
3956 my $line_end = substr($prevrawline, $-[0]);
3957 $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/;
3962 # check indentation starts on a tab stop
3975 # check multi-line statement indentation matches previous line
4005 # check for space after cast like "(int) foo" or "(struct foo) bar"
4027 …$realline > 3) { # Do not warn about the initial copyright comment block after SPDX-License-Identi…
4075 # check for missing blank lines after struct/union declarations
4083 $line =~ /^\+[a-z_]*init/ ||
4084 $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
4095 # check for multiple consecutive blank lines
4098 $last_blank_line != ($linenr - 1)) {
4108 # check for missing blank lines after declarations
4154 # check for spaces at the beginning of a line.
4168 # check we are in a valid C source file if not then ignore this hunk
4171 # check for unusual line ending [ or (
4177 # check if this appears to be the start function declaration, save the name
4183 # check if this appears to be the end of function declaration
4188 # check indentation of any line with a bare else
4202 # check indentation of a line with a break;
4216 # check for RCS/CVS revision markers
4222 # check for old HOTPLUG __dev<foo> section markings
4228 # Check for potential 'bare' types
4252 (!defined $lines[$realline_next - 1] ||
4253 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
4284 # Check for any sort of function declaration.
4308 # Check for switch () and associated case and default
4333 …if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $li…
4340 "Too many leading tabs - consider code refactoring\n" . $herecurr);
4343 my $ctx_cnt = $realcnt - $#ctx - 1;
4350 defined $lines[$ctx_ln - 1] &&
4351 $lines[$ctx_ln - 1] =~ /^-/)) {
4353 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
4358 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
4360 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
4363 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4367 defined $lines[$ctx_ln - 1])
4369 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
4373 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4378 # Check relative indent for conditionals and blocks.
4379 …if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /…
4403 # We want to check the first line inside the block
4409 my $check = 0;
4416 $check = 1;
4424 $check = 0;
4427 my $cond_ptr = -1;
4435 $check = 0;
4456 # Check if either of these lines are modified, else
4457 # this is not this patch's fault.
4460 $check = 0;
4466 …#print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuati…
4468 if ($check && $s ne '' &&
4490 $prev_values = substr($curr_values, -1);
4495 # check for self assignments used to avoid compiler warnings
4498 if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
4502 "Do not use self-assignments to avoid compiler warnings\n" . $herecurr);
4506 # check for dereferences that span multiple lines
4507 if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
4509 $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
4515 "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
4518 # check for declarations of signed or unsigned without int
4565 # check for initialisation to aggregates open brace on the next line
4571 fix_delete_line($fixlinenr - 1, $prevrawline);
4586 # check for malformed paths in #include statements (uses RAW line)
4617 #print "APW <$lines[$realline_next - 1]>\n";
4619 exists $lines[$realline_next - 1] &&
4621 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
4628 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
4641 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
4650 #print "FOO B <$lines[$linenr - 1]>\n";
4659 # check for global initialisers.
4668 # check for static initialisers.
4678 # check for misordered declarations of char/short/int/long with signed/unsigned
4685 # check for unnecessary <signed> int declarations of short/long/long long
4705 # check for static const char * arrays.
4712 # check for initialized const char arrays that should be static const
4721 # check for static char foo[] = "bar" declarations.
4728 # check for const <foo> const where <foo> is not a pointer or array type
4740 # check for const static or static <non ptr type> const declarations
4745 "Move const after static - use 'static const $1'\n" . $herecurr) &&
4752 # check for non-global char *foo[] = {"bar", ...} declarations.
4759 # check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
4772 # check for function declarations without arguments like "int foo()"
4775 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
4781 # check for new typedefs, only function parameters and sparse annotations
4849 …e =~ /\b(?!AA_|BUILD_|DCCP_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\…
4853 …"Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery cod…
4862 # check for uses of printk_ratelimit
4869 if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
4875 if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
4891 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
4953 fix_delete_line($fixlinenr - 1, $prevrawline);
4976 # check spacing between type, funcptr, and args
4987 # so check it for a missing trailing missing space but pointer return types
5045 # check for spacing round square brackets; allowed:
5046 # 1. with a type on the left -- int [] a;
5047 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
5048 # 3. inside a curly brace -- = { [0...10] = 5 }
5050 my ($where, $prefix) = ($-[1], $1);
5063 # check for spaces between functions and their parentheses.
5066 my $ctx_before = substr($line, 0, $-[1]);
5076 # cpp #define statements have non-optional spaces, ie
5098 # Check operator spacing.
5105 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
5106 =>|->|<<|>>|<|>|=|!|~|
5107 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
5128 my $last_after = -1;
5207 # ->
5208 } elsif ($op eq '->') {
5250 # '*' as part of a type definition -- reported already.
5258 $opv eq '*U' || $opv eq '-U' ||
5260 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
5283 # unary ++ and unary -- are allowed no space on one side.
5284 } elsif ($op eq '++' or $op eq '--') {
5314 $op eq '+' or $op eq '-' or
5318 if ($check) {
5409 # check for whitespace before a non-naked semicolon
5419 # check for multiple assignments
5425 ## # check for multiple declarations, allowing for a function declaration
5451 ## # check for blank lines before declarations
5470 # check spacing on square brackets
5488 # check spacing on parentheses
5509 # check unnecessary parentheses around addressof/dereference single $Lvals
5510 # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
5521 # check for unnecessary parentheses around function pointer uses
5522 # ie: (foo->bar)(); should be foo->bar();
5523 # but not "if (foo->bar) (" to avoid some false positives
5535 # check for unnecessary parentheses around comparisons in if uses
5536 # when !drivers/staging or command-line uses --strict
5541 my $test = substr($2, 1, -1);
5561 # check that goto labels aren't indented (allow a single space indentation)
5565 if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
5566 $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
5576 # check if a statement with a comma should be two statements like:
5605 # at end-of-function, with the previous line a single leading tab, then return;
5610 $lines[$linenr - 3] =~ /^[ +]/ &&
5611 $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
5616 # if statements using unnecessary parentheses - ie: if ((foo == bar))
5624 $msg = " - maybe == should be = ?" if ($comp eq "==");
5635 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
5642 $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
5660 if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
5664 "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
5678 # Check for illegal assignment in if conditional -- and check for trailing
5693 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
5695 statement_rawlines($whitespace) - 1;
5771 # Check for bitwise tests written as boolean
5775 \s*0[xX][0-9]+\s*
5779 \s*0[xX][0-9]+\s*
5813 # Check for }<nl>else {, these must be at the same
5820 fix_delete_line($fixlinenr - 1, $prevrawline);
5846 fix_delete_line($fixlinenr - 1, $prevrawline);
5864 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
5866 $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
5868 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
5873 $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
5875 $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
5878 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
5879 if ($check) {
5909 if (-f "$root/$checkfile" &&
5913 my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
5926 # multi-statement macros should be enclosed in a do while loop, grab the
5941 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
5952 $define_args = substr($define_args, 1, length($define_args) - 2);
5999 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
6000 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
6001 …$dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // f…
6010 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
6017 …"Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic d…
6020 … "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
6028 # Make $define_stmt single line, comment-free, etc
6045 # check if any macro arguments are reused (ignore '...' and 'type')
6056 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
6058 # check if any macro arguments may have other precedence issues
6066 # check if this is an unused argument
6069 "Argument '$arg' is not used in function-like macro\n" . "$herectx");
6073 # check for macros with flow control, but without ## concatenation
6083 # check for line continuations outside of #defines, preprocessor #, and asm
6099 # single-statement macros do not need to be enclosed in do while (0) loop,
6142 # check for redundant bracing round if etc
6153 my $ln = $linenr - 1;
6158 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
6159 my $offset = statement_rawlines($whitespace) - 1;
6168 $ln += statement_rawlines($block) - 1;
6205 if (!defined $suppress_ifbraces{$linenr - 1} &&
6209 # Check the pre-context.
6210 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
6216 ctx_statement_full($linenr, $realcnt, $-[0]);
6218 # Check the condition.
6236 # Check the post-context.
6243 #print "APW: ALLOWED: chunk-1 block<$block>\n";
6256 # check for single line unbalanced braces
6262 # check for unnecessary blank lines around braces
6267 fix_delete_line($fixlinenr - 1, $prevrawline);
6282 …"Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . …
6285 # Check for user-visible strings broken across lines, which breaks the ability
6291 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
6296 $last_coalesced_string_linenr != $linenr - 1) {
6303 fix_delete_line($fixlinenr - 1, $prevrawline);
6308 fix_insert_line($fixlinenr - 1, $fixedline);
6318 # check for missing a space in a string concatenation
6324 # check for an embedded function name in a string when the function is known
6325 # This does not work very well for -f --file checking as it depends on patch
6326 # context providing the function name or a single line form for in-file
6336 # check for unnecessary function tracing like uses
6341 "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
6347 # check for spaces before a quoted newline
6358 if ($line =~ /$String[A-Z_]/ ||
6359 ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
6364 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
6365 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
6366 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
6377 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
6378 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
6383 # check for non-standard and hex prefixed decimal printf formats
6387 my $string = substr($rawline, $-[1], $+[1] - $-[1]);
6389 # check for %L
6392 "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
6395 # check for %Z
6398 "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
6401 # check for 0x<decimal>
6408 # check for line continuations in quoted strings with odd counts of "
6426 # check for needless "if (<foo>) fn(<foo>)" uses
6433 "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
6438 if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
6443 if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
6452 fix_delete_line($fixlinenr - 1, $prevrawline);
6459 # check for unnecessary "Out of Memory" messages
6465 my $testline = $lines[$linenr - 3];
6467 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
6477 # check for logging functions with KERN_<LEVEL>
6479 $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
6488 # check for logging continuations
6494 # check for unnecessary use of %h[xudi] and %hh[xudi] in logging functions
6502 while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) {
6505 my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
6516 # check for mask then right shift without a parentheses
6521 … "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
6524 # check for pointer comparisons to NULL
6538 # check for bad placement of section $InitAttribute (e.g.: __initdata)
6556 # check for $InitAttributeData (ie: __initdata) with const
6570 # check for $InitAttributeConst (ie: __initconst) without const
6585 # check for __read_mostly with const non-pointer (should just be const)
6614 … "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr);
6618 "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
6626 …"msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr);
6630 # check for comparisons of jiffies
6636 # check for comparisons of get_jiffies_64()
6660 # check for spinlock_t definitions without a comment.
6669 # check for memory barriers without a comment.
6699 if ($realfile !~ m@^include/asm-generic/@ &&
6704 "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
6707 # check for waitqueue_active without a comment.
6715 # check for data_race without a comment.
6723 # check of hardware specific defines
6724 … m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
6729 # check that the storage class is not after a type
6734 # Check that the storage class is at the beginning of a declaration
6743 # check the location of the inline attribute, that it is between
6751 # Check for __inline__ and __inline, prefer inline
6762 # Check for compiler attributes
6820 # Check for __attribute__ unused, prefer __always_unused or __maybe_unused
6827 # Check for __attribute__ weak, or __weak declarations (may have link issues)
6836 # check for c99 types like uint8_t used outside of uapi/ and tools/
6855 # check for cast of C90 native int or longer types constants
6869 …"Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr)…
6875 # check for sizeof(&)
6881 # check for sizeof without parenthesis
6890 # check for struct spinlock declarations
6896 # check for seq_printf uses that could be seq_puts
6909 # check for vsprintf extension %p<foo> misuses
6923 my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
6952 $use = " - use %pS instead";
6955 $use = " - '%pA' is only intended to be used from Rust code";
6965 # Check for misused memsets
6983 # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
6994 # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
7002 # check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
7003 # check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
7028 "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
7034 "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
7040 …"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/iss…
7086 # check usleep_range arguments
7094 …"usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$her…
7098 …"usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$he…
7102 # check for naked sscanf
7116 # check for simple sscanf that should be kstrto<foo>
7134 # check for new externs in .h files.
7144 # check for new externs in .c files.
7177 "found a file-scoped extern type:$st_type name:$st_name in .c file\n"
7188 # check for function declarations that have arguments without identifier names
7202 # check for function definitions
7208 # check for multiline function definition with misplaced open brace
7231 …"__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $here…
7235 # check for pointless casting of alloc functions
7238 … "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
7249 # check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kca…
7267 !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
7280 # check for krealloc arg reuse
7288 # check for alloc argument mismatch
7294 # check for multiple semicolons
7303 # check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
7315 # check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
7321 # check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
7322 …if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:…
7331 # check for /* fallthrough */ like comment, prefer fallthrough;
7335 'lint -fallthrough[ \t]*',
7336 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
7337 '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
7338 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7339 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7353 # check for switch/default statements without a break;
7364 # check for gcc specific __FUNCTION__
7373 # check for uses of __DATE__, __TIME__, __TIMESTAMP__
7376 "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
7379 # check for use of yield()
7382 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
7385 # check for comparisons against true and false
7412 # check for semaphores initialized locked
7424 # check for __initcall(), use device_initcall() explicitly or more appropriate function please
7430 # check for spin_is_locked(), suggest lockdep instead
7436 # check for deprecated apis
7444 # check for various structs that are normally const (ops, kgdb, device_tree)
7465 …"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_po…
7471 … "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
7483 substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) {
7484 my $offset = $+[6] - 1;
7492 # check for array definition/declarations that should use flexible arrays instead
7496 …"Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one…
7498 $fixed[$fixlinenr - 1] =~ s/\[\s*0\s*\]/[]/;
7543 # check for lockdep_set_novalidate_class
7550 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
7560 # check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO>
7565 …E_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*…
7627 my $func = $entry->[0];
7628 my $arg_pos = $entry->[1];
7636 $arg_pos--;
7657 # check for uses of S_<PERMS> that could be octal for readability
7686 …"Prefer \"GPL\" over \"GPL v2\" - see commit bf7fbeeae6db (\"module: Cure the MODULE_LICENSE \"GPL…
7693 # check for sysctl duplicate constants
7702 if ($#rawlines == -1) {
7712 # This is not a patch, and we are in 'no-patch' mode so
7718 if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
7720 "Does not appear to be a unified-diff format patch\n");
7731 "Missing Signed-off-by: line(s)\n");
7734 # 0 -> missing sign off
7735 # 1 -> sign off identical
7736 # 2 -> names and addresses match, comments mismatch
7737 # 3 -> addresses match, names different
7738 # 4 -> names match, addresses different
7739 # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
7741 my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
7745 "Missing Signed-off-by: line by nominal patch author '$author'\n");
7748 "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
7751 "From:/Signed-off-by: email name mismatch: $sob_msg\n");
7754 "From:/Signed-off-by: email address mismatch: $sob_msg\n");
7757 "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
7766 (($check)? "$cnt_chk checks, " : "") .
7776 mechanically convert to the typical style using --fix or --fix-inplace.
7795 $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
7819 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'