diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 338 |
1 files changed, 245 insertions, 93 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 206a6b346a8d..a8368d1c4348 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -54,6 +54,7 @@ my $min_conf_desc_length = 4; | |||
54 | my $spelling_file = "$D/spelling.txt"; | 54 | my $spelling_file = "$D/spelling.txt"; |
55 | my $codespell = 0; | 55 | my $codespell = 0; |
56 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; | 56 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; |
57 | my $conststructsfile = "$D/const_structs.checkpatch"; | ||
57 | my $color = 1; | 58 | my $color = 1; |
58 | my $allow_c99_comments = 1; | 59 | my $allow_c99_comments = 1; |
59 | 60 | ||
@@ -523,7 +524,11 @@ our @mode_permission_funcs = ( | |||
523 | ["module_param_array_named", 5], | 524 | ["module_param_array_named", 5], |
524 | ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2], | 525 | ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2], |
525 | ["proc_create(?:_data|)", 2], | 526 | ["proc_create(?:_data|)", 2], |
526 | ["(?:CLASS|DEVICE|SENSOR)_ATTR", 2], | 527 | ["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2], |
528 | ["IIO_DEV_ATTR_[A-Z_]+", 1], | ||
529 | ["SENSOR_(?:DEVICE_|)ATTR_2", 2], | ||
530 | ["SENSOR_TEMPLATE(?:_2|)", 3], | ||
531 | ["__ATTR", 2], | ||
527 | ); | 532 | ); |
528 | 533 | ||
529 | #Create a search pattern for all these functions to speed up a loop below | 534 | #Create a search pattern for all these functions to speed up a loop below |
@@ -541,6 +546,32 @@ our $mode_perms_world_writable = qr{ | |||
541 | 0[0-7][0-7][2367] | 546 | 0[0-7][0-7][2367] |
542 | }x; | 547 | }x; |
543 | 548 | ||
549 | our %mode_permission_string_types = ( | ||
550 | "S_IRWXU" => 0700, | ||
551 | "S_IRUSR" => 0400, | ||
552 | "S_IWUSR" => 0200, | ||
553 | "S_IXUSR" => 0100, | ||
554 | "S_IRWXG" => 0070, | ||
555 | "S_IRGRP" => 0040, | ||
556 | "S_IWGRP" => 0020, | ||
557 | "S_IXGRP" => 0010, | ||
558 | "S_IRWXO" => 0007, | ||
559 | "S_IROTH" => 0004, | ||
560 | "S_IWOTH" => 0002, | ||
561 | "S_IXOTH" => 0001, | ||
562 | "S_IRWXUGO" => 0777, | ||
563 | "S_IRUGO" => 0444, | ||
564 | "S_IWUGO" => 0222, | ||
565 | "S_IXUGO" => 0111, | ||
566 | ); | ||
567 | |||
568 | #Create a search pattern for all these strings to speed up a loop below | ||
569 | our $mode_perms_string_search = ""; | ||
570 | foreach my $entry (keys %mode_permission_string_types) { | ||
571 | $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); | ||
572 | $mode_perms_string_search .= $entry; | ||
573 | } | ||
574 | |||
544 | our $allowed_asm_includes = qr{(?x: | 575 | our $allowed_asm_includes = qr{(?x: |
545 | irq| | 576 | irq| |
546 | memory| | 577 | memory| |
@@ -598,6 +629,29 @@ if ($codespell) { | |||
598 | 629 | ||
599 | $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; | 630 | $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; |
600 | 631 | ||
632 | my $const_structs = ""; | ||
633 | if (open(my $conststructs, '<', $conststructsfile)) { | ||
634 | while (<$conststructs>) { | ||
635 | my $line = $_; | ||
636 | |||
637 | $line =~ s/\s*\n?$//g; | ||
638 | $line =~ s/^\s*//g; | ||
639 | |||
640 | next if ($line =~ m/^\s*#/); | ||
641 | next if ($line =~ m/^\s*$/); | ||
642 | if ($line =~ /\s/) { | ||
643 | print("$conststructsfile: '$line' invalid - ignored\n"); | ||
644 | next; | ||
645 | } | ||
646 | |||
647 | $const_structs .= '|' if ($const_structs ne ""); | ||
648 | $const_structs .= $line; | ||
649 | } | ||
650 | close($conststructsfile); | ||
651 | } else { | ||
652 | warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; | ||
653 | } | ||
654 | |||
601 | sub build_types { | 655 | sub build_types { |
602 | my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; | 656 | my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; |
603 | my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)"; | 657 | my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)"; |
@@ -704,6 +758,16 @@ sub seed_camelcase_file { | |||
704 | } | 758 | } |
705 | } | 759 | } |
706 | 760 | ||
761 | sub is_maintained_obsolete { | ||
762 | my ($filename) = @_; | ||
763 | |||
764 | return 0 if (!(-e "$root/scripts/get_maintainer.pl")); | ||
765 | |||
766 | my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`; | ||
767 | |||
768 | return $status =~ /obsolete/i; | ||
769 | } | ||
770 | |||
707 | my $camelcase_seeded = 0; | 771 | my $camelcase_seeded = 0; |
708 | sub seed_camelcase_includes { | 772 | sub seed_camelcase_includes { |
709 | return if ($camelcase_seeded); | 773 | return if ($camelcase_seeded); |
@@ -2289,6 +2353,10 @@ sub process { | |||
2289 | } | 2353 | } |
2290 | 2354 | ||
2291 | if ($found_file) { | 2355 | if ($found_file) { |
2356 | if (is_maintained_obsolete($realfile)) { | ||
2357 | WARN("OBSOLETE", | ||
2358 | "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy. No unnecessary modifications please.\n"); | ||
2359 | } | ||
2292 | if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) { | 2360 | if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) { |
2293 | $check = 1; | 2361 | $check = 1; |
2294 | } else { | 2362 | } else { |
@@ -2939,6 +3007,30 @@ sub process { | |||
2939 | "Block comments use a trailing */ on a separate line\n" . $herecurr); | 3007 | "Block comments use a trailing */ on a separate line\n" . $herecurr); |
2940 | } | 3008 | } |
2941 | 3009 | ||
3010 | # Block comment * alignment | ||
3011 | if ($prevline =~ /$;[ \t]*$/ && #ends in comment | ||
3012 | $line =~ /^\+[ \t]*$;/ && #leading comment | ||
3013 | $rawline =~ /^\+[ \t]*\*/ && #leading * | ||
3014 | (($prevrawline =~ /^\+.*?\/\*/ && #leading /* | ||
3015 | $prevrawline !~ /\*\/[ \t]*$/) || #no trailing */ | ||
3016 | $prevrawline =~ /^\+[ \t]*\*/)) { #leading * | ||
3017 | my $oldindent; | ||
3018 | $prevrawline =~ m@^\+([ \t]*/?)\*@; | ||
3019 | if (defined($1)) { | ||
3020 | $oldindent = expand_tabs($1); | ||
3021 | } else { | ||
3022 | $prevrawline =~ m@^\+(.*/?)\*@; | ||
3023 | $oldindent = expand_tabs($1); | ||
3024 | } | ||
3025 | $rawline =~ m@^\+([ \t]*)\*@; | ||
3026 | my $newindent = $1; | ||
3027 | $newindent = expand_tabs($newindent); | ||
3028 | if (length($oldindent) ne length($newindent)) { | ||
3029 | WARN("BLOCK_COMMENT_STYLE", | ||
3030 | "Block comments should align the * on each line\n" . $hereprev); | ||
3031 | } | ||
3032 | } | ||
3033 | |||
2942 | # check for missing blank lines after struct/union declarations | 3034 | # check for missing blank lines after struct/union declarations |
2943 | # with exceptions for various attributes and macros | 3035 | # with exceptions for various attributes and macros |
2944 | if ($prevline =~ /^[\+ ]};?\s*$/ && | 3036 | if ($prevline =~ /^[\+ ]};?\s*$/ && |
@@ -4665,7 +4757,17 @@ sub process { | |||
4665 | $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/); | 4757 | $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/); |
4666 | $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/); | 4758 | $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/); |
4667 | 4759 | ||
4668 | $dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//; | 4760 | $dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//; |
4761 | my $define_args = $1; | ||
4762 | my $define_stmt = $dstat; | ||
4763 | my @def_args = (); | ||
4764 | |||
4765 | if (defined $define_args && $define_args ne "") { | ||
4766 | $define_args = substr($define_args, 1, length($define_args) - 2); | ||
4767 | $define_args =~ s/\s*//g; | ||
4768 | @def_args = split(",", $define_args); | ||
4769 | } | ||
4770 | |||
4669 | $dstat =~ s/$;//g; | 4771 | $dstat =~ s/$;//g; |
4670 | $dstat =~ s/\\\n.//g; | 4772 | $dstat =~ s/\\\n.//g; |
4671 | $dstat =~ s/^\s*//s; | 4773 | $dstat =~ s/^\s*//s; |
@@ -4701,6 +4803,15 @@ sub process { | |||
4701 | ^\[ | 4803 | ^\[ |
4702 | }x; | 4804 | }x; |
4703 | #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; | 4805 | #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; |
4806 | |||
4807 | $ctx =~ s/\n*$//; | ||
4808 | my $herectx = $here . "\n"; | ||
4809 | my $stmt_cnt = statement_rawlines($ctx); | ||
4810 | |||
4811 | for (my $n = 0; $n < $stmt_cnt; $n++) { | ||
4812 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
4813 | } | ||
4814 | |||
4704 | if ($dstat ne '' && | 4815 | if ($dstat ne '' && |
4705 | $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), | 4816 | $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), |
4706 | $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo(); | 4817 | $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo(); |
@@ -4716,13 +4827,6 @@ sub process { | |||
4716 | $dstat !~ /^\(\{/ && # ({... | 4827 | $dstat !~ /^\(\{/ && # ({... |
4717 | $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) | 4828 | $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) |
4718 | { | 4829 | { |
4719 | $ctx =~ s/\n*$//; | ||
4720 | my $herectx = $here . "\n"; | ||
4721 | my $cnt = statement_rawlines($ctx); | ||
4722 | |||
4723 | for (my $n = 0; $n < $cnt; $n++) { | ||
4724 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
4725 | } | ||
4726 | 4830 | ||
4727 | if ($dstat =~ /;/) { | 4831 | if ($dstat =~ /;/) { |
4728 | ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", | 4832 | ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", |
@@ -4731,6 +4835,46 @@ sub process { | |||
4731 | ERROR("COMPLEX_MACRO", | 4835 | ERROR("COMPLEX_MACRO", |
4732 | "Macros with complex values should be enclosed in parentheses\n" . "$herectx"); | 4836 | "Macros with complex values should be enclosed in parentheses\n" . "$herectx"); |
4733 | } | 4837 | } |
4838 | |||
4839 | } | ||
4840 | |||
4841 | # Make $define_stmt single line, comment-free, etc | ||
4842 | my @stmt_array = split('\n', $define_stmt); | ||
4843 | my $first = 1; | ||
4844 | $define_stmt = ""; | ||
4845 | foreach my $l (@stmt_array) { | ||
4846 | $l =~ s/\\$//; | ||
4847 | if ($first) { | ||
4848 | $define_stmt = $l; | ||
4849 | $first = 0; | ||
4850 | } elsif ($l =~ /^[\+ ]/) { | ||
4851 | $define_stmt .= substr($l, 1); | ||
4852 | } | ||
4853 | } | ||
4854 | $define_stmt =~ s/$;//g; | ||
4855 | $define_stmt =~ s/\s+/ /g; | ||
4856 | $define_stmt = trim($define_stmt); | ||
4857 | |||
4858 | # check if any macro arguments are reused (ignore '...' and 'type') | ||
4859 | foreach my $arg (@def_args) { | ||
4860 | next if ($arg =~ /\.\.\./); | ||
4861 | next if ($arg =~ /^type$/i); | ||
4862 | my $tmp = $define_stmt; | ||
4863 | $tmp =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; | ||
4864 | $tmp =~ s/\#+\s*$arg\b//g; | ||
4865 | $tmp =~ s/\b$arg\s*\#\#//g; | ||
4866 | my $use_cnt = $tmp =~ s/\b$arg\b//g; | ||
4867 | if ($use_cnt > 1) { | ||
4868 | CHK("MACRO_ARG_REUSE", | ||
4869 | "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx"); | ||
4870 | } | ||
4871 | # check if any macro arguments may have other precedence issues | ||
4872 | if ($define_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m && | ||
4873 | ((defined($1) && $1 ne ',') || | ||
4874 | (defined($2) && $2 ne ','))) { | ||
4875 | CHK("MACRO_ARG_PRECEDENCE", | ||
4876 | "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx"); | ||
4877 | } | ||
4734 | } | 4878 | } |
4735 | 4879 | ||
4736 | # check for macros with flow control, but without ## concatenation | 4880 | # check for macros with flow control, but without ## concatenation |
@@ -5495,46 +5639,46 @@ sub process { | |||
5495 | } | 5639 | } |
5496 | 5640 | ||
5497 | # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar) | 5641 | # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar) |
5498 | if ($^V && $^V ge 5.10.0 && | 5642 | # if ($^V && $^V ge 5.10.0 && |
5499 | defined $stat && | 5643 | # defined $stat && |
5500 | $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { | 5644 | # $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { |
5501 | if (WARN("PREFER_ETHER_ADDR_COPY", | 5645 | # if (WARN("PREFER_ETHER_ADDR_COPY", |
5502 | "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") && | 5646 | # "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") && |
5503 | $fix) { | 5647 | # $fix) { |
5504 | $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/; | 5648 | # $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/; |
5505 | } | 5649 | # } |
5506 | } | 5650 | # } |
5507 | 5651 | ||
5508 | # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar) | 5652 | # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar) |
5509 | if ($^V && $^V ge 5.10.0 && | 5653 | # if ($^V && $^V ge 5.10.0 && |
5510 | defined $stat && | 5654 | # defined $stat && |
5511 | $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { | 5655 | # $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { |
5512 | WARN("PREFER_ETHER_ADDR_EQUAL", | 5656 | # WARN("PREFER_ETHER_ADDR_EQUAL", |
5513 | "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n") | 5657 | # "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n") |
5514 | } | 5658 | # } |
5515 | 5659 | ||
5516 | # check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr | 5660 | # check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr |
5517 | # check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr | 5661 | # check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr |
5518 | if ($^V && $^V ge 5.10.0 && | 5662 | # if ($^V && $^V ge 5.10.0 && |
5519 | defined $stat && | 5663 | # defined $stat && |
5520 | $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { | 5664 | # $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { |
5521 | 5665 | # | |
5522 | my $ms_val = $7; | 5666 | # my $ms_val = $7; |
5523 | 5667 | # | |
5524 | if ($ms_val =~ /^(?:0x|)0+$/i) { | 5668 | # if ($ms_val =~ /^(?:0x|)0+$/i) { |
5525 | if (WARN("PREFER_ETH_ZERO_ADDR", | 5669 | # if (WARN("PREFER_ETH_ZERO_ADDR", |
5526 | "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") && | 5670 | # "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") && |
5527 | $fix) { | 5671 | # $fix) { |
5528 | $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/; | 5672 | # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/; |
5529 | } | 5673 | # } |
5530 | } elsif ($ms_val =~ /^(?:0xff|255)$/i) { | 5674 | # } elsif ($ms_val =~ /^(?:0xff|255)$/i) { |
5531 | if (WARN("PREFER_ETH_BROADCAST_ADDR", | 5675 | # if (WARN("PREFER_ETH_BROADCAST_ADDR", |
5532 | "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") && | 5676 | # "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") && |
5533 | $fix) { | 5677 | # $fix) { |
5534 | $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/; | 5678 | # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/; |
5535 | } | 5679 | # } |
5536 | } | 5680 | # } |
5537 | } | 5681 | # } |
5538 | 5682 | ||
5539 | # typecasts on min/max could be min_t/max_t | 5683 | # typecasts on min/max could be min_t/max_t |
5540 | if ($^V && $^V ge 5.10.0 && | 5684 | if ($^V && $^V ge 5.10.0 && |
@@ -5654,6 +5798,19 @@ sub process { | |||
5654 | "externs should be avoided in .c files\n" . $herecurr); | 5798 | "externs should be avoided in .c files\n" . $herecurr); |
5655 | } | 5799 | } |
5656 | 5800 | ||
5801 | if ($realfile =~ /\.[ch]$/ && defined $stat && | ||
5802 | $stat =~ /^.\s*(?:extern\s+)?$Type\s*$Ident\s*\(\s*([^{]+)\s*\)\s*;/s && | ||
5803 | $1 ne "void") { | ||
5804 | my $args = trim($1); | ||
5805 | while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) { | ||
5806 | my $arg = trim($1); | ||
5807 | if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) { | ||
5808 | WARN("FUNCTION_ARGUMENTS", | ||
5809 | "function definition argument '$arg' should also have an identifier name\n" . $herecurr); | ||
5810 | } | ||
5811 | } | ||
5812 | } | ||
5813 | |||
5657 | # checks for new __setup's | 5814 | # checks for new __setup's |
5658 | if ($rawline =~ /\b__setup\("([^"]*)"/) { | 5815 | if ($rawline =~ /\b__setup\("([^"]*)"/) { |
5659 | my $name = $1; | 5816 | my $name = $1; |
@@ -5853,46 +6010,6 @@ sub process { | |||
5853 | } | 6010 | } |
5854 | 6011 | ||
5855 | # check for various structs that are normally const (ops, kgdb, device_tree) | 6012 | # check for various structs that are normally const (ops, kgdb, device_tree) |
5856 | my $const_structs = qr{ | ||
5857 | acpi_dock_ops| | ||
5858 | address_space_operations| | ||
5859 | backlight_ops| | ||
5860 | block_device_operations| | ||
5861 | dentry_operations| | ||
5862 | dev_pm_ops| | ||
5863 | dma_map_ops| | ||
5864 | extent_io_ops| | ||
5865 | file_lock_operations| | ||
5866 | file_operations| | ||
5867 | hv_ops| | ||
5868 | ide_dma_ops| | ||
5869 | intel_dvo_dev_ops| | ||
5870 | item_operations| | ||
5871 | iwl_ops| | ||
5872 | kgdb_arch| | ||
5873 | kgdb_io| | ||
5874 | kset_uevent_ops| | ||
5875 | lock_manager_operations| | ||
5876 | microcode_ops| | ||
5877 | mtrr_ops| | ||
5878 | neigh_ops| | ||
5879 | nlmsvc_binding| | ||
5880 | of_device_id| | ||
5881 | pci_raw_ops| | ||
5882 | pipe_buf_operations| | ||
5883 | platform_hibernation_ops| | ||
5884 | platform_suspend_ops| | ||
5885 | proto_ops| | ||
5886 | rpc_pipe_ops| | ||
5887 | seq_operations| | ||
5888 | snd_ac97_build_ops| | ||
5889 | soc_pcmcia_socket_ops| | ||
5890 | stacktrace_ops| | ||
5891 | sysfs_ops| | ||
5892 | tty_operations| | ||
5893 | uart_ops| | ||
5894 | usb_mon_operations| | ||
5895 | wd_ops}x; | ||
5896 | if ($line !~ /\bconst\b/ && | 6013 | if ($line !~ /\bconst\b/ && |
5897 | $line =~ /\bstruct\s+($const_structs)\b/) { | 6014 | $line =~ /\bstruct\s+($const_structs)\b/) { |
5898 | WARN("CONST_STRUCT", | 6015 | WARN("CONST_STRUCT", |
@@ -5979,34 +6096,69 @@ sub process { | |||
5979 | # Mode permission misuses where it seems decimal should be octal | 6096 | # Mode permission misuses where it seems decimal should be octal |
5980 | # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop | 6097 | # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop |
5981 | if ($^V && $^V ge 5.10.0 && | 6098 | if ($^V && $^V ge 5.10.0 && |
6099 | defined $stat && | ||
5982 | $line =~ /$mode_perms_search/) { | 6100 | $line =~ /$mode_perms_search/) { |
5983 | foreach my $entry (@mode_permission_funcs) { | 6101 | foreach my $entry (@mode_permission_funcs) { |
5984 | my $func = $entry->[0]; | 6102 | my $func = $entry->[0]; |
5985 | my $arg_pos = $entry->[1]; | 6103 | my $arg_pos = $entry->[1]; |
5986 | 6104 | ||
6105 | my $lc = $stat =~ tr@\n@@; | ||
6106 | $lc = $lc + $linenr; | ||
6107 | my $stat_real = raw_line($linenr, 0); | ||
6108 | for (my $count = $linenr + 1; $count <= $lc; $count++) { | ||
6109 | $stat_real = $stat_real . "\n" . raw_line($count, 0); | ||
6110 | } | ||
6111 | |||
5987 | my $skip_args = ""; | 6112 | my $skip_args = ""; |
5988 | if ($arg_pos > 1) { | 6113 | if ($arg_pos > 1) { |
5989 | $arg_pos--; | 6114 | $arg_pos--; |
5990 | $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}"; | 6115 | $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}"; |
5991 | } | 6116 | } |
5992 | my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]"; | 6117 | my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]"; |
5993 | if ($line =~ /$test/) { | 6118 | if ($stat =~ /$test/) { |
5994 | my $val = $1; | 6119 | my $val = $1; |
5995 | $val = $6 if ($skip_args ne ""); | 6120 | $val = $6 if ($skip_args ne ""); |
5996 | 6121 | if (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || | |
5997 | if ($val !~ /^0$/ && | 6122 | ($val =~ /^$Octal$/ && length($val) ne 4)) { |
5998 | (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || | ||
5999 | length($val) ne 4)) { | ||
6000 | ERROR("NON_OCTAL_PERMISSIONS", | 6123 | ERROR("NON_OCTAL_PERMISSIONS", |
6001 | "Use 4 digit octal (0777) not decimal permissions\n" . $herecurr); | 6124 | "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real); |
6002 | } elsif ($val =~ /^$Octal$/ && (oct($val) & 02)) { | 6125 | } |
6126 | if ($val =~ /^$Octal$/ && (oct($val) & 02)) { | ||
6003 | ERROR("EXPORTED_WORLD_WRITABLE", | 6127 | ERROR("EXPORTED_WORLD_WRITABLE", |
6004 | "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); | 6128 | "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\n" . $stat_real); |
6005 | } | 6129 | } |
6006 | } | 6130 | } |
6007 | } | 6131 | } |
6008 | } | 6132 | } |
6009 | 6133 | ||
6134 | # check for uses of S_<PERMS> that could be octal for readability | ||
6135 | if ($line =~ /\b$mode_perms_string_search\b/) { | ||
6136 | my $val = ""; | ||
6137 | my $oval = ""; | ||
6138 | my $to = 0; | ||
6139 | my $curpos = 0; | ||
6140 | my $lastpos = 0; | ||
6141 | while ($line =~ /\b(($mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) { | ||
6142 | $curpos = pos($line); | ||
6143 | my $match = $2; | ||
6144 | my $omatch = $1; | ||
6145 | last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); | ||
6146 | $lastpos = $curpos; | ||
6147 | $to |= $mode_permission_string_types{$match}; | ||
6148 | $val .= '\s*\|\s*' if ($val ne ""); | ||
6149 | $val .= $match; | ||
6150 | $oval .= $omatch; | ||
6151 | } | ||
6152 | $oval =~ s/^\s*\|\s*//; | ||
6153 | $oval =~ s/\s*\|\s*$//; | ||
6154 | my $octal = sprintf("%04o", $to); | ||
6155 | if (WARN("SYMBOLIC_PERMS", | ||
6156 | "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) && | ||
6157 | $fix) { | ||
6158 | $fixed[$fixlinenr] =~ s/$val/$octal/; | ||
6159 | } | ||
6160 | } | ||
6161 | |||
6010 | # validate content of MODULE_LICENSE against list from include/linux/module.h | 6162 | # validate content of MODULE_LICENSE against list from include/linux/module.h |
6011 | if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { | 6163 | if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { |
6012 | my $extracted_string = get_quoted_string($line, $rawline); | 6164 | my $extracted_string = get_quoted_string($line, $rawline); |