From: Joe Perches Date: Mon, 8 May 2017 22:55:48 +0000 (-0700) Subject: checkpatch: improve MULTISTATEMENT_MACRO_USE_DO_WHILE test X-Git-Tag: v4.12-rc1~67^2~88 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e795556a581a849bf33b22521bf8ebc97ab899ea;p=uclinux-h8%2Flinux.git 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 Reported-by: Andreas Mohr Original-patch-by: Alfonso Lima Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3a1cb9d7474e..feb9e856f11d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4849,8 +4849,10 @@ sub process { $dstat !~ /^\(\{/ && # ({... $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) { - - if ($dstat =~ /;/) { + if ($dstat =~ /^\s*if\b/) { + ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", + "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx"); + } elsif ($dstat =~ /;/) { ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx"); } else {