Skip to contentSkip to conversation

checkpatch: Miscellaneous cleanups

PATCH New Joe Perches 1 participant 6 messages Feb 2, 2015 Checkpatch

lore
Share & tools
lore

Joe Perches

author maintainer
#0 lore raw

cover checkpatch: Miscellaneous cleanups

Heba Aamer (1):
checkpatch: Improve seq_print->seq_puts suggestion

Joe Perches (4):
checkpatch: Improve "no space necessary after cast" test
checkpatch: Neaten printk_ratelimited message position
checkpatch: Add --strict test for spaces around arithmetic
checkpatch: Make sure a commit reference description uses parentheses

 scripts/checkpatch.pl | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.2
author maintainer
#1 lore raw

PATCH 1/5 checkpatch: Improve seq_print->seq_puts suggestion

From: Heba Aamer <[email protected]>

Improve the format specifier test by removing any %% before looking for any remaining % format specifier.

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index 059c032..7f1804e 100755
@@ -4854,7 +4854,8 @@ sub process {
 # check for seq_printf uses that could be seq_puts
 		if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
 			my $fmt = get_quoted_string($line, $rawline);
-			if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
+			$fmt =~ s/%%//g;
+			if ($fmt !~ /%/) {
 				if (WARN("PREFER_SEQ_PUTS",
 					 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
 				    $fix) {
Signature · 1 line
2.1.2
author maintainer
#2 lore raw

PATCH 2/5 checkpatch: Improve "no space necessary after cast" test

In reply to Joe Perches

Code like:

	if (a < sizeof(<type>) &&
and
	{ .len = sizeof(<type>) },

incorrectly emits that warning, so add more exceptions to avoid the warning.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 7f1804e..a9baaab 100755
@@ -2541,7 +2541,7 @@ sub process {
 			}
 		}
 
-		if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;\({\[\<\>])/ &&
+		if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ &&
 		    (!defined($1) || $1 !~ /sizeof\s*/)) {
 			if (CHK("SPACING",
 				"No space is necessary after a cast\n" . $herecurr) &&
Signature · 1 line
2.1.2
author maintainer
#3 lore raw

PATCH 3/5 checkpatch: Neaten printk_ratelimited message position

In reply to Joe Perches

Just neatening...

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index a9baaab..bf23264 100755
@@ -3243,7 +3243,7 @@ sub process {
 # check for uses of printk_ratelimit
 		if ($line =~ /\bprintk_ratelimit\s*\(/) {
 			WARN("PRINTK_RATELIMITED",
-"Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
+			     "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
 		}
 
 # printk should use KERN_* levels.  Note that follow on printk's on the
Signature · 1 line
2.1.2
author maintainer
#4 lore raw

PATCH 4/5 checkpatch: Add --strict test for spaces around arithmetic

In reply to Joe Perches

Some prefer code to have spaces around arithmetic so instead of:

        a = b*c+d;
suggest
        a = b * c + d;
---
 scripts/checkpatch.pl | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +16 -1
index bf23264..32bd31c 100755
@@ -3689,7 +3689,22 @@ sub process {
 					 $op eq '*' or $op eq '/' or
 					 $op eq '%')
 				{
-					if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
+					if ($check) {
+						if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
+							if (CHK("SPACING",
+								"spaces preferred around that '$op' $at\n" . $hereptr)) {
+								$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+								$fix_elements[$n + 2] =~ s/^\s+//;
+								$line_fixed = 1;
+							}
+						} elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
+							if (CHK("SPACING",
+								"space preferred before that '$op' $at\n" . $hereptr)) {
+								$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
+								$line_fixed = 1;
+							}
+						}
+					} elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
 						if (ERROR("SPACING",
 							  "need consistent spacing around '$op' $at\n" . $hereptr)) {
 							$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
Signature · 1 line
2.1.2
author maintainer
#5 lore raw

PATCH 5/5 checkpatch: Make sure a commit reference description uses parentheses

In reply to Joe Perches

The preferred style for a commit reference in a commit log is:

    commit <foo> ("<title line>")

A recent commit removed this check for parentheses. Add it back.

---
 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +5 -1
index 32bd31c..3642b0d 100755
@@ -2191,6 +2191,7 @@ sub process {
 			my $case = 1;
 			my $space = 1;
 			my $hasdesc = 0;
+			my $hasparens = 0;
 			my $id = '0123456789ab';
 			my $orig_desc = "commit description";
 			my $description = "";
@@ -2201,10 +2202,12 @@ sub process {
 			$case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
 			if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
 				$orig_desc = $1;
+				$hasparens = 1;
 			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
 				 defined $rawlines[$linenr] &&
 				 $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
 				$orig_desc = $1;
+				$hasparens = 1;
 			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
 				 defined $rawlines[$linenr] &&
 				 $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
@@ -2212,12 +2215,13 @@ sub process {
 				$orig_desc = $1;
 				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
 				$orig_desc .= " " . $1;
+				$hasparens = 1;
 			}
 
 			($id, $description) = git_commit_info($orig_commit,
 							      $id, $orig_desc);
 
-			if ($short || $long || $space || $case || ($orig_desc ne $description)) {
+			if ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens) {
 				ERROR("GIT_COMMIT_ID",
 				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
 			}
Signature · 1 line
2.1.2