Skip to contentSkip to conversation

update checkpatch to version 0.27

PATCH New Andy Whitcroft 1 participant 7 messages Jan 12, 2009 Checkpatch

lore
Share & tools
lore

Andy Whitcroft

author maintainer
#0 lore raw

cover update checkpatch to version 0.27

This update brings an urgent fix for #if handling, and a couple of new checks. Of note:

- fixes spurious warning on mismatched #if/#else within the context
- fixes to type/cast warnings on bad spacing
- seq_operations should be const

The first patch in this series is the fix for the spurious warnings which were affecting Ingo and probabally should be expedited to mainline.

Complete changelog below.

-apw

Andy Whitcroft (6):
checkpatch: handle missing #if open in context
checkpatch: type/cast spacing should not check prefix spacing
checkpatch: allow parentheses on return handle array values
checkpatch: if should not continue a preceeding brace
checkpatch: struct seq_operations should normally be const
checkpatch: version: 0.27

 scripts/checkpatch.pl |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
author maintainer
#1 lore raw

PATCH 1/6 checkpatch: handle missing #if open in context

If the #if opening statement is not in the context then the context stack can be empty. Handle this by ensuring there is always a blank entry in the stack.

---
 scripts/checkpatch.pl |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +3 -1
index 7bed4ed..eefef65 100755
@@ -411,13 +411,15 @@ sub ctx_statement_block {
 
 	my $type = '';
 	my $level = 0;
-	my @stack = ([$type, $level]);
+	my @stack = ();
 	my $p;
 	my $c;
 	my $len = 0;
 
 	my $remainder;
 	while (1) {
+		@stack = (['', 0]) if ($#stack == -1);
+
 		#warn "CSB: blk<$blk> remain<$remain>\n";
 		# If we are about to drop off the end, pull in more
 		# context.
Signature · 1 line
1.6.0.4.911.gc990
author maintainer
#2 lore raw

PATCH 2/6 checkpatch: type/cast spacing should not check prefix spacing

In reply to Andy Whitcroft

We should not be complaining about the prefix spacing for types and casts. We are triggering here because the check for spacing between '*'s is overly loose. Tighten this up.

---
 scripts/checkpatch.pl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
index eefef65..1d7924a 100755
@@ -1665,7 +1665,7 @@ sub process {
 			# Should not end with a space.
 			$to =~ s/\s+$//;
 			# '*'s should not have spaces between.
-			while ($to =~ s/(.)\s\*/$1\*/) {
+			while ($to =~ s/\*\s+\*/\*\*/) {
 			}
 
 			#print "from<$from> to<$to>\n";
@@ -1680,7 +1680,7 @@ sub process {
 			# Should not end with a space.
 			$to =~ s/\s+$//;
 			# '*'s should not have spaces between.
-			while ($to =~ s/(.)\s\*/$1\*/) {
+			while ($to =~ s/\*\s+\*/\*\*/) {
 			}
 			# Modifiers should have spaces.
 			$to =~ s/(\b$Modifier$)/$1 /;
Signature · 1 line
1.6.0.4.911.gc990
author maintainer
#3 lore raw

PATCH 3/6 checkpatch: allow parentheses on return handle array values

In reply to Andy Whitcroft

When we allow return to have surrounding parentheses when containing comparison operators we are not correctly handling the case where the values contain array sufffixes. Squash them.

---
 scripts/checkpatch.pl |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +5 -1
index 1d7924a..696196e 100755
@@ -2016,7 +2016,11 @@ sub process {
 
 			# Flatten any parentheses
 			$value =~ s/\)\(/\) \(/g;
-			while ($value !~ /(?:$Ident|-?$Constant)\s*$Compare\s*(?:$Ident|-?$Constant)/ && $value =~ s/\([^\(\)]*\)/1/) {
+			while ($value =~ s/\[[^\{\}]*\]/1/ ||
+			       $value !~ /(?:$Ident|-?$Constant)\s*
+					     $Compare\s*
+					     (?:$Ident|-?$Constant)/x &&
+			       $value =~ s/\([^\(\)]*\)/1/) {
 			}
 
 			if ($value =~ /^(?:$Ident|-?$Constant)$/) {
Signature · 1 line
1.6.0.4.911.gc990
author maintainer
#4 lore raw

PATCH 4/6 checkpatch: if should not continue a preceeding brace

In reply to Andy Whitcroft

We should not be continuing a braced section with an if, for example:

	if (...) {
	} if (...) {
	}

Detect this and suggest adding a newline.

---
 scripts/checkpatch.pl |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +5 -0
index 696196e..5ea55e3 100755
@@ -2108,6 +2108,11 @@ sub process {
 				ERROR("trailing statements should be on next line\n" . $herecurr);
 			}
 		}
+# if should not continue a brace
+		if ($line =~ /}\s*if\b/) {
+			ERROR("trailing statements should be on next line\n" .
+				$herecurr);
+		}
 # case and default should not have general statements after them
 		if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
 		    $line !~ /\G(?:
Signature · 1 line
1.6.0.4.911.gc990
author maintainer
#5 lore raw

PATCH 5/6 checkpatch: struct seq_operations should normally be const

In reply to Andy Whitcroft

In the general use case struct seq_operations should be a const object. Check for and warn where it is not.

---
 scripts/checkpatch.pl |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +4 -3
index 5ea55e3..447435c 100755
@@ -2527,9 +2527,10 @@ sub process {
 			WARN("please use device_initcall() instead of __initcall()\n" . $herecurr);
 		}
 # check for struct file_operations, ensure they are const.
-		if ($line =~ /\bstruct\s+file_operations\b/ &&
-		    $line !~ /\bconst\b/) {
-			WARN("struct file_operations should normally be const\n" . $herecurr);
+		if ($line !~ /\bconst\b/ &&
+		    $line =~ /\bstruct\s+(file_operations|seq_operations)\b/) {
+			WARN("struct $1 should normally be const\n" .
+				$herecurr);
 		}
 
 # use of NR_CPUS is usually wrong
Signature · 1 line
1.6.0.4.911.gc990
author maintainer
#6 lore raw

PATCH 6/6 checkpatch: version: 0.27

In reply to Andy Whitcroft
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
index 447435c..45eb0ae 100755
@@ -10,7 +10,7 @@ use strict;
 my $P = $0;
 $P =~ s@.*/@@g;
 
-my $V = '0.26';
+my $V = '0.27';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
Signature · 1 line
1.6.0.4.911.gc990