Skip to contentSkip to conversation

checkpatch: add an exclusion for 'for_each' helper macros

PATCH In review Dan Williams 3 participants 3 messages Jun 8, 2007 – Jun 9, 2007 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: add an exclusion for 'for_each' helper macros

checkpatch currently complains about macros like the following:

#define for_each_dma_cap_mask(cap, mask) \
	for ((cap) = first_dma_cap(mask);       \
		(cap) < DMA_TX_TYPE_END;        \
		(cap) = next_dma_cap((cap), (mask)))

---

 scripts/checkpatch.pl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
index e216d49..ee6bac9 100755
@@ -548,10 +548,10 @@ sub process {
 			}
 		}
 
-#multiline macros should be enclosed in a do while loop
+#multiline macros should be enclosed in a do while loop, unless they are a for_each helper
 		if (($prevline=~/\#define.*\\/) and !($prevline=~/do\s+{/) and
 		   !($prevline=~/\(\{/) and ($line=~/;\s*\\/) and
-		   !($line=~/do.*{/) and !($line=~/\(\{/)) {
+		   !($line=~/do.*{/) and !($line=~/\(\{/) and !($prevline=~/.*for_each.*/)) {
 			print "Macros with multiple statements should be enclosed in a do - while loop\n";
 			print "$hereprev";
 			$clean = 0;
#1 lore raw
Quoted 9 lines · Dan Williams

checkpatch currently complains about macros like the following:

#define for_each_dma_cap_mask(cap, mask) \
	for ((cap) = first_dma_cap(mask);       \
		(cap) < DMA_TX_TYPE_END;        \
		(cap) = next_dma_cap((cap), (mask)))

I'd like it if this patch updated Chapter 12 of Documentation/CodingStyle as well. That section is where the rule to check came from and it would be nice for it to mention the exception to the rule as well.

#2 lore raw
Quoted 10 lines · Joel Schopp
Quoted 8 lines · Dan Williams

checkpatch currently complains about macros like the following:

#define for_each_dma_cap_mask(cap, mask) \
    for ((cap) = first_dma_cap(mask);       \
        (cap) < DMA_TX_TYPE_END;        \
        (cap) = next_dma_cap((cap), (mask)))
Quoted 9 lines
Quoted 1 line

I'd like it if this patch updated Chapter 12 of Documentation/CodingStyle as well. That section is where the rule to check came from and it would be nice for it to mention the exception to the rule as well.

The actual restriction is on statements not on lines it seems:

"Macros with multiple statements should be enclosed in a do - while block"

So if this is only a single statement it is safe without a "container".
I have a patch cooked up here which works out if there are more than
one statement which seems to do the trick.

Dan, thanks for the report.

-apw