Skip to content

Commit 9192d41

Browse files
JoePerchestorvalds
authored andcommitted
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>
1 parent f59b64b commit 9192d41

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

scripts/checkpatch.pl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4836,7 +4836,7 @@ sub process {
48364836
# check if any macro arguments are reused (ignore '...' and 'type')
48374837
foreach my $arg (@def_args) {
48384838
next if ($arg =~ /\.\.\./);
4839-
next if ($arg =~ /^type$/);
4839+
next if ($arg =~ /^type$/i);
48404840
my $tmp = $define_stmt;
48414841
$tmp =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
48424842
$tmp =~ s/\#\s*$arg\b//g;
@@ -4845,6 +4845,13 @@ sub process {
48454845
if ($use_cnt > 1) {
48464846
CHK("MACRO_ARG_REUSE",
48474847
"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");
48484855
}
48494856
}
48504857

0 commit comments

Comments
 (0)