Skip to contentSkip to conversation

checkpatch: update to version 0.23

PATCH In review Andy Whitcroft 2 participants 9 messages Sep 2, 2008 – Sep 11, 2008 Checkpatch

lore
Share & tools
lore
#0 lore raw

cover checkpatch: update to version 0.23

This update brings a few small fixes to existing checks. Of note:

- restricts case/default checks to changed lines,
- suppresses perl errors for short patch hunks
- fixes comment handling for long hunks

Complete changelog below.

-apw

Andy Whitcroft (7):
checkpatch: case/default checks should only check changed lines
checkpatch: suppress errors triggered by short patch
checkpatch: handle comment/quote nesting correctly
checkpatch: check line endings in text format files
checkpatch: suspect indent count condition lines correctly
checkpatch: ensure we only apply checks to the lines within hunks
checkpatch: version: 0.23

 scripts/checkpatch.pl |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)
#1 lore raw

PATCH 1/7 checkpatch: case/default checks should only check changed lines

We should only be checking changes lines for the trailing statement check on case/default statements.

---
 scripts/checkpatch.pl |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
scripts/checkpatch.pl +9 -8
index 66bcedc..457f874 100755
@@ -1363,14 +1363,6 @@ sub process {
 				ERROR("switch and case should be at the same indent\n$hereline$err");
 			}
 		}
-		if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
-		    $line !~ /\G(?:
-			(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
-			\s*return\s+
-		    )/xg)
-		{
-			ERROR("trailing statements should be on next line\n" . $herecurr);
-		}
 
 # if/while/etc brace do not go on next line, unless defining a do while loop,
 # or if that brace on the next line is for something else
@@ -1986,6 +1978,15 @@ sub process {
 				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(?:
+			(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
+			\s*return\s+
+		    )/xg)
+		{
+			ERROR("trailing statements should be on next line\n" . $herecurr);
+		}
 
 		# Check for }<nl>else {, these must be at the same
 		# indent level to be relevant to each other.
Signature · 1 line
1.6.0.rc1.258.g80295
#2 lore raw

PATCH 2/7 checkpatch: suppress errors triggered by short patch

In reply to Andy Whitcroft

When the last hunk of a patch is short it will trigger errors from checkpatch:

Use of uninitialized value in pattern match (m//)
at /usr/local/bin/checkpatch.pl line 394.
Use of uninitialized value in concatenation (.) or string
at /usr/local/bin/checkpatch.pl line 397.
Use of uninitialized value in pattern match (m//)

Avoid touching beyond the last line. Reported by Julien Brunel.

---
 scripts/checkpatch.pl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +1 -0
index 457f874..5382f72 100755
@@ -408,6 +408,7 @@ sub ctx_statement_block {
 		# context.
 		if ($off >= $len) {
 			for (; $remain > 0; $line++) {
+				last if (!defined $lines[$line]);
 				next if ($lines[$line] =~ /^-/);
 				$remain--;
 				$loff = $len;
Signature · 1 line
1.6.0.rc1.258.g80295
#3 lore raw

PATCH 3/7 checkpatch: handle comment/quote nesting correctly

In reply to Andy Whitcroft

Ensure that a close comment cannot incorrectly trigger in the middle of a string. Reported by Jaswinder Singh.

---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
index 5382f72..18646f0 100755
@@ -335,7 +335,7 @@ sub sanitise_line {
 			$off++;
 			next;
 		}
-		if (substr($line, $off, 2) eq '*/') {
+		if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
 			$sanitise_quote = '';
 			substr($res, $off, 2, "$;$;");
 			$off++;
Signature · 1 line
1.6.0.rc1.258.g80295
#5 lore raw

PATCH 4/7 checkpatch: check line endings in text format files

In reply to Andy Whitcroft

Firmware may be included in the kernel as .ihex files. These are inherantly text, but not source. The line ending checks are applicable to these kinds of file, allow just these checks to apply to all files.

---
 scripts/checkpatch.pl |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +4 -3
index 18646f0..a2e4a3d 100755
@@ -1241,9 +1241,6 @@ sub process {
 #ignore lines being removed
 		if ($line=~/^-/) {next;}
 
-# check we are in a valid source file if not then ignore this hunk
-		next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
-
 #trailing whitespace
 		if ($line =~ /^\+.*\015/) {
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
@@ -1253,6 +1250,10 @@ sub process {
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
 			ERROR("trailing whitespace\n" . $herevet);
 		}
+
+# check we are in a valid source file if not then ignore this hunk
+		next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
+
 #80 column limit
 		if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
 		    $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
Signature · 1 line
1.6.0.rc1.258.g80295
#6 lore raw

PATCH 5/7 checkpatch: suspect indent count condition lines correctly

In reply to Andy Whitcroft

Correct calculation of the number of lines of condition where we have suspect indent.

---
 scripts/checkpatch.pl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +2 -1
index a2e4a3d..2e513fd 100755
@@ -1417,7 +1417,8 @@ sub process {
 			$s =~ s/\n./\n/gs;
 
 			# Find out how long the conditional actually is.
-			my $cond_lines = 0 + $c =~ /\n/gs;
+			my @newlines = ($c =~ /\n/gs);
+			my $cond_lines = 1 + $#newlines;
 
 			# We want to check the first line inside the block
 			# starting at the end of the conditional, so remove:
Signature · 1 line
1.6.0.rc1.258.g80295
#7 lore raw

PATCH 6/7 checkpatch: ensure we only apply checks to the lines within hunks

In reply to Andy Whitcroft

We should only apply source checks to lines within hunks. Checks which are anchored in the context may falsly trigger in the commentory. Ensure they only match within valid hunk lines.

---
 scripts/checkpatch.pl |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
index 2e513fd..fe4553c 100755
@@ -1128,6 +1128,7 @@ sub process {
 		$linenr++;
 
 		my $rawline = $rawlines[$linenr - 1];
+		my $hunk_line = ($realcnt != 0);
 
 #extract the line range in the file after the patch is applied
 		if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
@@ -1238,8 +1239,8 @@ sub process {
 			ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
 		}
 
-#ignore lines being removed
-		if ($line=~/^-/) {next;}
+# ignore non-hunk lines and lines being removed
+		next if (!$hunk_line || $line =~ /^-/);
 
 #trailing whitespace
 		if ($line =~ /^\+.*\015/) {
Signature · 1 line
1.6.0.rc1.258.g80295
#8 lore raw

PATCH 7/7 checkpatch: version: 0.23

In reply to Andy Whitcroft
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
index fe4553c..118fe1f 100755
@@ -9,7 +9,7 @@ use strict;
 my $P = $0;
 $P =~ s@.*/@@g;
 
-my $V = '0.22';
+my $V = '0.23';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
Signature · 1 line
1.6.0.rc1.258.g80295