diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0c520f7bf095..7a360a8c1b91 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -4066,12 +4066,17 @@ sub process { | |||
4066 | my $cnt = $realcnt; | 4066 | my $cnt = $realcnt; |
4067 | my ($off, $dstat, $dcond, $rest); | 4067 | my ($off, $dstat, $dcond, $rest); |
4068 | my $ctx = ''; | 4068 | my $ctx = ''; |
4069 | my $has_flow_statement = 0; | ||
4070 | my $has_arg_concat = 0; | ||
4069 | ($dstat, $dcond, $ln, $cnt, $off) = | 4071 | ($dstat, $dcond, $ln, $cnt, $off) = |
4070 | ctx_statement_block($linenr, $realcnt, 0); | 4072 | ctx_statement_block($linenr, $realcnt, 0); |
4071 | $ctx = $dstat; | 4073 | $ctx = $dstat; |
4072 | #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n"; | 4074 | #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n"; |
4073 | #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n"; | 4075 | #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n"; |
4074 | 4076 | ||
4077 | $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/); | ||
4078 | $has_arg_concat = 1 if ($ctx =~ /\#\#/); | ||
4079 | |||
4075 | $dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//; | 4080 | $dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//; |
4076 | $dstat =~ s/$;//g; | 4081 | $dstat =~ s/$;//g; |
4077 | $dstat =~ s/\\\n.//g; | 4082 | $dstat =~ s/\\\n.//g; |
@@ -4136,6 +4141,19 @@ sub process { | |||
4136 | } | 4141 | } |
4137 | } | 4142 | } |
4138 | 4143 | ||
4144 | # check for macros with flow control, but without ## concatenation | ||
4145 | # ## concatenation is commonly a macro that defines a function so ignore those | ||
4146 | if ($has_flow_statement && !$has_arg_concat) { | ||
4147 | my $herectx = $here . "\n"; | ||
4148 | my $cnt = statement_rawlines($ctx); | ||
4149 | |||
4150 | for (my $n = 0; $n < $cnt; $n++) { | ||
4151 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
4152 | } | ||
4153 | WARN("MACRO_WITH_FLOW_CONTROL", | ||
4154 | "Macros with flow control statements should be avoided\n" . "$herectx"); | ||
4155 | } | ||
4156 | |||
4139 | # check for line continuations outside of #defines, preprocessor #, and asm | 4157 | # check for line continuations outside of #defines, preprocessor #, and asm |
4140 | 4158 | ||
4141 | } else { | 4159 | } else { |