Skip to contentSkip to conversation

checkpatch update

PATCH New Andy Whitcroft 1 participant 6 messages Mar 1, 2012 Checkpatch

lore
Share & tools
lore

Andy Whitcroft

author maintainer
#0 lore raw

cover checkpatch update

Andrew, here a a few patches I have sitting in my tree. A small collections of improvements for false positives.

They pass all the tests I have.

Thanks.

-apw

Andy Whitcroft (5):
checkpatch: catch [ ... ] usage when not at the beginning of defination
checkpatch: allow simple character constants in #defines
checkpatch: handle string concatenation in simple #defines
checkpatch: high precidence operators do not require additional
parentheses in #defines
checkpatch: add [] to type extensions

 scripts/checkpatch.pl |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.9
author maintainer
#1 lore raw

PATCH 1/5 checkpatch: catch [ ... ] usage when not at the beginning of defination

Handle the [ A ... B ] form deeper into a definition, for example:

    static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
	    {0, 0, 0, 0, 0, 0, 0, 27, 27, [9 ... PCI_MAX_DEVICES - 1] = 0 },
	    {0, 0, 0, 0, 0, 0, 0, 29, 29, [9 ... PCI_MAX_DEVICES - 1] = 0 },
    };
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
index a3b9782..d91a86c 100755
@@ -2325,7 +2325,7 @@ sub process {
 			my ($where, $prefix) = ($-[1], $1);
 			if ($prefix !~ /$Type\s+$/ &&
 			    ($where != 0 || $prefix !~ /^.\s+$/) &&
-			    $prefix !~ /{\s+$/) {
+			    $prefix !~ /[{,]\s+$/) {
 				ERROR("BRACKET_SPACE",
 				      "space prohibited before open square bracket '['\n" . $herecurr);
 			}
Signature · 1 line
1.7.9
author maintainer
#3 lore raw

PATCH 3/5 checkpatch: handle string concatenation in simple #defines

In reply to Andy Whitcroft

Adjacent strings indicate concatentation, therefore look at identifiers directly adjacent to literal strings as strings too. This allows us to better detect the form below and accept it as a simple constant:

    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
---
 scripts/checkpatch.pl |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +6 -0
index ff8a84f..35189de 100755
@@ -2828,6 +2828,12 @@ sub process {
 			{
 			}
 
+			# Flatten any obvious string concatentation.
+			while ($dstat =~ s/("X*")\s*$Ident/$1/ ||
+			       $dstat =~ s/$Ident\s*("X*")/$1/)
+			{
+			}
+
 			my $exceptions = qr{
 				$Declare|
 				module_param_named|
Signature · 1 line
1.7.9
author maintainer
#5 lore raw

PATCH 5/5 checkpatch: add [] to type extensions

In reply to Andy Whitcroft

Add [] to a type extensions. Fixes false positives on:

    .attrs = (struct attribute *[]) {
---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
index 610036e..2bfe013 100755
@@ -323,7 +323,7 @@ sub build_types {
 		  }x;
 	$Type	= qr{
 			$NonptrType
-			(?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)?
+			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)?
 			(?:\s+$Inline|\s+$Modifier)*
 		  }x;
 	$Declare	= qr{(?:$Storage\s+)?$Type};
Signature · 1 line
1.7.9
author maintainer
#4 lore raw

PATCH 4/5 checkpatch: high precidence operators do not require additional parentheses in #defines

In reply to Andy Whitcroft

With any very high precidence operator it is not necessary to enforce additional parentheses around simple negated expressions. This prevents us requesting further perentheses around the following:

    #define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

For now add logical and bitwise not and unary minus.

---
 scripts/checkpatch.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
index 35189de..610036e 100755
@@ -2850,7 +2850,7 @@ sub process {
 			if ($dstat ne '' &&
 			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
 			    $dstat !~ /^(?:$Ident|-?$Constant);$/ &&			# foo();
-			    $dstat !~ /^(?:$Ident|-?$Constant)$/ &&			# 10 // foo()
+			    $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ &&		# 10 // foo() // !foo // ~foo // -foo
 			    $dstat !~ /^'X'$/ &&					# character constants
 			    $dstat !~ /$exceptions/ &&
 			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
Signature · 1 line
1.7.9
author maintainer
#2 lore raw

PATCH 2/5 checkpatch: allow simple character constants in #defines

In reply to Andy Whitcroft
---
 scripts/checkpatch.pl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +1 -0
index d91a86c..ff8a84f 100755
@@ -2845,6 +2845,7 @@ sub process {
 			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
 			    $dstat !~ /^(?:$Ident|-?$Constant);$/ &&			# foo();
 			    $dstat !~ /^(?:$Ident|-?$Constant)$/ &&			# 10 // foo()
+			    $dstat !~ /^'X'$/ &&					# character constants
 			    $dstat !~ /$exceptions/ &&
 			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
 			    $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&	# do {...} while (...); // do {...} while (...)
Signature · 1 line
1.7.9