aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2016-10-11 16:52:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-11 18:06:30 -0400
commit9192d41a3f0b98844860f1de5b82f729bbe07c61 (patch)
tree5e8f6680b5b5d6b577cd15ee9d07773825584d30 /scripts
parentf59b64bffe163431b4ec61f3b00c1aeb846948f3 (diff)
checkpatch: add --strict test for precedence challenged macro arguments
Add a test for macro arguents that have a non-comma leading or trailing operator where the argument isn't parenthesized to avoid possible precedence issues. Link: http://lkml.kernel.org/r/47715508972f8d786f435e583ff881dbeee3a114.1473745855.git.joe@perches.com Signed-off-by: Joe Perches <joe@perches.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: Julia Lawall <julia.lawall@lip6.fr> Cc: Dan Carpenter <dan.carpenter@oracle.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-xscripts/checkpatch.pl9
1 files changed, 8 insertions, 1 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f135f8e4d069..ea1a7adce406 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4836,7 +4836,7 @@ sub process {
4836# check if any macro arguments are reused (ignore '...' and 'type') 4836# check if any macro arguments are reused (ignore '...' and 'type')
4837 foreach my $arg (@def_args) { 4837 foreach my $arg (@def_args) {
4838 next if ($arg =~ /\.\.\./); 4838 next if ($arg =~ /\.\.\./);
4839 next if ($arg =~ /^type$/); 4839 next if ($arg =~ /^type$/i);
4840 my $tmp = $define_stmt; 4840 my $tmp = $define_stmt;
4841 $tmp =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; 4841 $tmp =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
4842 $tmp =~ s/\#\s*$arg\b//g; 4842 $tmp =~ s/\#\s*$arg\b//g;
@@ -4845,6 +4845,13 @@ sub process {
4845 if ($use_cnt > 1) { 4845 if ($use_cnt > 1) {
4846 CHK("MACRO_ARG_REUSE", 4846 CHK("MACRO_ARG_REUSE",
4847 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx"); 4847 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
4848 }
4849# check if any macro arguments may have other precedence issues
4850 if ($define_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
4851 ((defined($1) && $1 ne ',') ||
4852 (defined($2) && $2 ne ','))) {
4853 CHK("MACRO_ARG_PRECEDENCE",
4854 "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx");
4848 } 4855 }
4849 } 4856 }
4850 4857