checkpatch: Miscellaneous cleanups
Joe Perches
maintainercover 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
Joe Perches
maintainerPATCH 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
@@ -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
Joe Perches
maintainerPATCH 2/5 checkpatch: Improve "no space necessary after cast" test
In reply to Joe PerchesCode 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
@@ -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
Joe Perches
maintainerPATCH 3/5 checkpatch: Neaten printk_ratelimited message position
In reply to Joe PerchesJust neatening...
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -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
Joe Perches
maintainerPATCH 4/5 checkpatch: Add --strict test for spaces around arithmetic
In reply to Joe PerchesSome 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
@@ -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
Joe Perches
maintainerPATCH 5/5 checkpatch: Make sure a commit reference description uses parentheses
In reply to Joe PerchesThe 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
@@ -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