Skip to contentSkip to conversation

scripts: checkpatch.pl: Fix existing typedef false positive warning

PATCH In review Greg Donald 2 participants 4 messages Sep 22, 2014 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: checkpatch.pl: Fix existing typedef false positive warning

Fixing an "open brace '{' following struct go on the same line" error causes a false positive warning "do not add new typedefs". Fix existing typedef false positive warning.

---
 scripts/checkpatch.pl | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +13 -3
index 4d08b39..eafe5e7 100755
@@ -3081,14 +3081,24 @@ sub process {
 		}
 
 # check for new typedefs, only function parameters and sparse annotations
-# make sense.
+# and existing typedefs make sense.
 		if ($line =~ /\btypedef\s/ &&
 		    $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
 		    $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
 		    $line !~ /\b$typeTypedefs\b/ &&
 		    $line !~ /\b__bitwise(?:__|)\b/) {
-			WARN("NEW_TYPEDEFS",
-			     "do not add new typedefs\n" . $herecurr);
+			# check if $line is diff-like
+			if (substr($rawlines[$linenr - 3], 0, 1) eq '-') {
+				my $oldline3 = substr($rawlines[$linenr - 3], 1);
+				# check if typedef already existed
+				if ($line !~ /$oldline3/) {
+					WARN("NEW_TYPEDEFS",
+					     "do not add new typedefs\n" . $herecurr);
+				}
+			} else {
+				WARN("NEW_TYPEDEFS",
+				     "do not add new typedefs\n" . $herecurr);
+			}
 		}
 
 # * goes on variable not on type
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 3 lines · Greg Donald

Fixing an "open brace '{' following struct go on the same line" error causes a false positive warning "do not add new typedefs". Fix existing typedef false positive warning.

This doesn't work.
The matching deleted line can be any number of lines above.

Quoted 37 lines
---
 scripts/checkpatch.pl | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +13 -3
index 4d08b39..eafe5e7 100755
@@ -3081,14 +3081,24 @@ sub process {
 		}
 
 # check for new typedefs, only function parameters and sparse annotations
-# make sense.
+# and existing typedefs make sense.
 		if ($line =~ /\btypedef\s/ &&
 		    $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
 		    $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
 		    $line !~ /\b$typeTypedefs\b/ &&
 		    $line !~ /\b__bitwise(?:__|)\b/) {
-			WARN("NEW_TYPEDEFS",
-			     "do not add new typedefs\n" . $herecurr);
+			# check if $line is diff-like
+			if (substr($rawlines[$linenr - 3], 0, 1) eq '-') {
+				my $oldline3 = substr($rawlines[$linenr - 3], 1);
+				# check if typedef already existed
+				if ($line !~ /$oldline3/) {
+					WARN("NEW_TYPEDEFS",
+					     "do not add new typedefs\n" . $herecurr);
+				}
+			} else {
+				WARN("NEW_TYPEDEFS",
+				     "do not add new typedefs\n" . $herecurr);
+			}
 		}
 
 # * goes on variable not on type
#2 lore raw
Quoted 7 lines · Joe Perches
Quoted 3 lines · Greg Donald

Fixing an "open brace '{' following struct go on the same line" error causes a false positive warning "do not add new typedefs". Fix existing typedef false positive warning.

This doesn't work.
The matching deleted line can be any number of lines above.

But this fixes the most common case:

-typedef struct ksock_proto
-{
+typedef struct ksock_proto {

If you're wanting to check more than just $rawlines[$linenr - 3], how far above does it make sense to go? From what I'm seeing the '{' is usually on the next line.

Signature · 1 line
Greg Donald
maintainer
#3 lore raw
Quoted 11 lines · Greg Donald
Quoted 7 lines · Joe Perches
Quoted 3 lines · Greg Donald

Fixing an "open brace '{' following struct go on the same line" error causes a false positive warning "do not add new typedefs". Fix existing typedef false positive warning.

This doesn't work.
The matching deleted line can be any number of lines above.

But this fixes the most common case:

Review

Quoted 3 lines
(quoted diff) +1 -2
-typedef struct ksock_proto
-{
+typedef struct ksock_proto {

Meh. I think people are smart enough to work
out that this is not a new typedef.

Quoted 3 lines

If you're wanting to check more than just $rawlines[$linenr - 3], how far above does it make sense to go? From what I'm seeing the '{' is usually on the next line.

It's not the most common case working, it's the
generic case working.

It's in a large block being changed, it doesn't work. If it's checking a file, there are no "-" lines.