mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/7] checkpatch: update to version 0.23
@ 2008-09-02 17:25 Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 1/7] checkpatch: case/default checks should only check changed lines Andy Whitcroft
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel, Andy Whitcroft

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


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

* [PATCH 1/7] checkpatch: case/default checks should only check changed lines
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 2/7] checkpatch: suppress errors triggered by short patch Andy Whitcroft
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel, Andy Whitcroft

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

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
 scripts/checkpatch.pl |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 66bcedc..457f874 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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.
-- 
1.6.0.rc1.258.g80295


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

* [PATCH 2/7] checkpatch: suppress errors triggered by short patch
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 1/7] checkpatch: case/default checks should only check changed lines Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 3/7] checkpatch: handle comment/quote nesting correctly Andy Whitcroft
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel,
	Andy Whitcroft, Julien Brunel

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.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Cc: Julien Brunel <brunel@diku.dk>
---
 scripts/checkpatch.pl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 457f874..5382f72 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;
-- 
1.6.0.rc1.258.g80295


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

* [PATCH 3/7] checkpatch: handle comment/quote nesting correctly
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 1/7] checkpatch: case/default checks should only check changed lines Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 2/7] checkpatch: suppress errors triggered by short patch Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  2008-09-11 18:46   ` Jaswinder Singh
  2008-09-02 17:25 ` [PATCH 4/7] checkpatch: check line endings in text format files Andy Whitcroft
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel,
	Andy Whitcroft, Jaswinder Singh

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

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Cc: Jaswinder Singh <jaswinder@infradead.org>
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5382f72..18646f0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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++;
-- 
1.6.0.rc1.258.g80295


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

* [PATCH 4/7] checkpatch: check line endings in text format files
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
                   ` (2 preceding siblings ...)
  2008-09-02 17:25 ` [PATCH 3/7] checkpatch: handle comment/quote nesting correctly Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 5/7] checkpatch: suspect indent count condition lines correctly Andy Whitcroft
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel, 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.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
 scripts/checkpatch.pl |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 18646f0..a2e4a3d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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/ &&
-- 
1.6.0.rc1.258.g80295


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

* [PATCH 5/7] checkpatch: suspect indent count condition lines correctly
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
                   ` (3 preceding siblings ...)
  2008-09-02 17:25 ` [PATCH 4/7] checkpatch: check line endings in text format files Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 6/7] checkpatch: ensure we only apply checks to the lines within hunks Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 7/7] checkpatch: version: 0.23 Andy Whitcroft
  6 siblings, 0 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel, Andy Whitcroft

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

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a2e4a3d..2e513fd 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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:
-- 
1.6.0.rc1.258.g80295


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

* [PATCH 6/7] checkpatch: ensure we only apply checks to the lines within hunks
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
                   ` (4 preceding siblings ...)
  2008-09-02 17:25 ` [PATCH 5/7] checkpatch: suspect indent count condition lines correctly Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  2008-09-02 17:25 ` [PATCH 7/7] checkpatch: version: 0.23 Andy Whitcroft
  6 siblings, 0 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel, 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.

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2e513fd..fe4553c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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/) {
-- 
1.6.0.rc1.258.g80295


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

* [PATCH 7/7] checkpatch: version: 0.23
  2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
                   ` (5 preceding siblings ...)
  2008-09-02 17:25 ` [PATCH 6/7] checkpatch: ensure we only apply checks to the lines within hunks Andy Whitcroft
@ 2008-09-02 17:25 ` Andy Whitcroft
  6 siblings, 0 replies; 9+ messages in thread
From: Andy Whitcroft @ 2008-09-02 17:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel, Andy Whitcroft

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index fe4553c..118fe1f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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);
 
-- 
1.6.0.rc1.258.g80295


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

* Re: [PATCH 3/7] checkpatch: handle comment/quote nesting correctly
  2008-09-02 17:25 ` [PATCH 3/7] checkpatch: handle comment/quote nesting correctly Andy Whitcroft
@ 2008-09-11 18:46   ` Jaswinder Singh
  0 siblings, 0 replies; 9+ messages in thread
From: Jaswinder Singh @ 2008-09-11 18:46 UTC (permalink / raw)
  To: Andy Whitcroft
  Cc: Andrew Morton, Randy Dunlap, Joel Schopp, Ingo Molnar, linux-kernel


On Tue, 2008-09-02 at 18:25 +0100, Andy Whitcroft wrote:
> Ensure that a close comment cannot incorrectly trigger in the middle
> of a string.  Reported by Jaswinder Singh.
> 
> Signed-off-by: Andy Whitcroft <apw@shadowen.org>
> Cc: Jaswinder Singh <jaswinder@infradead.org>

Acked by Jaswinder Singh <jaswinder@infradead.org>

Thank you,

Jaswinder Singh.


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

end of thread, other threads:[~2008-09-11 18:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-02 17:25 [PATCH 0/7] checkpatch: update to version 0.23 Andy Whitcroft
2008-09-02 17:25 ` [PATCH 1/7] checkpatch: case/default checks should only check changed lines Andy Whitcroft
2008-09-02 17:25 ` [PATCH 2/7] checkpatch: suppress errors triggered by short patch Andy Whitcroft
2008-09-02 17:25 ` [PATCH 3/7] checkpatch: handle comment/quote nesting correctly Andy Whitcroft
2008-09-11 18:46   ` Jaswinder Singh
2008-09-02 17:25 ` [PATCH 4/7] checkpatch: check line endings in text format files Andy Whitcroft
2008-09-02 17:25 ` [PATCH 5/7] checkpatch: suspect indent count condition lines correctly Andy Whitcroft
2008-09-02 17:25 ` [PATCH 6/7] checkpatch: ensure we only apply checks to the lines within hunks Andy Whitcroft
2008-09-02 17:25 ` [PATCH 7/7] checkpatch: version: 0.23 Andy Whitcroft

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

all inboxes | Powered by JetHome®