Merge tag 'arm-soc-drivers-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / scripts / checkpatch.pl
index d7616a6..0008530 100755 (executable)
@@ -3033,6 +3033,15 @@ sub process {
                        $commit_log_possible_stack_dump = 0;
                }
 
+# Check for lines starting with a #
+               if ($in_commit_log && $line =~ /^#/) {
+                       if (WARN("COMMIT_COMMENT_SYMBOL",
+                                "Commit log lines starting with '#' are dropped by git as comments\n" . $herecurr) &&
+                           $fix) {
+                               $fixed[$fixlinenr] =~ s/^/ /;
+                       }
+               }
+
 # Check for git id commit length and improperly formed commit descriptions
                if ($in_commit_log && !$commit_log_possible_stack_dump &&
                    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
@@ -3173,15 +3182,18 @@ sub process {
 # Check for various typo / spelling mistakes
                if (defined($misspellings) &&
                    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
-                       while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
+                       while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
                                my $typo = $1;
+                               my $blank = copy_spacing($rawline);
+                               my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
+                               my $hereptr = "$hereline$ptr\n";
                                my $typo_fix = $spelling_fix{lc($typo)};
                                $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
                                $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
                                my $msg_level = \&WARN;
                                $msg_level = \&CHK if ($file);
                                if (&{$msg_level}("TYPO_SPELLING",
-                                                 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
+                                                 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) &&
                                    $fix) {
                                        $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
                                }
@@ -4531,16 +4543,23 @@ sub process {
                             "printk() should include KERN_<LEVEL> facility level\n" . $herecurr);
                }
 
-               if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
-                       my $orig = $1;
+# prefer variants of (subsystem|netdev|dev|pr)_<level> to printk(KERN_<LEVEL>
+               if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
+                       my $printk = $1;
+                       my $modifier = $2;
+                       my $orig = $3;
+                       $modifier = "" if (!defined($modifier));
                        my $level = lc($orig);
                        $level = "warn" if ($level eq "warning");
                        my $level2 = $level;
                        $level2 = "dbg" if ($level eq "debug");
+                       $level .= $modifier;
+                       $level2 .= $modifier;
                        WARN("PREFER_PR_LEVEL",
-                            "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(...  to printk(KERN_$orig ...\n" . $herecurr);
+                            "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(...  to $printk(KERN_$orig ...\n" . $herecurr);
                }
 
+# prefer dev_<level> to dev_printk(KERN_<LEVEL>
                if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
                        my $orig = $1;
                        my $level = lc($orig);
@@ -6102,6 +6121,28 @@ sub process {
                             "Avoid logging continuation uses where feasible\n" . $herecurr);
                }
 
+# check for unnecessary use of %h[xudi] and %hh[xudi] in logging functions
+               if (defined $stat &&
+                   $line =~ /\b$logFunctions\s*\(/ &&
+                   index($stat, '"') >= 0) {
+                       my $lc = $stat =~ tr@\n@@;
+                       $lc = $lc + $linenr;
+                       my $stat_real = get_stat_real($linenr, $lc);
+                       pos($stat_real) = index($stat_real, '"');
+                       while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) {
+                               my $pspec = $1;
+                               my $h = $2;
+                               my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
+                               if (WARN("UNNECESSARY_MODIFIER",
+                                        "Integer promotion: Using '$h' in '$pspec' is unnecessary\n" . "$here\n$stat_real\n") &&
+                                   $fix && $fixed[$fixlinenr + $lineoff] =~ /^\+/) {
+                                       my $nspec = $pspec;
+                                       $nspec =~ s/h//g;
+                                       $fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/;
+                               }
+                       }
+               }
+
 # check for mask then right shift without a parentheses
                if ($perl_version_ok &&
                    $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&