Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1619527 > unrolled thread

[PATCH V2] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test

Started byJoe Perches <joe@perches.com>
First post2017-04-09 20:00 +0200
Last post2017-04-10 02:30 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH V2] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test Joe Perches <joe@perches.com> - 2017-04-09 20:00 +0200
    [PATCH V3] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test Joe Perches <joe@perches.com> - 2017-04-10 02:30 +0200

#1619527 — [PATCH V2] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test

FromJoe Perches <joe@perches.com>
Date2017-04-09 20:00 +0200
Subject[PATCH V2] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test
Message-ID<tupi2-67V-1@gated-at.bofh.it>
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

Original-patch-by: Alfonso Lima <alfonsolimaastor@gmail.com>
Reported-by: Andreas Mohr <andi@lisas.de>
Signed-off-by: Joe Perches <joe@perches.com>
---

V2: V1 was done incorrectly against a much older version of checkpatch
    and so rolled back several improvements.
    I forgot I had used git checkout <commit_id> -- scripts/checkpatch.pl
    and then edited that.

 scripts/checkpatch.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e8d8481b24c8..2468ed01b333 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 {
-- 
2.10.0.rc2.1.g053435c

[toc] | [next] | [standalone]


#1619577 — [PATCH V3] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test

FromJoe Perches <joe@perches.com>
Date2017-04-10 02:30 +0200
Subject[PATCH V3] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test
Message-ID<tuvns-1IR-3@gated-at.bofh.it>
In reply to#1619527
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

Original-patch-by: Alfonso Lima <alfonsolimaastor@gmail.com>
Reported-by: Andreas Mohr <andi@lisas.de>
Signed-off-by: Joe Perches <joe@perches.com>
---

V3: Fix bad merge - Add missing closing brace
V2: V1 was done incorrectly against a much older version of checkpatch
    and so rolled back several improvements.
    I forgot I had used git checkout <commit_id> -- scripts/checkpatch.pl
    and then edited that.

 scripts/checkpatch.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e8d8481b24c8..0a26f8ada9f9 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 {
-- 
2.10.0.rc2.1.g053435c

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web