linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] checkpatch update
@ 2012-03-01 12:44 Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 1/5] checkpatch: catch [ ... ] usage when not at the beginning of defination Andy Whitcroft
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Andy Whitcroft @ 2012-03-01 12:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Joe Perches, linux-kernel, Andy Whitcroft

Andrew, here a a few patches I have sitting in my tree.  A small
collections of improvements for false positives.

They pass all the tests I have.

Thanks.

-apw

Andy Whitcroft (5):
  checkpatch: catch [ ... ] usage when not at the beginning of defination
  checkpatch: allow simple character constants in #defines
  checkpatch: handle string concatenation in simple #defines
  checkpatch: high precidence operators do not require additional
    parentheses in #defines
  checkpatch: add [] to type extensions

 scripts/checkpatch.pl |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

-- 
1.7.9


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

* [PATCH 1/5] checkpatch: catch [ ... ] usage when not at the beginning of defination
  2012-03-01 12:44 [PATCH 0/5] checkpatch update Andy Whitcroft
@ 2012-03-01 12:44 ` Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 2/5] checkpatch: allow simple character constants in #defines Andy Whitcroft
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Whitcroft @ 2012-03-01 12:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Joe Perches, linux-kernel, Andy Whitcroft

Handle the [ A ... B ] form deeper into a definition, for example:

    static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
	    {0, 0, 0, 0, 0, 0, 0, 27, 27, [9 ... PCI_MAX_DEVICES - 1] = 0 },
	    {0, 0, 0, 0, 0, 0, 0, 29, 29, [9 ... PCI_MAX_DEVICES - 1] = 0 },
    };

Reported-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a3b9782..d91a86c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2325,7 +2325,7 @@ sub process {
 			my ($where, $prefix) = ($-[1], $1);
 			if ($prefix !~ /$Type\s+$/ &&
 			    ($where != 0 || $prefix !~ /^.\s+$/) &&
-			    $prefix !~ /{\s+$/) {
+			    $prefix !~ /[{,]\s+$/) {
 				ERROR("BRACKET_SPACE",
 				      "space prohibited before open square bracket '['\n" . $herecurr);
 			}
-- 
1.7.9


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

* [PATCH 2/5] checkpatch: allow simple character constants in #defines
  2012-03-01 12:44 [PATCH 0/5] checkpatch update Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 1/5] checkpatch: catch [ ... ] usage when not at the beginning of defination Andy Whitcroft
@ 2012-03-01 12:44 ` Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 3/5] checkpatch: handle string concatenation in simple #defines Andy Whitcroft
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Whitcroft @ 2012-03-01 12:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Joe Perches, linux-kernel, Andy Whitcroft

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d91a86c..ff8a84f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2845,6 +2845,7 @@ sub process {
 			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
 			    $dstat !~ /^(?:$Ident|-?$Constant);$/ &&			# foo();
 			    $dstat !~ /^(?:$Ident|-?$Constant)$/ &&			# 10 // foo()
+			    $dstat !~ /^'X'$/ &&					# character constants
 			    $dstat !~ /$exceptions/ &&
 			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
 			    $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&	# do {...} while (...); // do {...} while (...)
-- 
1.7.9


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

* [PATCH 3/5] checkpatch: handle string concatenation in simple #defines
  2012-03-01 12:44 [PATCH 0/5] checkpatch update Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 1/5] checkpatch: catch [ ... ] usage when not at the beginning of defination Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 2/5] checkpatch: allow simple character constants in #defines Andy Whitcroft
@ 2012-03-01 12:44 ` Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 4/5] checkpatch: high precidence operators do not require additional parentheses in #defines Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 5/5] checkpatch: add [] to type extensions Andy Whitcroft
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Whitcroft @ 2012-03-01 12:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Joe Perches, linux-kernel, Andy Whitcroft

Adjacent strings indicate concatentation, therefore look at identifiers
directly adjacent to literal strings as strings too.  This allows us to
better detect the form below and accept it as a simple constant:

    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ff8a84f..35189de 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2828,6 +2828,12 @@ sub process {
 			{
 			}
 
+			# Flatten any obvious string concatentation.
+			while ($dstat =~ s/("X*")\s*$Ident/$1/ ||
+			       $dstat =~ s/$Ident\s*("X*")/$1/)
+			{
+			}
+
 			my $exceptions = qr{
 				$Declare|
 				module_param_named|
-- 
1.7.9


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

* [PATCH 4/5] checkpatch: high precidence operators do not require additional parentheses in #defines
  2012-03-01 12:44 [PATCH 0/5] checkpatch update Andy Whitcroft
                   ` (2 preceding siblings ...)
  2012-03-01 12:44 ` [PATCH 3/5] checkpatch: handle string concatenation in simple #defines Andy Whitcroft
@ 2012-03-01 12:44 ` Andy Whitcroft
  2012-03-01 12:44 ` [PATCH 5/5] checkpatch: add [] to type extensions Andy Whitcroft
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Whitcroft @ 2012-03-01 12:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Joe Perches, linux-kernel, Andy Whitcroft

With any very high precidence operator it is not necessary to enforce
additional parentheses around simple negated expressions.  This prevents
us requesting further perentheses around the following:

    #define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

For now add logical and bitwise not and unary minus.

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 35189de..610036e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2850,7 +2850,7 @@ sub process {
 			if ($dstat ne '' &&
 			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
 			    $dstat !~ /^(?:$Ident|-?$Constant);$/ &&			# foo();
-			    $dstat !~ /^(?:$Ident|-?$Constant)$/ &&			# 10 // foo()
+			    $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ &&		# 10 // foo() // !foo // ~foo // -foo
 			    $dstat !~ /^'X'$/ &&					# character constants
 			    $dstat !~ /$exceptions/ &&
 			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
-- 
1.7.9


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

* [PATCH 5/5] checkpatch: add [] to type extensions
  2012-03-01 12:44 [PATCH 0/5] checkpatch update Andy Whitcroft
                   ` (3 preceding siblings ...)
  2012-03-01 12:44 ` [PATCH 4/5] checkpatch: high precidence operators do not require additional parentheses in #defines Andy Whitcroft
@ 2012-03-01 12:44 ` Andy Whitcroft
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Whitcroft @ 2012-03-01 12:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Joe Perches, linux-kernel, Andy Whitcroft

Add [] to a type extensions.  Fixes false positives on:

    .attrs = (struct attribute *[]) {

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 610036e..2bfe013 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -323,7 +323,7 @@ sub build_types {
 		  }x;
 	$Type	= qr{
 			$NonptrType
-			(?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)?
+			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)?
 			(?:\s+$Inline|\s+$Modifier)*
 		  }x;
 	$Declare	= qr{(?:$Storage\s+)?$Type};
-- 
1.7.9


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

end of thread, other threads:[~2012-03-01 12:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-01 12:44 [PATCH 0/5] checkpatch update Andy Whitcroft
2012-03-01 12:44 ` [PATCH 1/5] checkpatch: catch [ ... ] usage when not at the beginning of defination Andy Whitcroft
2012-03-01 12:44 ` [PATCH 2/5] checkpatch: allow simple character constants in #defines Andy Whitcroft
2012-03-01 12:44 ` [PATCH 3/5] checkpatch: handle string concatenation in simple #defines Andy Whitcroft
2012-03-01 12:44 ` [PATCH 4/5] checkpatch: high precidence operators do not require additional parentheses in #defines Andy Whitcroft
2012-03-01 12:44 ` [PATCH 5/5] checkpatch: add [] to type extensions Andy Whitcroft

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).