.. | .. |
---|
43 | 43 | my $fix = 0; |
---|
44 | 44 | my $fix_inplace = 0; |
---|
45 | 45 | my $root; |
---|
| 46 | +my $gitroot = $ENV{'GIT_DIR'}; |
---|
| 47 | +$gitroot = ".git" if !defined($gitroot); |
---|
46 | 48 | my %debug; |
---|
47 | 49 | my %camelcase = (); |
---|
48 | 50 | my %use_type = (); |
---|
.. | .. |
---|
51 | 53 | my @ignore = (); |
---|
52 | 54 | my $help = 0; |
---|
53 | 55 | my $configuration_file = ".checkpatch.conf"; |
---|
54 | | -my $max_line_length = 80; |
---|
| 56 | +my $max_line_length = 100; |
---|
55 | 57 | my $ignore_perl_version = 0; |
---|
56 | 58 | my $minimum_perl_version = 5.10.0; |
---|
57 | 59 | my $min_conf_desc_length = 4; |
---|
.. | .. |
---|
59 | 61 | my $codespell = 0; |
---|
60 | 62 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; |
---|
61 | 63 | my $conststructsfile = "$D/const_structs.checkpatch"; |
---|
62 | | -my $typedefsfile = ""; |
---|
| 64 | +my $typedefsfile; |
---|
63 | 65 | my $color = "auto"; |
---|
64 | | -my $allow_c99_comments = 1; |
---|
| 66 | +my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE |
---|
| 67 | +# git output parsing needs US English output, so first set backtick child process LANGUAGE |
---|
| 68 | +my $git_command ='export LANGUAGE=en_US.UTF-8; git'; |
---|
| 69 | +my $tabsize = 8; |
---|
| 70 | +my ${CONFIG_} = "CONFIG_"; |
---|
65 | 71 | |
---|
66 | 72 | sub help { |
---|
67 | 73 | my ($exitcode) = @_; |
---|
.. | .. |
---|
94 | 100 | --types TYPE(,TYPE2...) show only these comma separated message types |
---|
95 | 101 | --ignore TYPE(,TYPE2...) ignore various comma separated message types |
---|
96 | 102 | --show-types show the specific message type in the output |
---|
97 | | - --max-line-length=n set the maximum line length, if exceeded, warn |
---|
| 103 | + --max-line-length=n set the maximum line length, (default $max_line_length) |
---|
| 104 | + if exceeded, warn on patches |
---|
| 105 | + requires --strict for use with --file |
---|
98 | 106 | --min-conf-desc-length=n set the min description length, if shorter, warn |
---|
| 107 | + --tab-size=n set the number of spaces for tab (default $tabsize) |
---|
99 | 108 | --root=PATH PATH to the kernel tree root |
---|
100 | 109 | --no-summary suppress the per-file summary |
---|
101 | 110 | --mailback only produce a report in case of warnings/errors |
---|
.. | .. |
---|
121 | 130 | --typedefsfile Read additional types from this file |
---|
122 | 131 | --color[=WHEN] Use colors 'always', 'never', or only when output |
---|
123 | 132 | is a terminal ('auto'). Default is 'auto'. |
---|
| 133 | + --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default |
---|
| 134 | + ${CONFIG_}) |
---|
124 | 135 | -h, --help, --version display this help and exit |
---|
125 | 136 | |
---|
126 | 137 | When FILE is - read standard input. |
---|
.. | .. |
---|
213 | 224 | 'list-types!' => \$list_types, |
---|
214 | 225 | 'max-line-length=i' => \$max_line_length, |
---|
215 | 226 | 'min-conf-desc-length=i' => \$min_conf_desc_length, |
---|
| 227 | + 'tab-size=i' => \$tabsize, |
---|
216 | 228 | 'root=s' => \$root, |
---|
217 | 229 | 'summary!' => \$summary, |
---|
218 | 230 | 'mailback!' => \$mailback, |
---|
.. | .. |
---|
228 | 240 | 'color=s' => \$color, |
---|
229 | 241 | 'no-color' => \$color, #keep old behaviors of -nocolor |
---|
230 | 242 | 'nocolor' => \$color, #keep old behaviors of -nocolor |
---|
| 243 | + 'kconfig-prefix=s' => \${CONFIG_}, |
---|
231 | 244 | 'h|help' => \$help, |
---|
232 | 245 | 'version' => \$help |
---|
233 | 246 | ) or help(1); |
---|
.. | .. |
---|
238 | 251 | |
---|
239 | 252 | $fix = 1 if ($fix_inplace); |
---|
240 | 253 | $check_orig = $check; |
---|
| 254 | + |
---|
| 255 | +die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); |
---|
241 | 256 | |
---|
242 | 257 | my $exit = 0; |
---|
243 | 258 | |
---|
.. | .. |
---|
262 | 277 | } elsif ($color =~ /^auto$/i) { |
---|
263 | 278 | $color = (-t STDOUT); |
---|
264 | 279 | } else { |
---|
265 | | - die "Invalid color mode: $color\n"; |
---|
| 280 | + die "$P: Invalid color mode: $color\n"; |
---|
266 | 281 | } |
---|
| 282 | + |
---|
| 283 | +# skip TAB size 1 to avoid additional checks on $tabsize - 1 |
---|
| 284 | +die "$P: Invalid TAB size: $tabsize\n" if ($tabsize < 2); |
---|
267 | 285 | |
---|
268 | 286 | sub hash_save_array_words { |
---|
269 | 287 | my ($hashRef, $arrayRef) = @_; |
---|
.. | .. |
---|
466 | 484 | seq_vprintf|seq_printf|seq_puts |
---|
467 | 485 | )}; |
---|
468 | 486 | |
---|
| 487 | +our $allocFunctions = qr{(?x: |
---|
| 488 | + (?:(?:devm_)? |
---|
| 489 | + (?:kv|k|v)[czm]alloc(?:_node|_array)? | |
---|
| 490 | + kstrdup(?:_const)? | |
---|
| 491 | + kmemdup(?:_nul)?) | |
---|
| 492 | + (?:\w+)?alloc_skb(?:_ip_align)? | |
---|
| 493 | + # dev_alloc_skb/netdev_alloc_skb, et al |
---|
| 494 | + dma_alloc_coherent |
---|
| 495 | +)}; |
---|
| 496 | + |
---|
469 | 497 | our $signature_tags = qr{(?xi: |
---|
470 | 498 | Signed-off-by:| |
---|
| 499 | + Co-developed-by:| |
---|
471 | 500 | Acked-by:| |
---|
472 | 501 | Tested-by:| |
---|
473 | 502 | Reviewed-by:| |
---|
.. | .. |
---|
565 | 594 | ["__ATTR", 2], |
---|
566 | 595 | ); |
---|
567 | 596 | |
---|
| 597 | +my $word_pattern = '\b[A-Z]?[a-z]{2,}\b'; |
---|
| 598 | + |
---|
568 | 599 | #Create a search pattern for all these functions to speed up a loop below |
---|
569 | 600 | our $mode_perms_search = ""; |
---|
570 | 601 | foreach my $entry (@mode_permission_funcs) { |
---|
.. | .. |
---|
572 | 603 | $mode_perms_search .= $entry->[0]; |
---|
573 | 604 | } |
---|
574 | 605 | $mode_perms_search = "(?:${mode_perms_search})"; |
---|
| 606 | + |
---|
| 607 | +our %deprecated_apis = ( |
---|
| 608 | + "synchronize_rcu_bh" => "synchronize_rcu", |
---|
| 609 | + "synchronize_rcu_bh_expedited" => "synchronize_rcu_expedited", |
---|
| 610 | + "call_rcu_bh" => "call_rcu", |
---|
| 611 | + "rcu_barrier_bh" => "rcu_barrier", |
---|
| 612 | + "synchronize_sched" => "synchronize_rcu", |
---|
| 613 | + "synchronize_sched_expedited" => "synchronize_rcu_expedited", |
---|
| 614 | + "call_rcu_sched" => "call_rcu", |
---|
| 615 | + "rcu_barrier_sched" => "rcu_barrier", |
---|
| 616 | + "get_state_synchronize_sched" => "get_state_synchronize_rcu", |
---|
| 617 | + "cond_synchronize_sched" => "cond_synchronize_rcu", |
---|
| 618 | +); |
---|
| 619 | + |
---|
| 620 | +#Create a search pattern for all these strings to speed up a loop below |
---|
| 621 | +our $deprecated_apis_search = ""; |
---|
| 622 | +foreach my $entry (keys %deprecated_apis) { |
---|
| 623 | + $deprecated_apis_search .= '|' if ($deprecated_apis_search ne ""); |
---|
| 624 | + $deprecated_apis_search .= $entry; |
---|
| 625 | +} |
---|
| 626 | +$deprecated_apis_search = "(?:${deprecated_apis_search})"; |
---|
575 | 627 | |
---|
576 | 628 | our $mode_perms_world_writable = qr{ |
---|
577 | 629 | S_IWUGO | |
---|
.. | .. |
---|
712 | 764 | next; |
---|
713 | 765 | } |
---|
714 | 766 | |
---|
715 | | - $$wordsRef .= '|' if ($$wordsRef ne ""); |
---|
| 767 | + $$wordsRef .= '|' if (defined $$wordsRef); |
---|
716 | 768 | $$wordsRef .= $line; |
---|
717 | 769 | } |
---|
718 | 770 | close($file); |
---|
.. | .. |
---|
722 | 774 | return 0; |
---|
723 | 775 | } |
---|
724 | 776 | |
---|
725 | | -my $const_structs = ""; |
---|
726 | | -read_words(\$const_structs, $conststructsfile) |
---|
727 | | - or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; |
---|
| 777 | +my $const_structs; |
---|
| 778 | +if (show_type("CONST_STRUCT")) { |
---|
| 779 | + read_words(\$const_structs, $conststructsfile) |
---|
| 780 | + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; |
---|
| 781 | +} |
---|
728 | 782 | |
---|
729 | | -my $typeOtherTypedefs = ""; |
---|
730 | | -if (length($typedefsfile)) { |
---|
| 783 | +if (defined($typedefsfile)) { |
---|
| 784 | + my $typeOtherTypedefs; |
---|
731 | 785 | read_words(\$typeOtherTypedefs, $typedefsfile) |
---|
732 | 786 | or warn "No additional types will be considered - file '$typedefsfile': $!\n"; |
---|
| 787 | + $typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs); |
---|
733 | 788 | } |
---|
734 | | -$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); |
---|
735 | 789 | |
---|
736 | 790 | sub build_types { |
---|
737 | 791 | my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; |
---|
.. | .. |
---|
770 | 824 | }x; |
---|
771 | 825 | $Type = qr{ |
---|
772 | 826 | $NonptrType |
---|
773 | | - (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? |
---|
| 827 | + (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4} |
---|
774 | 828 | (?:\s+$Inline|\s+$Modifier)* |
---|
775 | 829 | }x; |
---|
776 | 830 | $TypeMisordered = qr{ |
---|
777 | 831 | $NonptrTypeMisordered |
---|
778 | | - (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? |
---|
| 832 | + (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4} |
---|
779 | 833 | (?:\s+$Inline|\s+$Modifier)* |
---|
780 | 834 | }x; |
---|
781 | 835 | $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type}; |
---|
.. | .. |
---|
796 | 850 | our $declaration_macros = qr{(?x: |
---|
797 | 851 | (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(| |
---|
798 | 852 | (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(| |
---|
799 | | - (?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(| |
---|
800 | 853 | (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\( |
---|
801 | 854 | )}; |
---|
802 | 855 | |
---|
.. | .. |
---|
840 | 893 | } |
---|
841 | 894 | } |
---|
842 | 895 | |
---|
| 896 | +our %maintained_status = (); |
---|
| 897 | + |
---|
843 | 898 | sub is_maintained_obsolete { |
---|
844 | 899 | my ($filename) = @_; |
---|
845 | 900 | |
---|
846 | 901 | return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl")); |
---|
847 | 902 | |
---|
848 | | - my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`; |
---|
| 903 | + if (!exists($maintained_status{$filename})) { |
---|
| 904 | + $maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`; |
---|
| 905 | + } |
---|
849 | 906 | |
---|
850 | | - return $status =~ /obsolete/i; |
---|
| 907 | + return $maintained_status{$filename} =~ /obsolete/i; |
---|
851 | 908 | } |
---|
852 | 909 | |
---|
853 | 910 | sub is_SPDX_License_valid { |
---|
854 | 911 | my ($license) = @_; |
---|
855 | 912 | |
---|
856 | | - return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git")); |
---|
| 913 | + return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$gitroot")); |
---|
857 | 914 | |
---|
858 | 915 | my $root_path = abs_path($root); |
---|
859 | 916 | my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`; |
---|
.. | .. |
---|
871 | 928 | |
---|
872 | 929 | $camelcase_seeded = 1; |
---|
873 | 930 | |
---|
874 | | - if (-e ".git") { |
---|
875 | | - my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`; |
---|
| 931 | + if (-e "$gitroot") { |
---|
| 932 | + my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`; |
---|
876 | 933 | chomp $git_last_include_commit; |
---|
877 | 934 | $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit"; |
---|
878 | 935 | } else { |
---|
.. | .. |
---|
899 | 956 | return; |
---|
900 | 957 | } |
---|
901 | 958 | |
---|
902 | | - if (-e ".git") { |
---|
903 | | - $files = `git ls-files "include/*.h"`; |
---|
| 959 | + if (-e "$gitroot") { |
---|
| 960 | + $files = `${git_command} ls-files "include/*.h"`; |
---|
904 | 961 | @include_files = split('\n', $files); |
---|
905 | 962 | } |
---|
906 | 963 | |
---|
.. | .. |
---|
919 | 976 | } |
---|
920 | 977 | } |
---|
921 | 978 | |
---|
| 979 | +sub git_is_single_file { |
---|
| 980 | + my ($filename) = @_; |
---|
| 981 | + |
---|
| 982 | + return 0 if ((which("git") eq "") || !(-e "$gitroot")); |
---|
| 983 | + |
---|
| 984 | + my $output = `${git_command} ls-files -- $filename 2>/dev/null`; |
---|
| 985 | + my $count = $output =~ tr/\n//; |
---|
| 986 | + return $count eq 1 && $output =~ m{^${filename}$}; |
---|
| 987 | +} |
---|
| 988 | + |
---|
922 | 989 | sub git_commit_info { |
---|
923 | 990 | my ($commit, $id, $desc) = @_; |
---|
924 | 991 | |
---|
925 | | - return ($id, $desc) if ((which("git") eq "") || !(-e ".git")); |
---|
| 992 | + return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot")); |
---|
926 | 993 | |
---|
927 | | - my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`; |
---|
| 994 | + my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`; |
---|
928 | 995 | $output =~ s/^\s*//gm; |
---|
929 | 996 | my @lines = split("\n", $output); |
---|
930 | 997 | |
---|
931 | 998 | return ($id, $desc) if ($#lines < 0); |
---|
932 | 999 | |
---|
933 | | - if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { |
---|
| 1000 | + if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous/) { |
---|
934 | 1001 | # Maybe one day convert this block of bash into something that returns |
---|
935 | 1002 | # all matching commit ids, but it's very slow... |
---|
936 | 1003 | # |
---|
.. | .. |
---|
961 | 1028 | |
---|
962 | 1029 | # If input is git commits, extract all commits from the commit expressions. |
---|
963 | 1030 | # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'. |
---|
964 | | -die "$P: No git repository found\n" if ($git && !-e ".git"); |
---|
| 1031 | +die "$P: No git repository found\n" if ($git && !-e "$gitroot"); |
---|
965 | 1032 | |
---|
966 | 1033 | if ($git) { |
---|
967 | 1034 | my @commits = (); |
---|
.. | .. |
---|
974 | 1041 | } else { |
---|
975 | 1042 | $git_range = "-1 $commit_expr"; |
---|
976 | 1043 | } |
---|
977 | | - my $lines = `git log --no-color --no-merges --pretty=format:'%H %s' $git_range`; |
---|
| 1044 | + my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`; |
---|
978 | 1045 | foreach my $line (split(/\n/, $lines)) { |
---|
979 | 1046 | $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/; |
---|
980 | 1047 | next if (!defined($1) || !defined($2)); |
---|
.. | .. |
---|
989 | 1056 | } |
---|
990 | 1057 | |
---|
991 | 1058 | my $vname; |
---|
| 1059 | +$allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"}; |
---|
992 | 1060 | for my $filename (@ARGV) { |
---|
993 | 1061 | my $FILE; |
---|
| 1062 | + my $is_git_file = git_is_single_file($filename); |
---|
| 1063 | + my $oldfile = $file; |
---|
| 1064 | + $file = 1 if ($is_git_file); |
---|
994 | 1065 | if ($git) { |
---|
995 | 1066 | open($FILE, '-|', "git format-patch -M --stdout -1 $filename") || |
---|
996 | 1067 | die "$P: $filename: git format-patch failed - $!\n"; |
---|
.. | .. |
---|
1013 | 1084 | while (<$FILE>) { |
---|
1014 | 1085 | chomp; |
---|
1015 | 1086 | push(@rawlines, $_); |
---|
| 1087 | + $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i); |
---|
1016 | 1088 | } |
---|
1017 | 1089 | close($FILE); |
---|
1018 | 1090 | |
---|
.. | .. |
---|
1034 | 1106 | @modifierListFile = (); |
---|
1035 | 1107 | @typeListFile = (); |
---|
1036 | 1108 | build_types(); |
---|
| 1109 | + $file = $oldfile if ($is_git_file); |
---|
1037 | 1110 | } |
---|
1038 | 1111 | |
---|
1039 | 1112 | if (!$quiet) { |
---|
.. | .. |
---|
1079 | 1152 | my ($formatted_email) = @_; |
---|
1080 | 1153 | |
---|
1081 | 1154 | my $name = ""; |
---|
| 1155 | + my $name_comment = ""; |
---|
1082 | 1156 | my $address = ""; |
---|
1083 | 1157 | my $comment = ""; |
---|
1084 | 1158 | |
---|
.. | .. |
---|
1109 | 1183 | } |
---|
1110 | 1184 | } |
---|
1111 | 1185 | |
---|
| 1186 | + $comment = trim($comment); |
---|
1112 | 1187 | $name = trim($name); |
---|
1113 | 1188 | $name =~ s/^\"|\"$//g; |
---|
| 1189 | + if ($name =~ s/(\s*\([^\)]+\))\s*//) { |
---|
| 1190 | + $name_comment = trim($1); |
---|
| 1191 | + } |
---|
1114 | 1192 | $address = trim($address); |
---|
1115 | 1193 | $address =~ s/^\<|\>$//g; |
---|
1116 | 1194 | |
---|
.. | .. |
---|
1119 | 1197 | $name = "\"$name\""; |
---|
1120 | 1198 | } |
---|
1121 | 1199 | |
---|
1122 | | - return ($name, $address, $comment); |
---|
| 1200 | + return ($name, $name_comment, $address, $comment); |
---|
1123 | 1201 | } |
---|
1124 | 1202 | |
---|
1125 | 1203 | sub format_email { |
---|
1126 | | - my ($name, $address) = @_; |
---|
| 1204 | + my ($name, $name_comment, $address, $comment) = @_; |
---|
1127 | 1205 | |
---|
1128 | 1206 | my $formatted_email; |
---|
1129 | 1207 | |
---|
| 1208 | + $name_comment = trim($name_comment); |
---|
| 1209 | + $comment = trim($comment); |
---|
1130 | 1210 | $name = trim($name); |
---|
1131 | 1211 | $name =~ s/^\"|\"$//g; |
---|
1132 | 1212 | $address = trim($address); |
---|
.. | .. |
---|
1139 | 1219 | if ("$name" eq "") { |
---|
1140 | 1220 | $formatted_email = "$address"; |
---|
1141 | 1221 | } else { |
---|
1142 | | - $formatted_email = "$name <$address>"; |
---|
| 1222 | + $formatted_email = "$name$name_comment <$address>"; |
---|
1143 | 1223 | } |
---|
1144 | | - |
---|
| 1224 | + $formatted_email .= "$comment"; |
---|
1145 | 1225 | return $formatted_email; |
---|
| 1226 | +} |
---|
| 1227 | + |
---|
| 1228 | +sub reformat_email { |
---|
| 1229 | + my ($email) = @_; |
---|
| 1230 | + |
---|
| 1231 | + my ($email_name, $name_comment, $email_address, $comment) = parse_email($email); |
---|
| 1232 | + return format_email($email_name, $name_comment, $email_address, $comment); |
---|
| 1233 | +} |
---|
| 1234 | + |
---|
| 1235 | +sub same_email_addresses { |
---|
| 1236 | + my ($email1, $email2, $match_comment) = @_; |
---|
| 1237 | + |
---|
| 1238 | + my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1); |
---|
| 1239 | + my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2); |
---|
| 1240 | + |
---|
| 1241 | + if ($match_comment != 1) { |
---|
| 1242 | + return $email1_name eq $email2_name && |
---|
| 1243 | + $email1_address eq $email2_address; |
---|
| 1244 | + } |
---|
| 1245 | + return $email1_name eq $email2_name && |
---|
| 1246 | + $email1_address eq $email2_address && |
---|
| 1247 | + $name1_comment eq $name2_comment && |
---|
| 1248 | + $comment1 eq $comment2; |
---|
1146 | 1249 | } |
---|
1147 | 1250 | |
---|
1148 | 1251 | sub which { |
---|
.. | .. |
---|
1178 | 1281 | if ($c eq "\t") { |
---|
1179 | 1282 | $res .= ' '; |
---|
1180 | 1283 | $n++; |
---|
1181 | | - for (; ($n % 8) != 0; $n++) { |
---|
| 1284 | + for (; ($n % $tabsize) != 0; $n++) { |
---|
1182 | 1285 | $res .= ' '; |
---|
1183 | 1286 | } |
---|
1184 | 1287 | next; |
---|
.. | .. |
---|
1607 | 1710 | sub ctx_locate_comment { |
---|
1608 | 1711 | my ($first_line, $end_line) = @_; |
---|
1609 | 1712 | |
---|
| 1713 | + # If c99 comment on the current line, or the line before or after |
---|
| 1714 | + my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@); |
---|
| 1715 | + return $current_comment if (defined $current_comment); |
---|
| 1716 | + ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@); |
---|
| 1717 | + return $current_comment if (defined $current_comment); |
---|
| 1718 | + ($current_comment) = ($rawlines[$end_line] =~ m@^[\+ ].*(//.*$)@); |
---|
| 1719 | + return $current_comment if (defined $current_comment); |
---|
| 1720 | + |
---|
1610 | 1721 | # Catch a comment on the end of the line itself. |
---|
1611 | | - my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@); |
---|
| 1722 | + ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@); |
---|
1612 | 1723 | return $current_comment if (defined $current_comment); |
---|
1613 | 1724 | |
---|
1614 | 1725 | # Look through the context and try and figure out if there is a |
---|
.. | .. |
---|
2191 | 2302 | sub tabify { |
---|
2192 | 2303 | my ($leading) = @_; |
---|
2193 | 2304 | |
---|
2194 | | - my $source_indent = 8; |
---|
| 2305 | + my $source_indent = $tabsize; |
---|
2195 | 2306 | my $max_spaces_before_tab = $source_indent - 1; |
---|
2196 | 2307 | my $spaces_to_tab = " " x $source_indent; |
---|
2197 | 2308 | |
---|
.. | .. |
---|
2233 | 2344 | return length(expand_tabs(substr($line, 0, $last_openparen))) + 1; |
---|
2234 | 2345 | } |
---|
2235 | 2346 | |
---|
| 2347 | +sub get_raw_comment { |
---|
| 2348 | + my ($line, $rawline) = @_; |
---|
| 2349 | + my $comment = ''; |
---|
| 2350 | + |
---|
| 2351 | + for my $i (0 .. (length($line) - 1)) { |
---|
| 2352 | + if (substr($line, $i, 1) eq "$;") { |
---|
| 2353 | + $comment .= substr($rawline, $i, 1); |
---|
| 2354 | + } |
---|
| 2355 | + } |
---|
| 2356 | + |
---|
| 2357 | + return $comment; |
---|
| 2358 | +} |
---|
| 2359 | + |
---|
2236 | 2360 | sub process { |
---|
2237 | 2361 | my $filename = shift; |
---|
2238 | 2362 | |
---|
.. | .. |
---|
2251 | 2375 | my $signoff = 0; |
---|
2252 | 2376 | my $author = ''; |
---|
2253 | 2377 | my $authorsignoff = 0; |
---|
| 2378 | + my $author_sob = ''; |
---|
2254 | 2379 | my $is_patch = 0; |
---|
2255 | 2380 | my $is_binding_patch = -1; |
---|
2256 | 2381 | my $in_header_lines = $file ? 0 : 1; |
---|
2257 | 2382 | my $in_commit_log = 0; #Scanning lines before patch |
---|
| 2383 | + my $has_patch_separator = 0; #Found a --- line |
---|
2258 | 2384 | my $has_commit_log = 0; #Encountered lines before patch |
---|
2259 | 2385 | my $commit_log_lines = 0; #Number of commit log lines |
---|
2260 | 2386 | my $commit_log_possible_stack_dump = 0; |
---|
.. | .. |
---|
2313 | 2439 | |
---|
2314 | 2440 | if ($rawline=~/^\+\+\+\s+(\S+)/) { |
---|
2315 | 2441 | $setup_docs = 0; |
---|
2316 | | - if ($1 =~ m@Documentation/admin-guide/kernel-parameters.rst$@) { |
---|
| 2442 | + if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) { |
---|
2317 | 2443 | $setup_docs = 1; |
---|
2318 | 2444 | } |
---|
2319 | 2445 | #next; |
---|
.. | .. |
---|
2394 | 2520 | $sline =~ s/$;/ /g; #with comments as spaces |
---|
2395 | 2521 | |
---|
2396 | 2522 | my $rawline = $rawlines[$linenr - 1]; |
---|
| 2523 | + my $raw_comment = get_raw_comment($line, $rawline); |
---|
2397 | 2524 | |
---|
2398 | 2525 | # check if it's a mode change, rename or start of a patch |
---|
2399 | 2526 | if (!$in_commit_log && |
---|
.. | .. |
---|
2512 | 2639 | if (($last_binding_patch != -1) && |
---|
2513 | 2640 | ($last_binding_patch ^ $is_binding_patch)) { |
---|
2514 | 2641 | WARN("DT_SPLIT_BINDING_PATCH", |
---|
2515 | | - "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.txt\n"); |
---|
| 2642 | + "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n"); |
---|
2516 | 2643 | } |
---|
2517 | 2644 | } |
---|
2518 | 2645 | |
---|
.. | .. |
---|
2563 | 2690 | # Check the patch for a From: |
---|
2564 | 2691 | if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) { |
---|
2565 | 2692 | $author = $1; |
---|
| 2693 | + my $curline = $linenr; |
---|
| 2694 | + while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) { |
---|
| 2695 | + $author .= $1; |
---|
| 2696 | + } |
---|
2566 | 2697 | $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i); |
---|
2567 | 2698 | $author =~ s/"//g; |
---|
| 2699 | + $author = reformat_email($author); |
---|
2568 | 2700 | } |
---|
2569 | 2701 | |
---|
2570 | 2702 | # Check the patch for a signoff: |
---|
2571 | | - if ($line =~ /^\s*signed-off-by:/i) { |
---|
| 2703 | + if ($line =~ /^\s*signed-off-by:\s*(.*)/i) { |
---|
2572 | 2704 | $signoff++; |
---|
2573 | 2705 | $in_commit_log = 0; |
---|
2574 | | - if ($author ne '') { |
---|
2575 | | - my $l = $line; |
---|
2576 | | - $l =~ s/"//g; |
---|
2577 | | - if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) { |
---|
2578 | | - $authorsignoff = 1; |
---|
| 2706 | + if ($author ne '' && $authorsignoff != 1) { |
---|
| 2707 | + if (same_email_addresses($1, $author, 1)) { |
---|
| 2708 | + $authorsignoff = 1; |
---|
| 2709 | + } else { |
---|
| 2710 | + my $ctx = $1; |
---|
| 2711 | + my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx); |
---|
| 2712 | + my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author); |
---|
| 2713 | + |
---|
| 2714 | + if ($email_address eq $author_address && $email_name eq $author_name) { |
---|
| 2715 | + $author_sob = $ctx; |
---|
| 2716 | + $authorsignoff = 2; |
---|
| 2717 | + } elsif ($email_address eq $author_address) { |
---|
| 2718 | + $author_sob = $ctx; |
---|
| 2719 | + $authorsignoff = 3; |
---|
| 2720 | + } elsif ($email_name eq $author_name) { |
---|
| 2721 | + $author_sob = $ctx; |
---|
| 2722 | + $authorsignoff = 4; |
---|
| 2723 | + |
---|
| 2724 | + my $address1 = $email_address; |
---|
| 2725 | + my $address2 = $author_address; |
---|
| 2726 | + |
---|
| 2727 | + if ($address1 =~ /(\S+)\+\S+(\@.*)/) { |
---|
| 2728 | + $address1 = "$1$2"; |
---|
| 2729 | + } |
---|
| 2730 | + if ($address2 =~ /(\S+)\+\S+(\@.*)/) { |
---|
| 2731 | + $address2 = "$1$2"; |
---|
| 2732 | + } |
---|
| 2733 | + if ($address1 eq $address2) { |
---|
| 2734 | + $authorsignoff = 5; |
---|
| 2735 | + } |
---|
| 2736 | + } |
---|
2579 | 2737 | } |
---|
2580 | 2738 | } |
---|
| 2739 | + } |
---|
| 2740 | + |
---|
| 2741 | +# Check for patch separator |
---|
| 2742 | + if ($line =~ /^---$/) { |
---|
| 2743 | + $has_patch_separator = 1; |
---|
| 2744 | + $in_commit_log = 0; |
---|
2581 | 2745 | } |
---|
2582 | 2746 | |
---|
2583 | 2747 | # Check if MAINTAINERS is being updated. If so, there's probably no need to |
---|
.. | .. |
---|
2625 | 2789 | } |
---|
2626 | 2790 | } |
---|
2627 | 2791 | |
---|
2628 | | - my ($email_name, $email_address, $comment) = parse_email($email); |
---|
2629 | | - my $suggested_email = format_email(($email_name, $email_address)); |
---|
| 2792 | + my ($email_name, $name_comment, $email_address, $comment) = parse_email($email); |
---|
| 2793 | + my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment)); |
---|
2630 | 2794 | if ($suggested_email eq "") { |
---|
2631 | 2795 | ERROR("BAD_SIGN_OFF", |
---|
2632 | 2796 | "Unrecognized email address: '$email'\n" . $herecurr); |
---|
.. | .. |
---|
2636 | 2800 | $dequoted =~ s/" </ </; |
---|
2637 | 2801 | # Don't force email to have quotes |
---|
2638 | 2802 | # Allow just an angle bracketed address |
---|
2639 | | - if ("$dequoted$comment" ne $email && |
---|
2640 | | - "<$email_address>$comment" ne $email && |
---|
2641 | | - "$suggested_email$comment" ne $email) { |
---|
| 2803 | + if (!same_email_addresses($email, $suggested_email, 0)) { |
---|
2642 | 2804 | WARN("BAD_SIGN_OFF", |
---|
2643 | | - "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); |
---|
| 2805 | + "email address '$email' might be better as '$suggested_email'\n" . $herecurr); |
---|
2644 | 2806 | } |
---|
2645 | 2807 | } |
---|
2646 | 2808 | |
---|
.. | .. |
---|
2654 | 2816 | } else { |
---|
2655 | 2817 | $signatures{$sig_nospace} = 1; |
---|
2656 | 2818 | } |
---|
| 2819 | + |
---|
| 2820 | +# Check Co-developed-by: immediately followed by Signed-off-by: with same name and email |
---|
| 2821 | + if ($sign_off =~ /^co-developed-by:$/i) { |
---|
| 2822 | + if ($email eq $author) { |
---|
| 2823 | + WARN("BAD_SIGN_OFF", |
---|
| 2824 | + "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline); |
---|
| 2825 | + } |
---|
| 2826 | + if (!defined $lines[$linenr]) { |
---|
| 2827 | + WARN("BAD_SIGN_OFF", |
---|
| 2828 | + "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline); |
---|
| 2829 | + } elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) { |
---|
| 2830 | + WARN("BAD_SIGN_OFF", |
---|
| 2831 | + "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]); |
---|
| 2832 | + } elsif ($1 ne $email) { |
---|
| 2833 | + WARN("BAD_SIGN_OFF", |
---|
| 2834 | + "Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]); |
---|
| 2835 | + } |
---|
| 2836 | + } |
---|
2657 | 2837 | } |
---|
2658 | 2838 | |
---|
2659 | 2839 | # Check email subject for common tools that don't need to be mentioned |
---|
.. | .. |
---|
2663 | 2843 | "A patch subject line should describe the change not the tool that found it\n" . $herecurr); |
---|
2664 | 2844 | } |
---|
2665 | 2845 | |
---|
2666 | | -# Check for unwanted Gerrit info |
---|
2667 | | - if ($in_commit_log && $line =~ /^\s*change-id:/i) { |
---|
| 2846 | +# Check for Gerrit Change-Ids not in any patch context |
---|
| 2847 | + if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) { |
---|
2668 | 2848 | ERROR("GERRIT_CHANGE_ID", |
---|
2669 | | - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); |
---|
| 2849 | + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); |
---|
2670 | 2850 | } |
---|
2671 | 2851 | |
---|
2672 | 2852 | # Check if the commit log is in a possible stack dump |
---|
.. | .. |
---|
2674 | 2854 | ($line =~ /^\s*(?:WARNING:|BUG:)/ || |
---|
2675 | 2855 | $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ || |
---|
2676 | 2856 | # timestamp |
---|
2677 | | - $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/)) { |
---|
2678 | | - # stack dump address |
---|
| 2857 | + $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) || |
---|
| 2858 | + $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ || |
---|
| 2859 | + $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) { |
---|
| 2860 | + # stack dump address styles |
---|
2679 | 2861 | $commit_log_possible_stack_dump = 1; |
---|
2680 | 2862 | } |
---|
2681 | 2863 | |
---|
.. | .. |
---|
2702 | 2884 | |
---|
2703 | 2885 | # Check for git id commit length and improperly formed commit descriptions |
---|
2704 | 2886 | if ($in_commit_log && !$commit_log_possible_stack_dump && |
---|
2705 | | - $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink):/i && |
---|
| 2887 | + $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i && |
---|
2706 | 2888 | $line !~ /^This reverts commit [0-9a-f]{7,40}/ && |
---|
2707 | 2889 | ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || |
---|
2708 | 2890 | ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i && |
---|
.. | .. |
---|
2769 | 2951 | $reported_maintainer_file = 1; |
---|
2770 | 2952 | WARN("FILE_PATH_CHANGES", |
---|
2771 | 2953 | "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); |
---|
| 2954 | + } |
---|
| 2955 | + |
---|
| 2956 | +# Check for adding new DT bindings not in schema format |
---|
| 2957 | + if (!$in_commit_log && |
---|
| 2958 | + ($line =~ /^new file mode\s*\d+\s*$/) && |
---|
| 2959 | + ($realfile =~ m@^Documentation/devicetree/bindings/.*\.txt$@)) { |
---|
| 2960 | + WARN("DT_SCHEMA_BINDING_PATCH", |
---|
| 2961 | + "DT bindings should be in DT schema format. See: Documentation/devicetree/writing-schema.rst\n"); |
---|
2772 | 2962 | } |
---|
2773 | 2963 | |
---|
2774 | 2964 | # Check for wrappage within a valid hunk of the file |
---|
.. | .. |
---|
2847 | 3037 | } |
---|
2848 | 3038 | } |
---|
2849 | 3039 | |
---|
| 3040 | +# check for invalid commit id |
---|
| 3041 | + if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) { |
---|
| 3042 | + my $id; |
---|
| 3043 | + my $description; |
---|
| 3044 | + ($id, $description) = git_commit_info($2, undef, undef); |
---|
| 3045 | + if (!defined($id)) { |
---|
| 3046 | + WARN("UNKNOWN_COMMIT_ID", |
---|
| 3047 | + "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr); |
---|
| 3048 | + } |
---|
| 3049 | + } |
---|
| 3050 | + |
---|
| 3051 | +# check for repeated words separated by a single space |
---|
| 3052 | + if ($rawline =~ /^\+/ || $in_commit_log) { |
---|
| 3053 | + while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) { |
---|
| 3054 | + |
---|
| 3055 | + my $first = $1; |
---|
| 3056 | + my $second = $2; |
---|
| 3057 | + |
---|
| 3058 | + if ($first =~ /(?:struct|union|enum)/) { |
---|
| 3059 | + pos($rawline) += length($first) + length($second) + 1; |
---|
| 3060 | + next; |
---|
| 3061 | + } |
---|
| 3062 | + |
---|
| 3063 | + next if ($first ne $second); |
---|
| 3064 | + next if ($first eq 'long'); |
---|
| 3065 | + |
---|
| 3066 | + if (WARN("REPEATED_WORD", |
---|
| 3067 | + "Possible repeated word: '$first'\n" . $herecurr) && |
---|
| 3068 | + $fix) { |
---|
| 3069 | + $fixed[$fixlinenr] =~ s/\b$first $second\b/$first/; |
---|
| 3070 | + } |
---|
| 3071 | + } |
---|
| 3072 | + |
---|
| 3073 | + # if it's a repeated word on consecutive lines in a comment block |
---|
| 3074 | + if ($prevline =~ /$;+\s*$/ && |
---|
| 3075 | + $prevrawline =~ /($word_pattern)\s*$/) { |
---|
| 3076 | + my $last_word = $1; |
---|
| 3077 | + if ($rawline =~ /^\+\s*\*\s*$last_word /) { |
---|
| 3078 | + if (WARN("REPEATED_WORD", |
---|
| 3079 | + "Possible repeated word: '$last_word'\n" . $hereprev) && |
---|
| 3080 | + $fix) { |
---|
| 3081 | + $fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/; |
---|
| 3082 | + } |
---|
| 3083 | + } |
---|
| 3084 | + } |
---|
| 3085 | + } |
---|
| 3086 | + |
---|
2850 | 3087 | # ignore non-hunk lines and lines being removed |
---|
2851 | 3088 | next if (!$hunk_line || $line =~ /^-/); |
---|
2852 | 3089 | |
---|
.. | .. |
---|
2905 | 3142 | |
---|
2906 | 3143 | if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) { |
---|
2907 | 3144 | $is_start = 1; |
---|
2908 | | - } elsif ($lines[$ln - 1] =~ /^\+\s*(?:help|---help---)\s*$/) { |
---|
2909 | | - if ($lines[$ln - 1] =~ "---help---") { |
---|
2910 | | - WARN("CONFIG_DESCRIPTION", |
---|
2911 | | - "prefer 'help' over '---help---' for new help texts\n" . $herecurr); |
---|
2912 | | - } |
---|
| 3145 | + } elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) { |
---|
2913 | 3146 | $length = -1; |
---|
2914 | 3147 | } |
---|
2915 | 3148 | |
---|
.. | .. |
---|
2936 | 3169 | #print "is_start<$is_start> is_end<$is_end> length<$length>\n"; |
---|
2937 | 3170 | } |
---|
2938 | 3171 | |
---|
2939 | | -# check for MAINTAINERS entries that don't have the right form |
---|
2940 | | - if ($realfile =~ /^MAINTAINERS$/ && |
---|
2941 | | - $rawline =~ /^\+[A-Z]:/ && |
---|
2942 | | - $rawline !~ /^\+[A-Z]:\t\S/) { |
---|
2943 | | - if (WARN("MAINTAINERS_STYLE", |
---|
2944 | | - "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) && |
---|
2945 | | - $fix) { |
---|
2946 | | - $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/; |
---|
| 3172 | +# check MAINTAINERS entries |
---|
| 3173 | + if ($realfile =~ /^MAINTAINERS$/) { |
---|
| 3174 | +# check MAINTAINERS entries for the right form |
---|
| 3175 | + if ($rawline =~ /^\+[A-Z]:/ && |
---|
| 3176 | + $rawline !~ /^\+[A-Z]:\t\S/) { |
---|
| 3177 | + if (WARN("MAINTAINERS_STYLE", |
---|
| 3178 | + "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) && |
---|
| 3179 | + $fix) { |
---|
| 3180 | + $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/; |
---|
| 3181 | + } |
---|
| 3182 | + } |
---|
| 3183 | +# check MAINTAINERS entries for the right ordering too |
---|
| 3184 | + my $preferred_order = 'MRLSWQBCPTFXNK'; |
---|
| 3185 | + if ($rawline =~ /^\+[A-Z]:/ && |
---|
| 3186 | + $prevrawline =~ /^[\+ ][A-Z]:/) { |
---|
| 3187 | + $rawline =~ /^\+([A-Z]):\s*(.*)/; |
---|
| 3188 | + my $cur = $1; |
---|
| 3189 | + my $curval = $2; |
---|
| 3190 | + $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/; |
---|
| 3191 | + my $prev = $1; |
---|
| 3192 | + my $prevval = $2; |
---|
| 3193 | + my $curindex = index($preferred_order, $cur); |
---|
| 3194 | + my $previndex = index($preferred_order, $prev); |
---|
| 3195 | + if ($curindex < 0) { |
---|
| 3196 | + WARN("MAINTAINERS_STYLE", |
---|
| 3197 | + "Unknown MAINTAINERS entry type: '$cur'\n" . $herecurr); |
---|
| 3198 | + } else { |
---|
| 3199 | + if ($previndex >= 0 && $curindex < $previndex) { |
---|
| 3200 | + WARN("MAINTAINERS_STYLE", |
---|
| 3201 | + "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev); |
---|
| 3202 | + } elsif ((($prev eq 'F' && $cur eq 'F') || |
---|
| 3203 | + ($prev eq 'X' && $cur eq 'X')) && |
---|
| 3204 | + ($prevval cmp $curval) > 0) { |
---|
| 3205 | + WARN("MAINTAINERS_STYLE", |
---|
| 3206 | + "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev); |
---|
| 3207 | + } |
---|
| 3208 | + } |
---|
2947 | 3209 | } |
---|
2948 | 3210 | } |
---|
2949 | 3211 | |
---|
.. | .. |
---|
2976 | 3238 | my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g; |
---|
2977 | 3239 | |
---|
2978 | 3240 | my $dt_path = $root . "/Documentation/devicetree/bindings/"; |
---|
2979 | | - my $vp_file = $dt_path . "vendor-prefixes.txt"; |
---|
| 3241 | + my $vp_file = $dt_path . "vendor-prefixes.yaml"; |
---|
2980 | 3242 | |
---|
2981 | 3243 | foreach my $compat (@compats) { |
---|
2982 | 3244 | my $compat2 = $compat; |
---|
.. | .. |
---|
2991 | 3253 | |
---|
2992 | 3254 | next if $compat !~ /^([a-zA-Z0-9\-]+)\,/; |
---|
2993 | 3255 | my $vendor = $1; |
---|
2994 | | - `grep -Eq "^$vendor\\b" $vp_file`; |
---|
| 3256 | + `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`; |
---|
2995 | 3257 | if ( $? >> 8 ) { |
---|
2996 | 3258 | WARN("UNDOCUMENTED_DT_STRING", |
---|
2997 | 3259 | "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr); |
---|
.. | .. |
---|
3009 | 3271 | $comment = '/*'; |
---|
3010 | 3272 | } elsif ($realfile =~ /\.(c|dts|dtsi)$/) { |
---|
3011 | 3273 | $comment = '//'; |
---|
3012 | | - } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) { |
---|
| 3274 | + } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) { |
---|
3013 | 3275 | $comment = '#'; |
---|
3014 | 3276 | } elsif ($realfile =~ /\.rst$/) { |
---|
3015 | 3277 | $comment = '..'; |
---|
3016 | 3278 | } |
---|
3017 | 3279 | |
---|
| 3280 | +# check SPDX comment style for .[chsS] files |
---|
| 3281 | + if ($realfile =~ /\.[chsS]$/ && |
---|
| 3282 | + $rawline =~ /SPDX-License-Identifier:/ && |
---|
| 3283 | + $rawline !~ m@^\+\s*\Q$comment\E\s*@) { |
---|
| 3284 | + WARN("SPDX_LICENSE_TAG", |
---|
| 3285 | + "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr); |
---|
| 3286 | + } |
---|
| 3287 | + |
---|
3018 | 3288 | if ($comment !~ /^$/ && |
---|
3019 | | - $rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) { |
---|
3020 | | - WARN("SPDX_LICENSE_TAG", |
---|
3021 | | - "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr); |
---|
| 3289 | + $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) { |
---|
| 3290 | + WARN("SPDX_LICENSE_TAG", |
---|
| 3291 | + "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr); |
---|
3022 | 3292 | } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) { |
---|
3023 | | - my $spdx_license = $1; |
---|
3024 | | - if (!is_SPDX_License_valid($spdx_license)) { |
---|
3025 | | - WARN("SPDX_LICENSE_TAG", |
---|
3026 | | - "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr); |
---|
3027 | | - } |
---|
| 3293 | + my $spdx_license = $1; |
---|
| 3294 | + if (!is_SPDX_License_valid($spdx_license)) { |
---|
| 3295 | + WARN("SPDX_LICENSE_TAG", |
---|
| 3296 | + "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr); |
---|
| 3297 | + } |
---|
| 3298 | + if ($realfile =~ m@^Documentation/devicetree/bindings/@ && |
---|
| 3299 | + not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) { |
---|
| 3300 | + my $msg_level = \&WARN; |
---|
| 3301 | + $msg_level = \&CHK if ($file); |
---|
| 3302 | + if (&{$msg_level}("SPDX_LICENSE_TAG", |
---|
| 3303 | + |
---|
| 3304 | + "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) && |
---|
| 3305 | + $fix) { |
---|
| 3306 | + $fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/; |
---|
| 3307 | + } |
---|
| 3308 | + } |
---|
3028 | 3309 | } |
---|
3029 | 3310 | } |
---|
3030 | 3311 | } |
---|
3031 | 3312 | |
---|
| 3313 | +# check for embedded filenames |
---|
| 3314 | + if ($rawline =~ /^\+.*\Q$realfile\E/) { |
---|
| 3315 | + WARN("EMBEDDED_FILENAME", |
---|
| 3316 | + "It's generally not useful to have the filename in the file\n" . $herecurr); |
---|
| 3317 | + } |
---|
| 3318 | + |
---|
3032 | 3319 | # check we are in a valid source file if not then ignore this hunk |
---|
3033 | 3320 | next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/); |
---|
| 3321 | + |
---|
| 3322 | +# check for using SPDX-License-Identifier on the wrong line number |
---|
| 3323 | + if ($realline != $checklicenseline && |
---|
| 3324 | + $rawline =~ /\bSPDX-License-Identifier:/ && |
---|
| 3325 | + substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) { |
---|
| 3326 | + WARN("SPDX_LICENSE_TAG", |
---|
| 3327 | + "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr); |
---|
| 3328 | + } |
---|
3034 | 3329 | |
---|
3035 | 3330 | # line length limit (with some exclusions) |
---|
3036 | 3331 | # |
---|
.. | .. |
---|
3089 | 3384 | |
---|
3090 | 3385 | if ($msg_type ne "" && |
---|
3091 | 3386 | (show_type("LONG_LINE") || show_type($msg_type))) { |
---|
3092 | | - WARN($msg_type, |
---|
3093 | | - "line over $max_line_length characters\n" . $herecurr); |
---|
| 3387 | + my $msg_level = \&WARN; |
---|
| 3388 | + $msg_level = \&CHK if ($file); |
---|
| 3389 | + &{$msg_level}($msg_type, |
---|
| 3390 | + "line length of $length exceeds $max_line_length columns\n" . $herecurr); |
---|
3094 | 3391 | } |
---|
3095 | 3392 | } |
---|
3096 | 3393 | |
---|
.. | .. |
---|
3104 | 3401 | next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); |
---|
3105 | 3402 | |
---|
3106 | 3403 | # at the beginning of a line any tabs must come first and anything |
---|
3107 | | -# more than 8 must use tabs. |
---|
| 3404 | +# more than $tabsize must use tabs. |
---|
3108 | 3405 | if ($rawline =~ /^\+\s* \t\s*\S/ || |
---|
3109 | 3406 | $rawline =~ /^\+\s* \s*/) { |
---|
3110 | 3407 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
---|
.. | .. |
---|
3123 | 3420 | "please, no space before tabs\n" . $herevet) && |
---|
3124 | 3421 | $fix) { |
---|
3125 | 3422 | while ($fixed[$fixlinenr] =~ |
---|
3126 | | - s/(^\+.*) {8,8}\t/$1\t\t/) {} |
---|
| 3423 | + s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {} |
---|
3127 | 3424 | while ($fixed[$fixlinenr] =~ |
---|
3128 | 3425 | s/(^\+.*) +\t/$1\t/) {} |
---|
3129 | 3426 | } |
---|
.. | .. |
---|
3145 | 3442 | if ($perl_version_ok && |
---|
3146 | 3443 | $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) { |
---|
3147 | 3444 | my $indent = length($1); |
---|
3148 | | - if ($indent % 8) { |
---|
| 3445 | + if ($indent % $tabsize) { |
---|
3149 | 3446 | if (WARN("TABSTOP", |
---|
3150 | 3447 | "Statements should start on a tabstop\n" . $herecurr) && |
---|
3151 | 3448 | $fix) { |
---|
3152 | | - $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e; |
---|
| 3449 | + $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e; |
---|
3153 | 3450 | } |
---|
3154 | 3451 | } |
---|
3155 | 3452 | } |
---|
.. | .. |
---|
3167 | 3464 | my $newindent = $2; |
---|
3168 | 3465 | |
---|
3169 | 3466 | my $goodtabindent = $oldindent . |
---|
3170 | | - "\t" x ($pos / 8) . |
---|
3171 | | - " " x ($pos % 8); |
---|
| 3467 | + "\t" x ($pos / $tabsize) . |
---|
| 3468 | + " " x ($pos % $tabsize); |
---|
3172 | 3469 | my $goodspaceindent = $oldindent . " " x $pos; |
---|
3173 | 3470 | |
---|
3174 | 3471 | if ($newindent ne $goodtabindent && |
---|
.. | .. |
---|
3206 | 3503 | if ($realfile =~ m@^(drivers/net/|net/)@ && |
---|
3207 | 3504 | $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ && |
---|
3208 | 3505 | $rawline =~ /^\+[ \t]*\*/ && |
---|
3209 | | - $realline > 2) { |
---|
| 3506 | + $realline > 3) { # Do not warn about the initial copyright comment block after SPDX-License-Identifier |
---|
3210 | 3507 | WARN("NETWORKING_BLOCK_COMMENT_STYLE", |
---|
3211 | 3508 | "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); |
---|
3212 | 3509 | } |
---|
.. | .. |
---|
3639 | 3936 | #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n"; |
---|
3640 | 3937 | |
---|
3641 | 3938 | if ($check && $s ne '' && |
---|
3642 | | - (($sindent % 8) != 0 || |
---|
| 3939 | + (($sindent % $tabsize) != 0 || |
---|
3643 | 3940 | ($sindent < $indent) || |
---|
3644 | 3941 | ($sindent == $indent && |
---|
3645 | 3942 | ($s !~ /^\s*(?:\}|\{|else\b)/)) || |
---|
3646 | | - ($sindent > $indent + 8))) { |
---|
| 3943 | + ($sindent > $indent + $tabsize))) { |
---|
3647 | 3944 | WARN("SUSPECT_CODE_INDENT", |
---|
3648 | 3945 | "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); |
---|
3649 | 3946 | } |
---|
.. | .. |
---|
3664 | 3961 | |
---|
3665 | 3962 | #ignore lines not being added |
---|
3666 | 3963 | next if ($line =~ /^[^\+]/); |
---|
| 3964 | + |
---|
| 3965 | +# check for self assignments used to avoid compiler warnings |
---|
| 3966 | +# e.g.: int foo = foo, *bar = NULL; |
---|
| 3967 | +# struct foo bar = *(&(bar)); |
---|
| 3968 | + if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) { |
---|
| 3969 | + my $var = $1; |
---|
| 3970 | + if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) { |
---|
| 3971 | + WARN("SELF_ASSIGNMENT", |
---|
| 3972 | + "Do not use self-assignments to avoid compiler warnings\n" . $herecurr); |
---|
| 3973 | + } |
---|
| 3974 | + } |
---|
3667 | 3975 | |
---|
3668 | 3976 | # check for dereferences that span multiple lines |
---|
3669 | 3977 | if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ && |
---|
.. | .. |
---|
3869 | 4177 | WARN("STATIC_CONST_CHAR_ARRAY", |
---|
3870 | 4178 | "static const char * array should probably be static const char * const\n" . |
---|
3871 | 4179 | $herecurr); |
---|
3872 | | - } |
---|
| 4180 | + } |
---|
| 4181 | + |
---|
| 4182 | +# check for initialized const char arrays that should be static const |
---|
| 4183 | + if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) { |
---|
| 4184 | + if (WARN("STATIC_CONST_CHAR_ARRAY", |
---|
| 4185 | + "const array should probably be static const\n" . $herecurr) && |
---|
| 4186 | + $fix) { |
---|
| 4187 | + $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/; |
---|
| 4188 | + } |
---|
| 4189 | + } |
---|
3873 | 4190 | |
---|
3874 | 4191 | # check for static char foo[] = "bar" declarations. |
---|
3875 | 4192 | if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { |
---|
3876 | 4193 | WARN("STATIC_CONST_CHAR_ARRAY", |
---|
3877 | 4194 | "static char array declaration should probably be static const char\n" . |
---|
3878 | 4195 | $herecurr); |
---|
3879 | | - } |
---|
| 4196 | + } |
---|
3880 | 4197 | |
---|
3881 | 4198 | # check for const <foo> const where <foo> is not a pointer or array type |
---|
3882 | 4199 | if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { |
---|
.. | .. |
---|
3911 | 4228 | } |
---|
3912 | 4229 | |
---|
3913 | 4230 | # check for function declarations without arguments like "int foo()" |
---|
3914 | | - if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { |
---|
| 4231 | + if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) { |
---|
3915 | 4232 | if (ERROR("FUNCTION_WITHOUT_ARGS", |
---|
3916 | 4233 | "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) && |
---|
3917 | 4234 | $fix) { |
---|
.. | .. |
---|
4022 | 4339 | "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr); |
---|
4023 | 4340 | } |
---|
4024 | 4341 | |
---|
4025 | | - if ($line =~ /\bpr_warning\s*\(/) { |
---|
4026 | | - if (WARN("PREFER_PR_LEVEL", |
---|
4027 | | - "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) && |
---|
4028 | | - $fix) { |
---|
4029 | | - $fixed[$fixlinenr] =~ |
---|
4030 | | - s/\bpr_warning\b/pr_warn/; |
---|
4031 | | - } |
---|
4032 | | - } |
---|
4033 | | - |
---|
4034 | 4342 | if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) { |
---|
4035 | 4343 | my $orig = $1; |
---|
4036 | 4344 | my $level = lc($orig); |
---|
.. | .. |
---|
4040 | 4348 | "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr); |
---|
4041 | 4349 | } |
---|
4042 | 4350 | |
---|
| 4351 | +# trace_printk should not be used in production code. |
---|
| 4352 | + if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) { |
---|
| 4353 | + WARN("TRACE_PRINTK", |
---|
| 4354 | + "Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr); |
---|
| 4355 | + } |
---|
| 4356 | + |
---|
4043 | 4357 | # ENOSYS means "bad syscall nr" and nothing else. This will have a small |
---|
4044 | 4358 | # number of false positives, but assembly files are not checked, so at |
---|
4045 | 4359 | # least the arch entry code will not trigger this warning. |
---|
4046 | 4360 | if ($line =~ /\bENOSYS\b/) { |
---|
4047 | 4361 | WARN("ENOSYS", |
---|
4048 | 4362 | "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr); |
---|
| 4363 | + } |
---|
| 4364 | + |
---|
| 4365 | +# ENOTSUPP is not a standard error code and should be avoided in new patches. |
---|
| 4366 | +# Folks usually mean EOPNOTSUPP (also called ENOTSUP), when they type ENOTSUPP. |
---|
| 4367 | +# Similarly to ENOSYS warning a small number of false positives is expected. |
---|
| 4368 | + if (!$file && $line =~ /\bENOTSUPP\b/) { |
---|
| 4369 | + if (WARN("ENOTSUPP", |
---|
| 4370 | + "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP\n" . $herecurr) && |
---|
| 4371 | + $fix) { |
---|
| 4372 | + $fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/; |
---|
| 4373 | + } |
---|
4049 | 4374 | } |
---|
4050 | 4375 | |
---|
4051 | 4376 | # function brace can't be on same line, except for #defines of do while, |
---|
.. | .. |
---|
4488 | 4813 | ($op eq '>' && |
---|
4489 | 4814 | $ca =~ /<\S+\@\S+$/)) |
---|
4490 | 4815 | { |
---|
4491 | | - $ok = 1; |
---|
| 4816 | + $ok = 1; |
---|
4492 | 4817 | } |
---|
4493 | 4818 | |
---|
4494 | 4819 | # for asm volatile statements |
---|
.. | .. |
---|
4584 | 4909 | |
---|
4585 | 4910 | # closing brace should have a space following it when it has anything |
---|
4586 | 4911 | # on the line |
---|
4587 | | - if ($line =~ /}(?!(?:,|;|\)))\S/) { |
---|
| 4912 | + if ($line =~ /}(?!(?:,|;|\)|\}))\S/) { |
---|
4588 | 4913 | if (ERROR("SPACING", |
---|
4589 | 4914 | "space required after that close brace '}'\n" . $herecurr) && |
---|
4590 | 4915 | $fix) { |
---|
.. | .. |
---|
4693 | 5018 | $fixed[$fixlinenr] =~ |
---|
4694 | 5019 | s/^(.)\s+/$1/; |
---|
4695 | 5020 | } |
---|
| 5021 | + } |
---|
| 5022 | + |
---|
| 5023 | +# check if a statement with a comma should be two statements like: |
---|
| 5024 | +# foo = bar(), /* comma should be semicolon */ |
---|
| 5025 | +# bar = baz(); |
---|
| 5026 | + if (defined($stat) && |
---|
| 5027 | + $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) { |
---|
| 5028 | + my $cnt = statement_rawlines($stat); |
---|
| 5029 | + my $herectx = get_stat_here($linenr, $cnt, $here); |
---|
| 5030 | + WARN("SUSPECT_COMMA_SEMICOLON", |
---|
| 5031 | + "Possible comma where semicolon could be used\n" . $herectx); |
---|
4696 | 5032 | } |
---|
4697 | 5033 | |
---|
4698 | 5034 | # return is not a function |
---|
.. | .. |
---|
4815 | 5151 | my ($s, $c) = ($stat, $cond); |
---|
4816 | 5152 | |
---|
4817 | 5153 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { |
---|
4818 | | - ERROR("ASSIGN_IN_IF", |
---|
4819 | | - "do not use assignment in if condition\n" . $herecurr); |
---|
| 5154 | + if (ERROR("ASSIGN_IN_IF", |
---|
| 5155 | + "do not use assignment in if condition\n" . $herecurr) && |
---|
| 5156 | + $fix && $perl_version_ok) { |
---|
| 5157 | + if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) { |
---|
| 5158 | + my $space = $1; |
---|
| 5159 | + my $not = $2; |
---|
| 5160 | + my $statement = $3; |
---|
| 5161 | + my $assigned = $4; |
---|
| 5162 | + my $test = $8; |
---|
| 5163 | + my $against = $9; |
---|
| 5164 | + my $brace = $15; |
---|
| 5165 | + fix_delete_line($fixlinenr, $rawline); |
---|
| 5166 | + fix_insert_line($fixlinenr, "$space$statement;"); |
---|
| 5167 | + my $newline = "${space}if ("; |
---|
| 5168 | + $newline .= '!' if defined($not); |
---|
| 5169 | + $newline .= '(' if (defined $not && defined($test) && defined($against)); |
---|
| 5170 | + $newline .= "$assigned"; |
---|
| 5171 | + $newline .= " $test $against" if (defined($test) && defined($against)); |
---|
| 5172 | + $newline .= ')' if (defined $not && defined($test) && defined($against)); |
---|
| 5173 | + $newline .= ')'; |
---|
| 5174 | + $newline .= " {" if (defined($brace)); |
---|
| 5175 | + fix_insert_line($fixlinenr + 1, $newline); |
---|
| 5176 | + } |
---|
| 5177 | + } |
---|
4820 | 5178 | } |
---|
4821 | 5179 | |
---|
4822 | 5180 | # Find out what is on the end of the line after the |
---|
4823 | 5181 | # conditional. |
---|
4824 | 5182 | substr($s, 0, length($c), ''); |
---|
4825 | 5183 | $s =~ s/\n.*//g; |
---|
4826 | | - $s =~ s/$;//g; # Remove any comments |
---|
| 5184 | + $s =~ s/$;//g; # Remove any comments |
---|
4827 | 5185 | if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ && |
---|
4828 | 5186 | $c !~ /}\s*while\s*/) |
---|
4829 | 5187 | { |
---|
.. | .. |
---|
4862 | 5220 | # if and else should not have general statements after it |
---|
4863 | 5221 | if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { |
---|
4864 | 5222 | my $s = $1; |
---|
4865 | | - $s =~ s/$;//g; # Remove any comments |
---|
| 5223 | + $s =~ s/$;//g; # Remove any comments |
---|
4866 | 5224 | if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { |
---|
4867 | 5225 | ERROR("TRAILING_STATEMENTS", |
---|
4868 | 5226 | "trailing statements should be on next line\n" . $herecurr); |
---|
.. | .. |
---|
4934 | 5292 | while ($line =~ m{($Constant|$Lval)}g) { |
---|
4935 | 5293 | my $var = $1; |
---|
4936 | 5294 | |
---|
4937 | | -#gcc binary extension |
---|
4938 | | - if ($var =~ /^$Binary$/) { |
---|
4939 | | - if (WARN("GCC_BINARY_CONSTANT", |
---|
4940 | | - "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) && |
---|
4941 | | - $fix) { |
---|
4942 | | - my $hexval = sprintf("0x%x", oct($var)); |
---|
4943 | | - $fixed[$fixlinenr] =~ |
---|
4944 | | - s/\b$var\b/$hexval/; |
---|
4945 | | - } |
---|
4946 | | - } |
---|
4947 | | - |
---|
4948 | 5295 | #CamelCase |
---|
4949 | 5296 | if ($var !~ /^$Constant$/ && |
---|
4950 | 5297 | $var =~ /[A-Z][a-z]|[a-z][A-Z]/ && |
---|
4951 | 5298 | #Ignore Page<foo> variants |
---|
4952 | 5299 | $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && |
---|
4953 | | -#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) |
---|
4954 | | - $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ && |
---|
| 5300 | +#Ignore SI style variants like nS, mV and dB |
---|
| 5301 | +#(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE) |
---|
| 5302 | + $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ && |
---|
4955 | 5303 | #Ignore some three character SI units explicitly, like MiB and KHz |
---|
4956 | 5304 | $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) { |
---|
4957 | 5305 | while ($var =~ m{($Ident)}g) { |
---|
.. | .. |
---|
5042 | 5390 | $dstat =~ s/\s*$//s; |
---|
5043 | 5391 | |
---|
5044 | 5392 | # Flatten any parentheses and braces |
---|
5045 | | - while ($dstat =~ s/\([^\(\)]*\)/1/ || |
---|
5046 | | - $dstat =~ s/\{[^\{\}]*\}/1/ || |
---|
5047 | | - $dstat =~ s/.\[[^\[\]]*\]/1/) |
---|
| 5393 | + while ($dstat =~ s/\([^\(\)]*\)/1u/ || |
---|
| 5394 | + $dstat =~ s/\{[^\{\}]*\}/1u/ || |
---|
| 5395 | + $dstat =~ s/.\[[^\[\]]*\]/1u/) |
---|
5048 | 5396 | { |
---|
5049 | 5397 | } |
---|
5050 | 5398 | |
---|
5051 | | - # Flatten any obvious string concatentation. |
---|
| 5399 | + # Flatten any obvious string concatenation. |
---|
5052 | 5400 | while ($dstat =~ s/($String)\s*$Ident/$1/ || |
---|
5053 | 5401 | $dstat =~ s/$Ident\s*($String)/$1/) |
---|
5054 | 5402 | { |
---|
.. | .. |
---|
5085 | 5433 | $dstat !~ /^\.$Ident\s*=/ && # .foo = |
---|
5086 | 5434 | $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo |
---|
5087 | 5435 | $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...) |
---|
| 5436 | + $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...} |
---|
5088 | 5437 | $dstat !~ /^for\s*$Constant$/ && # for (...) |
---|
5089 | 5438 | $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar() |
---|
5090 | 5439 | $dstat !~ /^do\s*{/ && # do {... |
---|
.. | .. |
---|
5126 | 5475 | next if ($arg =~ /\.\.\./); |
---|
5127 | 5476 | next if ($arg =~ /^type$/i); |
---|
5128 | 5477 | my $tmp_stmt = $define_stmt; |
---|
5129 | | - $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; |
---|
| 5478 | + $tmp_stmt =~ s/\b(sizeof|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; |
---|
5130 | 5479 | $tmp_stmt =~ s/\#+\s*$arg\b//g; |
---|
5131 | 5480 | $tmp_stmt =~ s/\b$arg\s*\#\#//g; |
---|
5132 | 5481 | my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g; |
---|
.. | .. |
---|
5525 | 5874 | my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0); |
---|
5526 | 5875 | # print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n"); |
---|
5527 | 5876 | |
---|
5528 | | - if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*(?:devm_)?(?:[kv][czm]alloc(?:_node|_array)?\b|kstrdup|kmemdup|(?:dev_)?alloc_skb)/) { |
---|
| 5877 | + if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ && |
---|
| 5878 | + $s !~ /\b__GFP_NOWARN\b/ ) { |
---|
5529 | 5879 | WARN("OOM_MESSAGE", |
---|
5530 | 5880 | "Possible unnecessary 'out of memory' message\n" . $hereprev); |
---|
5531 | 5881 | } |
---|
.. | .. |
---|
5646 | 5996 | # ignore udelay's < 10, however |
---|
5647 | 5997 | if (! ($delay < 10) ) { |
---|
5648 | 5998 | CHK("USLEEP_RANGE", |
---|
5649 | | - "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr); |
---|
| 5999 | + "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr); |
---|
5650 | 6000 | } |
---|
5651 | 6001 | if ($delay > 2000) { |
---|
5652 | 6002 | WARN("LONG_UDELAY", |
---|
.. | .. |
---|
5658 | 6008 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { |
---|
5659 | 6009 | if ($1 < 20) { |
---|
5660 | 6010 | WARN("MSLEEP", |
---|
5661 | | - "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr); |
---|
| 6011 | + "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr); |
---|
5662 | 6012 | } |
---|
5663 | 6013 | } |
---|
5664 | 6014 | |
---|
.. | .. |
---|
5706 | 6056 | my $barriers = qr{ |
---|
5707 | 6057 | mb| |
---|
5708 | 6058 | rmb| |
---|
5709 | | - wmb| |
---|
5710 | | - read_barrier_depends |
---|
| 6059 | + wmb |
---|
5711 | 6060 | }x; |
---|
5712 | 6061 | my $barrier_stems = qr{ |
---|
5713 | 6062 | mb__before_atomic| |
---|
.. | .. |
---|
5748 | 6097 | } |
---|
5749 | 6098 | } |
---|
5750 | 6099 | |
---|
5751 | | -# check for smp_read_barrier_depends and read_barrier_depends |
---|
5752 | | - if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) { |
---|
5753 | | - WARN("READ_BARRIER_DEPENDS", |
---|
5754 | | - "$1read_barrier_depends should only be used in READ_ONCE or DEC Alpha code\n" . $herecurr); |
---|
| 6100 | +# check for data_race without a comment. |
---|
| 6101 | + if ($line =~ /\bdata_race\s*\(/) { |
---|
| 6102 | + if (!ctx_has_comment($first_line, $linenr)) { |
---|
| 6103 | + WARN("DATA_RACE", |
---|
| 6104 | + "data_race without comment\n" . $herecurr); |
---|
| 6105 | + } |
---|
5755 | 6106 | } |
---|
5756 | 6107 | |
---|
5757 | 6108 | # check of hardware specific defines |
---|
.. | .. |
---|
5805 | 6156 | $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { |
---|
5806 | 6157 | WARN("PREFER_ALIGNED", |
---|
5807 | 6158 | "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); |
---|
| 6159 | + } |
---|
| 6160 | + |
---|
| 6161 | +# Check for __attribute__ section, prefer __section |
---|
| 6162 | + if ($realfile !~ m@\binclude/uapi/@ && |
---|
| 6163 | + $line =~ /\b__attribute__\s*\(\s*\(.*_*section_*\s*\(\s*("[^"]*")/) { |
---|
| 6164 | + my $old = substr($rawline, $-[1], $+[1] - $-[1]); |
---|
| 6165 | + my $new = substr($old, 1, -1); |
---|
| 6166 | + if (WARN("PREFER_SECTION", |
---|
| 6167 | + "__section($new) is preferred over __attribute__((section($old)))\n" . $herecurr) && |
---|
| 6168 | + $fix) { |
---|
| 6169 | + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/; |
---|
| 6170 | + } |
---|
5808 | 6171 | } |
---|
5809 | 6172 | |
---|
5810 | 6173 | # Check for __attribute__ format(printf, prefer __printf |
---|
.. | .. |
---|
5922 | 6285 | for (my $count = $linenr; $count <= $lc; $count++) { |
---|
5923 | 6286 | my $specifier; |
---|
5924 | 6287 | my $extension; |
---|
| 6288 | + my $qualifier; |
---|
5925 | 6289 | my $bad_specifier = ""; |
---|
5926 | 6290 | my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0)); |
---|
5927 | 6291 | $fmt =~ s/%%//g; |
---|
5928 | 6292 | |
---|
5929 | | - while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) { |
---|
| 6293 | + while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*))/g) { |
---|
5930 | 6294 | $specifier = $1; |
---|
5931 | 6295 | $extension = $2; |
---|
5932 | | - if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) { |
---|
| 6296 | + $qualifier = $3; |
---|
| 6297 | + if ($extension !~ /[SsBKRraEehMmIiUDdgVCbGNOxtf]/ || |
---|
| 6298 | + ($extension eq "f" && |
---|
| 6299 | + defined $qualifier && $qualifier !~ /^w/)) { |
---|
5933 | 6300 | $bad_specifier = $specifier; |
---|
5934 | 6301 | last; |
---|
5935 | 6302 | } |
---|
.. | .. |
---|
5946 | 6313 | my $ext_type = "Invalid"; |
---|
5947 | 6314 | my $use = ""; |
---|
5948 | 6315 | if ($bad_specifier =~ /p[Ff]/) { |
---|
5949 | | - $ext_type = "Deprecated"; |
---|
5950 | 6316 | $use = " - use %pS instead"; |
---|
5951 | 6317 | $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/); |
---|
5952 | 6318 | } |
---|
.. | .. |
---|
6049 | 6415 | my $max = $7; |
---|
6050 | 6416 | if ($min eq $max) { |
---|
6051 | 6417 | WARN("USLEEP_RANGE", |
---|
6052 | | - "usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n"); |
---|
| 6418 | + "usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n"); |
---|
6053 | 6419 | } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ && |
---|
6054 | 6420 | $min > $max) { |
---|
6055 | 6421 | WARN("USLEEP_RANGE", |
---|
6056 | | - "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n"); |
---|
| 6422 | + "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n"); |
---|
6057 | 6423 | } |
---|
6058 | 6424 | } |
---|
6059 | 6425 | |
---|
.. | .. |
---|
6110 | 6476 | if (defined $cond) { |
---|
6111 | 6477 | substr($s, 0, length($cond), ''); |
---|
6112 | 6478 | } |
---|
6113 | | - if ($s =~ /^\s*;/ && |
---|
6114 | | - $function_name ne 'uninitialized_var') |
---|
| 6479 | + if ($s =~ /^\s*;/) |
---|
6115 | 6480 | { |
---|
6116 | 6481 | WARN("AVOID_EXTERNS", |
---|
6117 | 6482 | "externs should be avoided in .c files\n" . $herecurr); |
---|
.. | .. |
---|
6172 | 6537 | |
---|
6173 | 6538 | if (!grep(/$name/, @setup_docs)) { |
---|
6174 | 6539 | CHK("UNDOCUMENTED_SETUP", |
---|
6175 | | - "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.rst\n" . $herecurr); |
---|
| 6540 | + "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $herecurr); |
---|
6176 | 6541 | } |
---|
6177 | 6542 | } |
---|
6178 | 6543 | |
---|
6179 | | -# check for pointless casting of kmalloc return |
---|
6180 | | - if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { |
---|
| 6544 | +# check for pointless casting of alloc functions |
---|
| 6545 | + if ($line =~ /\*\s*\)\s*$allocFunctions\b/) { |
---|
6181 | 6546 | WARN("UNNECESSARY_CASTS", |
---|
6182 | 6547 | "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); |
---|
6183 | 6548 | } |
---|
.. | .. |
---|
6185 | 6550 | # alloc style |
---|
6186 | 6551 | # p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...) |
---|
6187 | 6552 | if ($perl_version_ok && |
---|
6188 | | - $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) { |
---|
| 6553 | + $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) { |
---|
6189 | 6554 | CHK("ALLOC_SIZEOF_STRUCT", |
---|
6190 | 6555 | "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); |
---|
6191 | 6556 | } |
---|
.. | .. |
---|
6254 | 6619 | } |
---|
6255 | 6620 | } |
---|
6256 | 6621 | |
---|
| 6622 | +# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too) |
---|
| 6623 | + if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) { |
---|
| 6624 | + WARN("IS_ENABLED_CONFIG", |
---|
| 6625 | + "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr); |
---|
| 6626 | + } |
---|
| 6627 | + |
---|
6257 | 6628 | # check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE |
---|
6258 | | - if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { |
---|
| 6629 | + if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { |
---|
6259 | 6630 | my $config = $1; |
---|
6260 | 6631 | if (WARN("PREFER_IS_ENABLED", |
---|
6261 | | - "Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) && |
---|
| 6632 | + "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) && |
---|
6262 | 6633 | $fix) { |
---|
6263 | 6634 | $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)"; |
---|
6264 | 6635 | } |
---|
6265 | 6636 | } |
---|
6266 | 6637 | |
---|
6267 | | -# check for case / default statements not preceded by break/fallthrough/switch |
---|
6268 | | - if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { |
---|
6269 | | - my $has_break = 0; |
---|
6270 | | - my $has_statement = 0; |
---|
6271 | | - my $count = 0; |
---|
6272 | | - my $prevline = $linenr; |
---|
6273 | | - while ($prevline > 1 && ($file || $count < 3) && !$has_break) { |
---|
6274 | | - $prevline--; |
---|
6275 | | - my $rline = $rawlines[$prevline - 1]; |
---|
6276 | | - my $fline = $lines[$prevline - 1]; |
---|
6277 | | - last if ($fline =~ /^\@\@/); |
---|
6278 | | - next if ($fline =~ /^\-/); |
---|
6279 | | - next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/); |
---|
6280 | | - $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i); |
---|
6281 | | - next if ($fline =~ /^.[\s$;]*$/); |
---|
6282 | | - $has_statement = 1; |
---|
6283 | | - $count++; |
---|
6284 | | - $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/); |
---|
6285 | | - } |
---|
6286 | | - if (!$has_break && $has_statement) { |
---|
6287 | | - WARN("MISSING_BREAK", |
---|
6288 | | - "Possible switch case/default not preceded by break or fallthrough comment\n" . $herecurr); |
---|
| 6638 | +# check for /* fallthrough */ like comment, prefer fallthrough; |
---|
| 6639 | + my @fallthroughs = ( |
---|
| 6640 | + 'fallthrough', |
---|
| 6641 | + '@fallthrough@', |
---|
| 6642 | + 'lint -fallthrough[ \t]*', |
---|
| 6643 | + 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)', |
---|
| 6644 | + '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?', |
---|
| 6645 | + 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', |
---|
| 6646 | + 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', |
---|
| 6647 | + ); |
---|
| 6648 | + if ($raw_comment ne '') { |
---|
| 6649 | + foreach my $ft (@fallthroughs) { |
---|
| 6650 | + if ($raw_comment =~ /$ft/) { |
---|
| 6651 | + my $msg_level = \&WARN; |
---|
| 6652 | + $msg_level = \&CHK if ($file); |
---|
| 6653 | + &{$msg_level}("PREFER_FALLTHROUGH", |
---|
| 6654 | + "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr); |
---|
| 6655 | + last; |
---|
| 6656 | + } |
---|
6289 | 6657 | } |
---|
6290 | 6658 | } |
---|
6291 | 6659 | |
---|
.. | .. |
---|
6348 | 6716 | } |
---|
6349 | 6717 | } |
---|
6350 | 6718 | |
---|
6351 | | -# check for bool bitfields |
---|
6352 | | - if ($sline =~ /^.\s+bool\s*$Ident\s*:\s*\d+\s*;/) { |
---|
6353 | | - WARN("BOOL_BITFIELD", |
---|
6354 | | - "Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>\n" . $herecurr); |
---|
6355 | | - } |
---|
6356 | | - |
---|
6357 | | -# check for bool use in .h files |
---|
6358 | | - if ($realfile =~ /\.h$/ && |
---|
6359 | | - $sline =~ /^.\s+bool\s*$Ident\s*(?::\s*d+\s*)?;/) { |
---|
6360 | | - CHK("BOOL_MEMBER", |
---|
6361 | | - "Avoid using bool structure members because of possible alignment issues - see: https://lkml.org/lkml/2017/11/21/384\n" . $herecurr); |
---|
6362 | | - } |
---|
6363 | | - |
---|
6364 | 6719 | # check for semaphores initialized locked |
---|
6365 | 6720 | if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { |
---|
6366 | 6721 | WARN("CONSIDER_COMPLETION", |
---|
.. | .. |
---|
6379 | 6734 | "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr); |
---|
6380 | 6735 | } |
---|
6381 | 6736 | |
---|
| 6737 | +# check for spin_is_locked(), suggest lockdep instead |
---|
| 6738 | + if ($line =~ /\bspin_is_locked\(/) { |
---|
| 6739 | + WARN("USE_LOCKDEP", |
---|
| 6740 | + "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr); |
---|
| 6741 | + } |
---|
| 6742 | + |
---|
| 6743 | +# check for deprecated apis |
---|
| 6744 | + if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) { |
---|
| 6745 | + my $deprecated_api = $1; |
---|
| 6746 | + my $new_api = $deprecated_apis{$deprecated_api}; |
---|
| 6747 | + WARN("DEPRECATED_API", |
---|
| 6748 | + "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr); |
---|
| 6749 | + } |
---|
| 6750 | + |
---|
6382 | 6751 | # check for various structs that are normally const (ops, kgdb, device_tree) |
---|
6383 | 6752 | # and avoid what seem like struct definitions 'struct foo {' |
---|
6384 | | - if ($line !~ /\bconst\b/ && |
---|
| 6753 | + if (defined($const_structs) && |
---|
| 6754 | + $line !~ /\bconst\b/ && |
---|
6385 | 6755 | $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { |
---|
6386 | 6756 | WARN("CONST_STRUCT", |
---|
6387 | 6757 | "struct $1 should normally be const\n" . $herecurr); |
---|
.. | .. |
---|
6411 | 6781 | $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) { |
---|
6412 | 6782 | WARN("LIKELY_MISUSE", |
---|
6413 | 6783 | "Using $1 should generally have parentheses around the comparison\n" . $herecurr); |
---|
| 6784 | + } |
---|
| 6785 | + |
---|
| 6786 | +# nested likely/unlikely calls |
---|
| 6787 | + if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) { |
---|
| 6788 | + WARN("LIKELY_MISUSE", |
---|
| 6789 | + "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr); |
---|
6414 | 6790 | } |
---|
6415 | 6791 | |
---|
6416 | 6792 | # whine mightly about in_atomic |
---|
.. | .. |
---|
6572 | 6948 | "unknown module license " . $extracted_string . "\n" . $herecurr); |
---|
6573 | 6949 | } |
---|
6574 | 6950 | } |
---|
| 6951 | + |
---|
| 6952 | +# check for sysctl duplicate constants |
---|
| 6953 | + if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) { |
---|
| 6954 | + WARN("DUPLICATED_SYSCTL_CONST", |
---|
| 6955 | + "duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr); |
---|
| 6956 | + } |
---|
6575 | 6957 | } |
---|
6576 | 6958 | |
---|
6577 | 6959 | # If we have no input at all, then there is nothing to report on |
---|
.. | .. |
---|
6600 | 6982 | if ($signoff == 0) { |
---|
6601 | 6983 | ERROR("MISSING_SIGN_OFF", |
---|
6602 | 6984 | "Missing Signed-off-by: line(s)\n"); |
---|
6603 | | - } elsif (!$authorsignoff) { |
---|
6604 | | - WARN("NO_AUTHOR_SIGN_OFF", |
---|
6605 | | - "Missing Signed-off-by: line by nominal patch author '$author'\n"); |
---|
| 6985 | + } elsif ($authorsignoff != 1) { |
---|
| 6986 | + # authorsignoff values: |
---|
| 6987 | + # 0 -> missing sign off |
---|
| 6988 | + # 1 -> sign off identical |
---|
| 6989 | + # 2 -> names and addresses match, comments mismatch |
---|
| 6990 | + # 3 -> addresses match, names different |
---|
| 6991 | + # 4 -> names match, addresses different |
---|
| 6992 | + # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match |
---|
| 6993 | + |
---|
| 6994 | + my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'"; |
---|
| 6995 | + |
---|
| 6996 | + if ($authorsignoff == 0) { |
---|
| 6997 | + ERROR("NO_AUTHOR_SIGN_OFF", |
---|
| 6998 | + "Missing Signed-off-by: line by nominal patch author '$author'\n"); |
---|
| 6999 | + } elsif ($authorsignoff == 2) { |
---|
| 7000 | + CHK("FROM_SIGN_OFF_MISMATCH", |
---|
| 7001 | + "From:/Signed-off-by: email comments mismatch: $sob_msg\n"); |
---|
| 7002 | + } elsif ($authorsignoff == 3) { |
---|
| 7003 | + WARN("FROM_SIGN_OFF_MISMATCH", |
---|
| 7004 | + "From:/Signed-off-by: email name mismatch: $sob_msg\n"); |
---|
| 7005 | + } elsif ($authorsignoff == 4) { |
---|
| 7006 | + WARN("FROM_SIGN_OFF_MISMATCH", |
---|
| 7007 | + "From:/Signed-off-by: email address mismatch: $sob_msg\n"); |
---|
| 7008 | + } elsif ($authorsignoff == 5) { |
---|
| 7009 | + WARN("FROM_SIGN_OFF_MISMATCH", |
---|
| 7010 | + "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n"); |
---|
| 7011 | + } |
---|
6606 | 7012 | } |
---|
6607 | 7013 | } |
---|
6608 | 7014 | |
---|