2010-08-18 15:49:58

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 00/16] update checkpatch to v0.31

After a long hiatus here is a batch of checkpatch updates from my tree.
I have resynced with the version in v2.6.36-rc1 and added tests for all
of the changes therein. This has thrown up a couple of regressions introduced
in those changes. This update includes fixes for those, as below:

checkpatch: fix regressions in "fix handling of leading spaces"
checkpatch: ensure kconfig help checks only apply when we are adding help

The rest of my commits mostly fixes for false positives reported directly
to me. There are also a couple of fixes from Joe and Rabin which I've
integrated and tested.

Joe et al thanks for chiming in on many of the pending threads, most
helpful.

Complete changelog below.

-apw

Andy Whitcroft (14):
checkpatch: fix regressions in "fix handling of leading spaces"
checkpatch: types may sit on a line on their own
checkpatch: suggest cleanpatch and cleanfile when appropriate
checkpatch: ensure we do not collapse bracketed sections into constants
checkpatch: handle casts better fixing false categorisation of : as binary
checkpatch: returning errno typically should be negative
checkpatch: add check for space after struct, union, and enum
checkpatch: simplify and consolidate "missing space after" checks
checkpatch: ensure kconfig help checks only apply when we are adding help
checkpatch: update copyright dates
checkpatch: clean up structure definition macro handline
checkpatch: handle EXPORT_SYMBOL for DEVICE_ATTR and similar
checkpatch: statement/block context analyser should look at sanitised lines
checkpatch: version 0.31

Joe Perches (1):
checkpatch: Add additional attribute #defines

Rabin Vincent (1):
checkpatch: check for incorrect permissions

scripts/checkpatch.pl | 133 ++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 109 insertions(+), 24 deletions(-)


2010-08-18 15:47:12

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 02/16] checkpatch: types may sit on a line on their own

When the following form is used we have a type which fully fills a line.
This means that a type may end at the end of line as well as at the
following identifier.

int **
foo;

Reported-by: Daniel Walker <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0a87c74..41f59b1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -843,7 +843,7 @@ sub annotate_values {
$av_preprocessor = 0;
}

- } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\()/) {
+ } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
print "DECLARE($1)\n" if ($dbg_values > 1);
$type = 'T';

--
1.7.0.4

2010-08-18 15:47:16

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 09/16] checkpatch: ensure kconfig help checks only apply when we are adding help

When checking the length of the help we need to be sure we are seeing
the whole story before erroring. Firstly we only want to check when
adding the help in the first place. Second we need to be sure that we
are seeing the end of the entry, nominally when there is no context below
or that context shows the start of the next entry.

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index cb19f54..e44ff91 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1400,18 +1400,34 @@ sub process {
}

# check for Kconfig help text having a real description
+# Only applies when adding the entry originally, after that we do not have
+# sufficient context to determine whether it is indeed long enough.
if ($realfile =~ /Kconfig/ &&
- $line =~ /\+?\s*(---)?help(---)?$/) {
+ $line =~ /\+\s*(?:---)?help(?:---)?$/) {
my $length = 0;
- for (my $l = $linenr; defined($lines[$l]); $l++) {
- my $f = $lines[$l];
+ my $cnt = $realcnt;
+ my $ln = $linenr + 1;
+ my $f;
+ my $is_end = 0;
+ while ($cnt > 0 && defined $lines[$ln - 1]) {
+ $f = $lines[$ln - 1];
+ $cnt-- if ($lines[$ln - 1] !~ /^-/);
+ $is_end = $lines[$ln - 1] =~ /^\+/;
+ $ln++;
+
+ next if ($f =~ /^-/);
+ $f =~ s/^.//;
$f =~ s/#.*//;
$f =~ s/^\s+//;
next if ($f =~ /^$/);
- last if ($f =~ /^\s*config\s/);
+ if ($f =~ /^\s*config\s/) {
+ $is_end = 1;
+ last;
+ }
$length++;
}
- WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($length < 4);
+ WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4);
+ #print "is_end<$is_end> length<$length>\n";
}

# check we are in a valid source file if not then ignore this hunk
--
1.7.0.4

2010-08-18 15:47:20

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 03/16] checkpatch: suggest cleanpatch and cleanfile when appropriate

When we hit types of whitespace which may be fixed by scripts/cleanpatch
and scripts/cleanfile suggest their use in our report.

Suggested-by: Bartlomiej Zolnierkiewicz <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 41f59b1..32d6a23 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -103,6 +103,8 @@ for my $key (keys %debug) {
die "$@" if ($@);
}

+my $rpt_cleaners = 0;
+
if ($terse) {
$emacs = 1;
$quiet++;
@@ -1389,6 +1391,7 @@ sub process {
} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
ERROR("trailing whitespace\n" . $herevet);
+ $rpt_cleaners = 1;
}

# check for Kconfig help text having a real description
@@ -1450,6 +1453,7 @@ sub process {
$rawline =~ /^\+\s* \s*/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
ERROR("code indent should use tabs where possible\n" . $herevet);
+ $rpt_cleaners = 1;
}

# check for space before tabs.
@@ -2842,6 +2846,15 @@ sub process {
print "\n" if ($quiet == 0);
}

+ if ($quiet == 0) {
+ # If there were whitespace errors which cleanpatch can fix
+ # then suggest that.
+ if ($rpt_cleaners) {
+ print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
+ print " scripts/cleanfile\n\n";
+ }
+ }
+
if ($clean == 1 && $quiet == 0) {
print "$vname has no obvious style problems and is ready for submission.\n"
}
--
1.7.0.4

2010-08-18 15:47:18

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 08/16] checkpatch: simplify and consolidate "missing space after" checks

Commonise the code for missing spaces after struct, union, and enum such
that they share the same code. Ensure we cover all the common cases in
each case. Check against the sanitised line to ensure we do not report
on comments and strings.

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 15 +++++----------
1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 983ac18..cb19f54 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1905,22 +1905,17 @@ sub process {
ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
}

-# missing space after union or struct definition
- if ($rawline =~ /^\+\s*(union|struct)\s+$Ident[=\{]/) {
- WARN("Missing space after struct or union definition\n" . $herecurr);
- }
-
-# missing space after enum definition
- if ($rawline =~ /^\+\s*enum\{/) {
- WARN("Missing space after enum definition\n" . $herecurr);
- }
-
# open braces for enum, union and struct go on the same line.
if ($line =~ /^.\s*{/ &&
$prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
}

+# missing space after union, struct or enum definition
+ if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
+ WARN("missing space after $1 definition\n" . $herecurr);
+ }
+
# check for spacing round square brackets; allowed:
# 1. with a type on the left -- int [] a;
# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
--
1.7.0.4

2010-08-18 15:47:51

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 15/16] checkpatch: statement/block context analyser should look at sanitised lines

When tracking context to find a block or statement we need to use the
sanitised lines, else perentheses '(' & ')' and braces '{' & '}' can
throw the scanner out. Also fix up a couple of error outputs which
include those sanitised lines incorrectly.

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8ab45b7..d086ffe 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -691,15 +691,15 @@ sub ctx_block_get {
$blk .= $rawlines[$line];

# Handle nested #if/#else.
- if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
+ if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
push(@stack, $level);
- } elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
+ } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
$level = $stack[$#stack - 1];
- } elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) {
+ } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
$level = pop(@stack);
}

- foreach my $c (split(//, $rawlines[$line])) {
+ foreach my $c (split(//, $lines[$line])) {
##print "C<$c>L<$level><$open$close>O<$off>\n";
if ($off > 0) {
$off--;
@@ -1652,7 +1652,7 @@ sub process {

if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
ERROR("that open brace { should be on the previous line\n" .
- "$here\n$ctx\n$lines[$ctx_ln - 1]\n");
+ "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
}
if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
$ctx =~ /\)\s*\;\s*$/ &&
@@ -1661,7 +1661,7 @@ sub process {
my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
if ($nindent > $indent) {
WARN("trailing semicolon indicates no statements, indent implies otherwise\n" .
- "$here\n$ctx\n$lines[$ctx_ln - 1]\n");
+ "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
}
}
}
--
1.7.0.4

2010-08-18 15:48:06

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 10/16] checkpatch: check for incorrect permissions

From: Rabin Vincent <[email protected]>

Throw an error when a source file has been given execute permissions
using the mode change line present in git diffs. Also alow the filename
matching to use the "diff" line in addition to the "+++" line, since the
mode change lines appear before any "+++" lines.

[[email protected]: simplified filename logic slightly, added tests]
Cc: Andy Whitcroft <[email protected]>
Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Rabin Vincent <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e44ff91..93fa145 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1315,7 +1315,11 @@ sub process {
$here = "#$realline: " if ($file);

# extract the filename as it passes
- if ($line=~/^\+\+\+\s+(\S+)/) {
+ if ($line =~ /^diff --git.*?(\S+)$/) {
+ $realfile = $1;
+ $realfile =~ s@^([^/]*)/@@;
+
+ } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
$realfile = $1;
$realfile =~ s@^([^/]*)/@@;

@@ -1339,6 +1343,14 @@ sub process {

$cnt_lines++ if ($realcnt != 0);

+# Check for incorrect file permissions
+ if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
+ my $permhere = $here . "FILE: $realfile\n";
+ if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
+ ERROR("do not set execute permissions for source files\n" . $permhere);
+ }
+ }
+
#check the patch for a signoff:
if ($line =~ /^\s*signed-off-by:/i) {
# This is a signoff, if ugly, so do not double report.
--
1.7.0.4

2010-08-18 15:48:14

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 07/16] checkpatch: add check for space after struct, union, and enum

Add spacing checks for struct, union, and enum definitions. Check the
spacing after type and before the equals (=) and open brace ({).

Based on a patch by Joe Perches <[email protected]>.

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index bcdb54b..983ac18 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1905,6 +1905,16 @@ sub process {
ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
}

+# missing space after union or struct definition
+ if ($rawline =~ /^\+\s*(union|struct)\s+$Ident[=\{]/) {
+ WARN("Missing space after struct or union definition\n" . $herecurr);
+ }
+
+# missing space after enum definition
+ if ($rawline =~ /^\+\s*enum\{/) {
+ WARN("Missing space after enum definition\n" . $herecurr);
+ }
+
# open braces for enum, union and struct go on the same line.
if ($line =~ /^.\s*{/ &&
$prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
--
1.7.0.4

2010-08-18 15:48:18

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 04/16] checkpatch: ensure we do not collapse bracketed sections into constants

When determining if a return () sequence is a function style bracketing
we simplify the expression one bracket at a time replacing each with a
constant. However this can trigger a false merge with expressions as
below:

return (foo)0;

Prevent this false merging.

Reported-by: Hitoshi Mitake <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 32d6a23..8d010ac 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2183,15 +2183,16 @@ sub process {
my $value = $2;

# Flatten any parentheses
- $value =~ s/\)\(/\) \(/g;
+ $value =~ s/\(/ \(/g;
+ $value =~ s/\)/\) /g;
while ($value =~ s/\[[^\{\}]*\]/1/ ||
$value !~ /(?:$Ident|-?$Constant)\s*
$Compare\s*
(?:$Ident|-?$Constant)/x &&
$value =~ s/\([^\(\)]*\)/1/) {
}
-
- if ($value =~ /^(?:$Ident|-?$Constant)$/) {
+#print "value<$value>\n";
+ if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
ERROR("return is not a function, parentheses are not required\n" . $herecurr);

} elsif ($spacing !~ /\s+/) {
--
1.7.0.4

2010-08-18 15:48:11

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 11/16] checkpatch: Add additional attribute #defines

From: Joe Perches <[email protected]>

On Wed, 2010-08-11 at 12:35 -0400, Dave Jones wrote:
> I just got this from a patch I merged..
>
> ERROR: need consistent spacing around '*' (ctx:WxV)
> #121: FILE: arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c:113:
> +static struct pcc_cpu __percpu *pcc_cpu_info;
> ^
> which doesn't seem right.

Perhaps these need to be added to checkpatch.

[[email protected]: added tests]
Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 93fa145..c151c9e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -152,6 +152,20 @@ our $Sparse = qr{
# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
our $Attribute = qr{
const|
+ __percpu|
+ __nocast|
+ __safe|
+ __bitwise__|
+ __packed__|
+ __packed2__|
+ __naked|
+ __maybe_unused|
+ __always_unused|
+ __noreturn|
+ __used|
+ __cold|
+ __noclone|
+ __deprecated|
__read_mostly|
__kprobes|
__(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
--
1.7.0.4

2010-08-18 15:48:09

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 13/16] checkpatch: clean up structure definition macro handline

Handle definitions such as the following correctly, it is not
a complex statement:

#define PREALLOC(NAME, START, END, FLAGS) { \
.name = (NAME), \
.start = (START), \
.end = (END), \
.flags = (FLAGS) \
},

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 53b2eae..d5361e4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2476,8 +2476,8 @@ sub process {
\.$Ident\s*=\s*|
^\"|\"$
}x;
- #print "REST<$rest> dstat<$dstat>\n";
- if ($rest ne '') {
+ #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
+ if ($rest ne '' && $rest ne ',') {
if ($rest !~ /while\s*\(/ &&
$dstat !~ /$exceptions/)
{
--
1.7.0.4

2010-08-18 15:48:22

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 06/16] checkpatch: returning errno typically should be negative

Add a (strict mode only) test to check for non-negative returns of what
appear to be errno values as the majority case these should indeed be
negative.

Suggested-by: Andrew Morton <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3cec299..bcdb54b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2204,6 +2204,13 @@ sub process {
ERROR("space required before the open parenthesis '('\n" . $herecurr);
}
}
+# Return of what appears to be an errno should normally be -'ve
+ if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
+ my $name = $1;
+ if ($name ne 'EOF' && $name ne 'ERROR') {
+ WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
+ }
+ }

# Need a space before open parenthesis after if, while etc
if ($line=~/\b(if|while|for|switch)\(/) {
--
1.7.0.4

2010-08-18 15:48:20

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 12/16] checkpatch: update copyright dates

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c151c9e..53b2eae 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2,7 +2,7 @@
# (c) 2001, Dave Jones. (the file handling bit)
# (c) 2005, Joel Schopp <[email protected]> (the ugly bit)
# (c) 2007,2008, Andy Whitcroft <[email protected]> (new conditions, test suite)
-# (c) 2008,2009, Andy Whitcroft <[email protected]>
+# (c) 2008-2010 Andy Whitcroft <[email protected]>
# Licensed under the terms of the GNU GPL License version 2

use strict;
--
1.7.0.4

2010-08-18 15:48:01

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 16/16] checkpatch: version 0.31

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d086ffe..c1e7fb3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -10,7 +10,7 @@ use strict;
my $P = $0;
$P =~ s@.*/@@g;

-my $V = '0.30';
+my $V = '0.31';

use Getopt::Long qw(:config no_auto_abbrev);

--
1.7.0.4

2010-08-18 15:48:03

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 14/16] checkpatch: handle EXPORT_SYMBOL for DEVICE_ATTR and similar

Handly definitions similar to below. The definition macro spits out
a symbol with a prefix. Add matching of any identifier prefix:

DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR,
ata_scsi_lpm_show, ata_scsi_lpm_put);
EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy);

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d5361e4..8ab45b7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1822,8 +1822,17 @@ sub process {
!defined $suppress_export{$realline_next} &&
($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
$lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
+ # Handle definitions which produce identifiers with
+ # a prefix:
+ # XXX(foo);
+ # EXPORT_SYMBOL(something_foo);
my $name = $1;
- if ($stat !~ /(?:
+ if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ &&
+ $name =~ /^${Ident}_$2/) {
+#print "FOO C name<$name>\n";
+ $suppress_export{$realline_next} = 1;
+
+ } elsif ($stat !~ /(?:
\n.}\s*$|
^.DEFINE_$Ident\(\Q$name\E\)|
^.DECLARE_$Ident\(\Q$name\E\)|
--
1.7.0.4

2010-08-18 15:49:47

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 05/16] checkpatch: handle casts better fixing false categorisation of : as binary

The following incantation is triggering categorisation of its colon (:)
as a binary form, which it is not:

return foo ? (s8)bar : baz;

Handle casts differently from types in the categoriser, allowing us
to better track (s8)bar as a value and not a declaration.

Reported-by: Jean Delvare <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8d010ac..3cec299 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -845,6 +845,11 @@ sub annotate_values {
$av_preprocessor = 0;
}

+ } elsif ($cur =~ /^(\(\s*$Type\s*)\)/) {
+ print "CAST($1)\n" if ($dbg_values > 1);
+ push(@av_paren_type, $type);
+ $type = 'C';
+
} elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
print "DECLARE($1)\n" if ($dbg_values > 1);
$type = 'T';
--
1.7.0.4

2010-08-18 15:50:11

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 01/16] checkpatch: fix regressions in "fix handling of leading spaces"

The patch below added checks for leading spaces on lines, but this
introduces regressions. Firstly it does not correctly detect when we are
in a comment. Secondly it does not allow for preprocessor command spacing.
Finally it does not allow for label indentation which is required to be
less than one tab. Fix these up:

checkpatch: fix handling of leading spaces:

Signed-off-by: Andy Whitcroft <[email protected]>
---
scripts/checkpatch.pl | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2039acd..0a87c74 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1459,10 +1459,13 @@ sub process {
}

# check for spaces at the beginning of a line.
- if ($rawline =~ /^\+ / && $rawline !~ /\+ +\*/) {
+# Exceptions:
+# 1) within comments
+# 2) indented preprocessor commands
+# 3) hanging labels
+ if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
- WARN("please, no space for starting a line, \
- excluding comments\n" . $herevet);
+ WARN("please, no spaces at the start of a line\n" . $herevet);
}

# check we are in a valid C source file if not then ignore this hunk
--
1.7.0.4