public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] checkpatch: Add missing c90 types
@ 2014-07-17 15:52 Joe Perches
  2014-07-17 15:52 ` [PATCH 1/3] checkpatch: Add short int to c variable types Joe Perches
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Joe Perches @ 2014-07-17 15:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andy Whitcroft, Hartley Sweeten, linux-kernel

c90 section "6.7.2 Type Specifiers" says:
    "type specifiers may occur in any order"

That means that:
    short int is the same as int short
    unsigned short int is the same as int unsigned short
    etc...

checkpatch currently parses only a subset of these allowed types.

For instance: "unsigned short" is a found by checkpatch as a
specific type, but none of the "signed int" or "int short" variants
are found.

Change all the existing types to allow signed and unsigned variants.
Reorder the existing types array to match longest type first.

Add another table for the "kernel style misordered" variants.

Add this misordered table to the findable types.

Warn when the misordered style is used.

This improves the "Missing a blank line after declarations" test as
it depends on the correct parsing of the $Declare variable which
looks for "$Type $Ident;" (ie: declarations like "int foo;").

Joe Perches (3):
  checkpatch: Add short int to c variable types
  checkpatch: Add signed generic types
  checkpatch: Add test for native c90 types in unusual order

 scripts/checkpatch.pl | 61 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 8 deletions(-)

-- 
1.8.1.2.459.gbcd45b4.dirty


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

* [PATCH 1/3] checkpatch: Add short int to c variable types
  2014-07-17 15:52 [PATCH 0/3] checkpatch: Add missing c90 types Joe Perches
@ 2014-07-17 15:52 ` Joe Perches
  2014-07-17 15:52 ` [PATCH 2/3] checkpatch: Add signed generic types Joe Perches
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2014-07-17 15:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andy Whitcroft, Hartley Sweeten, linux-kernel

short int is one of the 6.7.2 c90 types.
Find it appropriately.

This fixes a defect in checkpatch where it suggests that a
line break after declaration is required using an input like:

	int foo;
	short int bar;

Without this change, it warns on the short int line.

Reported-by: Hartley Sweeten <HartleyS@visionengravers.com>
Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f3d9a88..d81e4ab 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -356,6 +356,7 @@ our $signature_tags = qr{(?xi:
 our @typeList = (
 	qr{void},
 	qr{(?:unsigned\s+)?char},
+	qr{(?:unsigned\s+)?short\s+int},
 	qr{(?:unsigned\s+)?short},
 	qr{(?:unsigned\s+)?int},
 	qr{(?:unsigned\s+)?long},
-- 
1.8.1.2.459.gbcd45b4.dirty


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

* [PATCH 2/3] checkpatch: Add signed generic types
  2014-07-17 15:52 [PATCH 0/3] checkpatch: Add missing c90 types Joe Perches
  2014-07-17 15:52 ` [PATCH 1/3] checkpatch: Add short int to c variable types Joe Perches
@ 2014-07-17 15:52 ` Joe Perches
  2014-07-17 15:52 ` [PATCH 3/3] checkpatch: Add test for native c90 types in unusual order Joe Perches
  2014-07-18 11:06 ` [PATCH 0/3] checkpatch: Add missing c90 types Andy Whitcroft
  3 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2014-07-17 15:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andy Whitcroft, Hartley Sweeten, linux-kernel

Current generic types are unsigned or unspecified.
Add signed to the types.

Reorder the types to find the longest match first.

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d81e4ab..1bfe2fc 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -355,15 +355,15 @@ our $signature_tags = qr{(?xi:
 
 our @typeList = (
 	qr{void},
-	qr{(?:unsigned\s+)?char},
-	qr{(?:unsigned\s+)?short\s+int},
-	qr{(?:unsigned\s+)?short},
-	qr{(?:unsigned\s+)?int},
-	qr{(?:unsigned\s+)?long},
-	qr{(?:unsigned\s+)?long\s+int},
-	qr{(?:unsigned\s+)?long\s+long},
-	qr{(?:unsigned\s+)?long\s+long\s+int},
-	qr{unsigned},
+	qr{(?:(?:un)?signed\s+)?char},
+	qr{(?:(?:un)?signed\s+)?short\s+int},
+	qr{(?:(?:un)?signed\s+)?short},
+	qr{(?:(?:un)?signed\s+)?int},
+	qr{(?:(?:un)?signed\s+)?long\s+int},
+	qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
+	qr{(?:(?:un)?signed\s+)?long\s+long},
+	qr{(?:(?:un)?signed\s+)?long},
+	qr{(?:un)?signed},
 	qr{float},
 	qr{double},
 	qr{bool},
-- 
1.8.1.2.459.gbcd45b4.dirty


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

* [PATCH 3/3] checkpatch: Add test for native c90 types in unusual order
  2014-07-17 15:52 [PATCH 0/3] checkpatch: Add missing c90 types Joe Perches
  2014-07-17 15:52 ` [PATCH 1/3] checkpatch: Add short int to c variable types Joe Perches
  2014-07-17 15:52 ` [PATCH 2/3] checkpatch: Add signed generic types Joe Perches
@ 2014-07-17 15:52 ` Joe Perches
  2014-07-18 11:06 ` [PATCH 0/3] checkpatch: Add missing c90 types Andy Whitcroft
  3 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2014-07-17 15:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andy Whitcroft, Hartley Sweeten, linux-kernel

c90 section "6.7.2 Type Specifiers" says:
    "type specifiers may occur in any order"

That means that:
    short int is the same as int short
    unsigned short int is the same as int unsigned short
    etc...

checkpatch currently parses only a subset of these allowed types.

For instance: "unsigned short" and "signed short" are found by checkpatch
as a specific type, but none of the or "int short" or "int signed short"
variants are found.

Add another table for the "kernel style misordered" variants.

Add this misordered table to the findable types.

Warn when the misordered style is used.

This improves the "Missing a blank line after declarations" test as
it depends on the correct parsing of the $Declare variable which
looks for "$Type $Ident;" (ie: declarations like "int foo;").

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1bfe2fc..d21b890 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -309,9 +309,12 @@ our $Operators	= qr{
 our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
 
 our $NonptrType;
+our $NonptrTypeMisordered;
 our $NonptrTypeWithAttr;
 our $Type;
+our $TypeMisordered;
 our $Declare;
+our $DeclareMisordered;
 
 our $NON_ASCII_UTF8	= qr{
 	[\xC2-\xDF][\x80-\xBF]               # non-overlong 2-byte
@@ -353,6 +356,25 @@ our $signature_tags = qr{(?xi:
 	Cc:
 )};
 
+our @typeListMisordered = (
+	qr{char\s+(?:un)?signed},
+	qr{int\s+(?:(?:un)?signed\s+)?short\s},
+	qr{int\s+short(?:\s+(?:un)?signed)},
+	qr{short\s+int(?:\s+(?:un)?signed)},
+	qr{(?:un)?signed\s+int\s+short},
+	qr{short\s+(?:un)?signed},
+	qr{long\s+int\s+(?:un)?signed},
+	qr{int\s+long\s+(?:un)?signed},
+	qr{long\s+(?:un)?signed\s+int},
+	qr{int\s+(?:un)?signed\s+long},
+	qr{int\s+(?:un)?signed},
+	qr{int\s+long\s+long\s+(?:un)?signed},
+	qr{long\s+long\s+int\s+(?:un)?signed},
+	qr{long\s+long\s+(?:un)?signed\s+int},
+	qr{long\s+long\s+(?:un)?signed},
+	qr{long\s+(?:un)?signed},
+);
+
 our @typeList = (
 	qr{void},
 	qr{(?:(?:un)?signed\s+)?char},
@@ -373,6 +395,7 @@ our @typeList = (
 	qr{${Ident}_t},
 	qr{${Ident}_handler},
 	qr{${Ident}_handler_fn},
+	@typeListMisordered,
 );
 our @typeListWithAttr = (
 	@typeList,
@@ -414,6 +437,7 @@ our $allowed_asm_includes = qr{(?x:
 sub build_types {
 	my $mods = "(?x:  \n" . join("|\n  ", @modifierList) . "\n)";
 	my $all = "(?x:  \n" . join("|\n  ", @typeList) . "\n)";
+	my $Misordered = "(?x:  \n" . join("|\n  ", @typeListMisordered) . "\n)";
 	my $allWithAttr = "(?x:  \n" . join("|\n  ", @typeListWithAttr) . "\n)";
 	$Modifier	= qr{(?:$Attribute|$Sparse|$mods)};
 	$NonptrType	= qr{
@@ -425,6 +449,13 @@ sub build_types {
 			)
 			(?:\s+$Modifier|\s+const)*
 		  }x;
+	$NonptrTypeMisordered	= qr{
+			(?:$Modifier\s+|const\s+)*
+			(?:
+				(?:${Misordered}\b)
+			)
+			(?:\s+$Modifier|\s+const)*
+		  }x;
 	$NonptrTypeWithAttr	= qr{
 			(?:$Modifier\s+|const\s+)*
 			(?:
@@ -439,7 +470,13 @@ sub build_types {
 			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
 			(?:\s+$Inline|\s+$Modifier)*
 		  }x;
+	$TypeMisordered	= qr{
+			$NonptrTypeMisordered
+			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
+			(?:\s+$Inline|\s+$Modifier)*
+		  }x;
 	$Declare	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
+	$DeclareMisordered	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
 }
 build_types();
 
@@ -2994,6 +3031,13 @@ sub process {
 			}
 		}
 
+# check for misordered declarations of char/short/int/long with signed/unsigned
+		while ($sline =~ m{(\b$TypeMisordered\b)}g) {
+			my $tmp = trim($1);
+			WARN("MISORDERED_TYPE",
+			     "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
+		}
+
 # check for static const char * arrays.
 		if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
 			WARN("STATIC_CONST_CHAR_ARRAY",
-- 
1.8.1.2.459.gbcd45b4.dirty


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

* Re: [PATCH 0/3] checkpatch: Add missing c90 types
  2014-07-17 15:52 [PATCH 0/3] checkpatch: Add missing c90 types Joe Perches
                   ` (2 preceding siblings ...)
  2014-07-17 15:52 ` [PATCH 3/3] checkpatch: Add test for native c90 types in unusual order Joe Perches
@ 2014-07-18 11:06 ` Andy Whitcroft
  3 siblings, 0 replies; 5+ messages in thread
From: Andy Whitcroft @ 2014-07-18 11:06 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andrew Morton, Hartley Sweeten, linux-kernel

On Thu, Jul 17, 2014 at 08:52:00AM -0700, Joe Perches wrote:
> c90 section "6.7.2 Type Specifiers" says:
>     "type specifiers may occur in any order"
> 
> That means that:
>     short int is the same as int short
>     unsigned short int is the same as int unsigned short
>     etc...
> 
> checkpatch currently parses only a subset of these allowed types.
> 
> For instance: "unsigned short" is a found by checkpatch as a
> specific type, but none of the "signed int" or "int short" variants
> are found.
> 
> Change all the existing types to allow signed and unsigned variants.
> Reorder the existing types array to match longest type first.
> 
> Add another table for the "kernel style misordered" variants.
> 
> Add this misordered table to the findable types.
> 
> Warn when the misordered style is used.
> 
> This improves the "Missing a blank line after declarations" test as
> it depends on the correct parsing of the $Declare variable which
> looks for "$Type $Ident;" (ie: declarations like "int foo;").
> 
> Joe Perches (3):
>   checkpatch: Add short int to c variable types
>   checkpatch: Add signed generic types
>   checkpatch: Add test for native c90 types in unusual order
> 
>  scripts/checkpatch.pl | 61 ++++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 53 insertions(+), 8 deletions(-)

Looks like a sane plan to me.

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw

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

end of thread, other threads:[~2014-07-18 11:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-17 15:52 [PATCH 0/3] checkpatch: Add missing c90 types Joe Perches
2014-07-17 15:52 ` [PATCH 1/3] checkpatch: Add short int to c variable types Joe Perches
2014-07-17 15:52 ` [PATCH 2/3] checkpatch: Add signed generic types Joe Perches
2014-07-17 15:52 ` [PATCH 3/3] checkpatch: Add test for native c90 types in unusual order Joe Perches
2014-07-18 11:06 ` [PATCH 0/3] checkpatch: Add missing c90 types Andy Whitcroft

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