Skip to contentSkip to conversation

checkpatch: suppress false long-line warining

PATCH Superseded Yury Norov 2 participants 2 messages Nov 28, 2017 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH 1/1 checkpatch: suppress false long-line warining

For DOS-formatted patches, extra ^M symbol at the end of line increases overall line length by 1.

It triggers unneeded warning if line is exactly 80 chars length. This patch fixes it.

Discovered in discussion to this patch:
https://lkml.org/lkml/2017/11/25/24

---
 scripts/checkpatch.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
scripts/checkpatch.pl +12 -4
index 95cda3ecc66b..a14d36f7df13 100755
@@ -59,6 +59,7 @@ my $conststructsfile = "$D/const_structs.checkpatch";
 my $typedefsfile = "";
 my $color = "auto";
 my $allow_c99_comments = 1;
+my $is_dos_line;
 
 sub help {
 	my ($exitcode) = @_;
@@ -2731,7 +2732,9 @@ sub process {
 		next if (!$hunk_line || $line =~ /^-/);
 
 #trailing whitespace
+		$is_dos_line = 0;
 		if ($line =~ /^\+.*\015/) {
+			$is_dos_line = 1 if (!$fix_inplace);
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
 			if (ERROR("DOS_LINE_ENDINGS",
 				  "DOS line endings\n" . $herevet) &&
@@ -2884,7 +2887,12 @@ sub process {
 # if LONG_LINE is ignored, the other 2 types are also ignored
 #
 
-		if ($line =~ /^\+/ && $length > $max_line_length) {
+		# If DOS line detected, additional ^M symbol at the end of
+		# line increases line length, so increase max_line_length
+		# accordingly.
+		my $__max_line_length = $max_line_length + $is_dos_line;
+
+		if ($line =~ /^\+/ && $length > $__max_line_length) {
 			my $msg_type = "LONG_LINE";
 
 			# Check the allowed long line types first
@@ -2892,7 +2900,7 @@ sub process {
 			# logging functions that end in a string that starts
 			# before $max_line_length
 			if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
-			    length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+			    length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $__max_line_length) {
 				$msg_type = "";
 
 			# lines with only strings (w/ possible termination)
@@ -2910,12 +2918,12 @@ sub process {
 
 			# a comment starts before $max_line_length
 			} elsif ($line =~ /($;[\s$;]*)$/ &&
-				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $__max_line_length) {
 				$msg_type = "LONG_LINE_COMMENT"
 
 			# a quoted string starts before $max_line_length
 			} elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
-				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $__max_line_length) {
 				$msg_type = "LONG_LINE_STRING"
 			}
 
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 5 lines · Yury Norov

For DOS-formatted patches, extra ^M symbol at the end of line increases overall line length by 1.

It triggers unneeded warning if line is exactly 80 chars length. This patch fixes it.

It's may be simpler to just remove the \015 from the input line

scripts/checkpatch.pl

Quoted 9 lines

Discovered in discussion to this patch:
https://lkml.org/lkml/2017/11/25/24

---
 scripts/checkpatch.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
scripts/checkpatch.pl +0 -0

[]

Quoted 9 lines
scripts/checkpatch.pl +1 -0
@@ -59,6 +59,7 @@ my $conststructsfile = "$D/const_structs.checkpatch";
 my $typedefsfile = "";
 my $color = "auto";
 my $allow_c99_comments = 1;
+my $is_dos_line;
 
 sub help {
 	my ($exitcode) = @_;

scripts/checkpatch.pl sub process { · line 2736

Quoted 5 lines
scripts/checkpatch.pl +1 -0
@@ -2731,7 +2732,9 @@ sub process {
 		next if (!$hunk_line || $line =~ /^-/);
 
 #trailing whitespace
+		$is_dos_line = 0;
 		if ($line =~ /^\+.*\015$/) {

Maybe:

			$line =~ /\015$//;
			$length--;

and nothing else

Quoted 42 lines
scripts/checkpatch.pl +10 -4
+			$is_dos_line = 1 if (!$fix_inplace);
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
 			if (ERROR("DOS_LINE_ENDINGS",
 				  "DOS line endings\n" . $herevet) &&
@@ -2884,7 +2887,12 @@ sub process {
 # if LONG_LINE is ignored, the other 2 types are also ignored
 #
 
-		if ($line =~ /^\+/ && $length > $max_line_length) {
+		# If DOS line detected, additional ^M symbol at the end of
+		# line increases line length, so increase max_line_length
+		# accordingly.
+		my $__max_line_length = $max_line_length + $is_dos_line;
+
+		if ($line =~ /^\+/ && $length > $__max_line_length) {
 			my $msg_type = "LONG_LINE";
 
 			# Check the allowed long line types first
@@ -2892,7 +2900,7 @@ sub process {
 			# logging functions that end in a string that starts
 			# before $max_line_length
 			if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
-			    length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+			    length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $__max_line_length) {
 				$msg_type = "";
 
 			# lines with only strings (w/ possible termination)
@@ -2910,12 +2918,12 @@ sub process {
 
 			# a comment starts before $max_line_length
 			} elsif ($line =~ /($;[\s$;]*)$/ &&
-				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $__max_line_length) {
 				$msg_type = "LONG_LINE_COMMENT"
 
 			# a quoted string starts before $max_line_length
 			} elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
-				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $__max_line_length) {
 				$msg_type = "LONG_LINE_STRING"
 			}