Skip to content

Commit e795556

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: improve MULTISTATEMENT_MACRO_USE_DO_WHILE test
The logic currrently misses macros that start with an if statement. e.g.: #define foo(bar) if (bar) baz; Add a test for macro content that starts with if Link: http://lkml.kernel.org/r/a9d41aafe1673889caf1a9850208fb7fd74107a0.1491783914.git.joe@perches.com Signed-off-by: Joe Perches <joe@perches.com> Reported-by: Andreas Mohr <andi@lisas.de> Original-patch-by: Alfonso Lima <alfonsolimaastor@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d9190e4 commit e795556

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

scripts/checkpatch.pl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4849,8 +4849,10 @@ sub process {
48494849
$dstat !~ /^\(\{/ && # ({...
48504850
$ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
48514851
{
4852-
4853-
if ($dstat =~ /;/) {
4852+
if ($dstat =~ /^\s*if\b/) {
4853+
ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
4854+
"Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx");
4855+
} elsif ($dstat =~ /;/) {
48544856
ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
48554857
"Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
48564858
} else {

0 commit comments

Comments
 (0)