diff options
author | Jerome Forissier <jerome.forissier@linaro.org> | 2017-05-08 18:56:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-08 20:15:11 -0400 |
commit | 75ad8c575a5ad105e2afc2051c68abceb9c65431 (patch) | |
tree | ec4e9454fd744e9003337c16ce8a68b747a36f43 /scripts | |
parent | 1b4a2ed4c8773524cc7890c4cd57d58b39c049eb (diff) |
checkpatch: add --typedefsfile
When using checkpatch on out-of-tree code, it may occur that some
project-specific types are used, which will cause spurious warnings.
Add the --typedefsfile option as a way to extend the known types and
deal with this issue.
This was developed for OP-TEE [1]. We run a Travis job on all pull
requests [2], and checkpatch is part of that. The typical false warning
we get on a regular basis is with some pointers to functions returning
TEE_Result [3], which is a typedef from the GlobalPlatform APIs. We
consider it is acceptable to use GP types in the OP-TEE core
implementation, that's why this patch would be helpful for us.
[1] https://github.com/OP-TEE/optee_os
[2] https://travis-ci.org/OP-TEE/optee_os/builds
[3] https://travis-ci.org/OP-TEE/optee_os/builds/193355335#L1733
Link: http://lkml.kernel.org/r/ba1124d6dfa599bb0dd1d8919dd45dd09ce541a4.1492702192.git.jerome.forissier@linaro.org
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d2c074feaa7d..65bb50076632 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -55,6 +55,7 @@ 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 $conststructsfile = "$D/const_structs.checkpatch"; |
58 | my $typedefsfile = ""; | ||
58 | my $color = 1; | 59 | my $color = 1; |
59 | my $allow_c99_comments = 1; | 60 | my $allow_c99_comments = 1; |
60 | 61 | ||
@@ -113,6 +114,7 @@ Options: | |||
113 | --codespell Use the codespell dictionary for spelling/typos | 114 | --codespell Use the codespell dictionary for spelling/typos |
114 | (default:/usr/share/codespell/dictionary.txt) | 115 | (default:/usr/share/codespell/dictionary.txt) |
115 | --codespellfile Use this codespell dictionary | 116 | --codespellfile Use this codespell dictionary |
117 | --typedefsfile Read additional types from this file | ||
116 | --color Use colors when output is STDOUT (default: on) | 118 | --color Use colors when output is STDOUT (default: on) |
117 | -h, --help, --version display this help and exit | 119 | -h, --help, --version display this help and exit |
118 | 120 | ||
@@ -208,6 +210,7 @@ GetOptions( | |||
208 | 'test-only=s' => \$tst_only, | 210 | 'test-only=s' => \$tst_only, |
209 | 'codespell!' => \$codespell, | 211 | 'codespell!' => \$codespell, |
210 | 'codespellfile=s' => \$codespellfile, | 212 | 'codespellfile=s' => \$codespellfile, |
213 | 'typedefsfile=s' => \$typedefsfile, | ||
211 | 'color!' => \$color, | 214 | 'color!' => \$color, |
212 | 'h|help' => \$help, | 215 | 'h|help' => \$help, |
213 | 'version' => \$help | 216 | 'version' => \$help |
@@ -629,28 +632,43 @@ if ($codespell) { | |||
629 | 632 | ||
630 | $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; | 633 | $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; |
631 | 634 | ||
632 | my $const_structs = ""; | 635 | sub read_words { |
633 | if (open(my $conststructs, '<', $conststructsfile)) { | 636 | my ($wordsRef, $file) = @_; |
634 | while (<$conststructs>) { | ||
635 | my $line = $_; | ||
636 | 637 | ||
637 | $line =~ s/\s*\n?$//g; | 638 | if (open(my $words, '<', $file)) { |
638 | $line =~ s/^\s*//g; | 639 | while (<$words>) { |
640 | my $line = $_; | ||
639 | 641 | ||
640 | next if ($line =~ m/^\s*#/); | 642 | $line =~ s/\s*\n?$//g; |
641 | next if ($line =~ m/^\s*$/); | 643 | $line =~ s/^\s*//g; |
642 | if ($line =~ /\s/) { | ||
643 | print("$conststructsfile: '$line' invalid - ignored\n"); | ||
644 | next; | ||
645 | } | ||
646 | 644 | ||
647 | $const_structs .= '|' if ($const_structs ne ""); | 645 | next if ($line =~ m/^\s*#/); |
648 | $const_structs .= $line; | 646 | next if ($line =~ m/^\s*$/); |
647 | if ($line =~ /\s/) { | ||
648 | print("$file: '$line' invalid - ignored\n"); | ||
649 | next; | ||
650 | } | ||
651 | |||
652 | $$wordsRef .= '|' if ($$wordsRef ne ""); | ||
653 | $$wordsRef .= $line; | ||
654 | } | ||
655 | close($file); | ||
656 | return 1; | ||
649 | } | 657 | } |
650 | close($conststructsfile); | 658 | |
651 | } else { | 659 | return 0; |
652 | warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; | 660 | } |
661 | |||
662 | my $const_structs = ""; | ||
663 | read_words(\$const_structs, $conststructsfile) | ||
664 | or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; | ||
665 | |||
666 | my $typeOtherTypedefs = ""; | ||
667 | if (length($typedefsfile)) { | ||
668 | read_words(\$typeOtherTypedefs, $typedefsfile) | ||
669 | or warn "No additional types will be considered - file '$typedefsfile': $!\n"; | ||
653 | } | 670 | } |
671 | $typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); | ||
654 | 672 | ||
655 | sub build_types { | 673 | sub build_types { |
656 | my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; | 674 | my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; |