public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: add an exclusion for 'for_each' helper macros
@ 2007-06-08 17:11 Dan Williams
  2007-06-08 17:46 ` Joel Schopp
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2007-06-08 17:11 UTC (permalink / raw)
  To: apw, rdunlap, jschopp; +Cc: linux-kernel

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)))


Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e216d49..ee6bac9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] checkpatch: add an exclusion for 'for_each' helper macros
  2007-06-08 17:11 [PATCH] checkpatch: add an exclusion for 'for_each' helper macros Dan Williams
@ 2007-06-08 17:46 ` Joel Schopp
  2007-06-09 14:06   ` Andy Whitcroft
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Schopp @ 2007-06-08 17:46 UTC (permalink / raw)
  To: Dan Williams; +Cc: apw, rdunlap, linux-kernel


Dan Williams wrote:
> 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)))
> 
> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

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.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] checkpatch: add an exclusion for 'for_each' helper macros
  2007-06-08 17:46 ` Joel Schopp
@ 2007-06-09 14:06   ` Andy Whitcroft
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Whitcroft @ 2007-06-09 14:06 UTC (permalink / raw)
  To: Joel Schopp, Dan Williams; +Cc: rdunlap, linux-kernel

Joel Schopp wrote:
> 
> Dan Williams wrote:
>> 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)))
>>
>>
>> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-09 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-08 17:11 [PATCH] checkpatch: add an exclusion for 'for_each' helper macros Dan Williams
2007-06-08 17:46 ` Joel Schopp
2007-06-09 14:06   ` Andy Whitcroft

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox