checkpatch: two spelling fixes
[sfrench/cifs-2.6.git] / scripts / checkpatch.pl
index 43322bd8f66ab496ba5a8d4f0396814924e9a91b..5fe361e1ed5e46451fe87ac7ecb76c01de798c04 100755 (executable)
@@ -1218,7 +1218,7 @@ sub sanitise_line {
        for ($off = 1; $off < length($line); $off++) {
                $c = substr($line, $off, 1);
 
-               # Comments we are wacking completly including the begin
+               # Comments we are whacking completely including the begin
                # and end, all to $;.
                if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
                        $sanitise_quote = '*/';
@@ -1298,6 +1298,7 @@ sub sanitise_line {
 sub get_quoted_string {
        my ($line, $rawline) = @_;
 
+       return "" if (!defined($line) || !defined($rawline));
        return "" if ($line !~ m/($String)/g);
        return substr($rawline, $-[0], $+[0] - $-[0]);
 }
@@ -1645,6 +1646,28 @@ sub raw_line {
        return $line;
 }
 
+sub get_stat_real {
+       my ($linenr, $lc) = @_;
+
+       my $stat_real = raw_line($linenr, 0);
+       for (my $count = $linenr + 1; $count <= $lc; $count++) {
+               $stat_real = $stat_real . "\n" . raw_line($count, 0);
+       }
+
+       return $stat_real;
+}
+
+sub get_stat_here {
+       my ($linenr, $cnt, $here) = @_;
+
+       my $herectx = $here . "\n";
+       for (my $n = 0; $n < $cnt; $n++) {
+               $herectx .= raw_line($linenr, $n) . "\n";
+       }
+
+       return $herectx;
+}
+
 sub cat_vet {
        my ($vet) = @_;
        my ($res, $coded);
@@ -4956,12 +4979,8 @@ sub process {
                        #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
 
                        $ctx =~ s/\n*$//;
-                       my $herectx = $here . "\n";
                        my $stmt_cnt = statement_rawlines($ctx);
-
-                       for (my $n = 0; $n < $stmt_cnt; $n++) {
-                               $herectx .= raw_line($linenr, $n) . "\n";
-                       }
+                       my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
 
                        if ($dstat ne '' &&
                            $dstat !~ /^(?:$Ident|-?$Constant),$/ &&                    # 10, // foo(),
@@ -5033,12 +5052,9 @@ sub process {
 # check for macros with flow control, but without ## concatenation
 # ## concatenation is commonly a macro that defines a function so ignore those
                        if ($has_flow_statement && !$has_arg_concat) {
-                               my $herectx = $here . "\n";
                                my $cnt = statement_rawlines($ctx);
+                               my $herectx = get_stat_here($linenr, $cnt, $here);
 
-                               for (my $n = 0; $n < $cnt; $n++) {
-                                       $herectx .= raw_line($linenr, $n) . "\n";
-                               }
                                WARN("MACRO_WITH_FLOW_CONTROL",
                                     "Macros with flow control statements should be avoided\n" . "$herectx");
                        }
@@ -5078,11 +5094,7 @@ sub process {
 
                                $ctx =~ s/\n*$//;
                                my $cnt = statement_rawlines($ctx);
-                               my $herectx = $here . "\n";
-
-                               for (my $n = 0; $n < $cnt; $n++) {
-                                       $herectx .= raw_line($linenr, $n) . "\n";
-                               }
+                               my $herectx = get_stat_here($linenr, $cnt, $here);
 
                                if (($stmts =~ tr/;/;/) == 1 &&
                                    $stmts !~ /^\s*(if|while|for|switch)\b/) {
@@ -5096,11 +5108,7 @@ sub process {
                        } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
                                $ctx =~ s/\n*$//;
                                my $cnt = statement_rawlines($ctx);
-                               my $herectx = $here . "\n";
-
-                               for (my $n = 0; $n < $cnt; $n++) {
-                                       $herectx .= raw_line($linenr, $n) . "\n";
-                               }
+                               my $herectx = get_stat_here($linenr, $cnt, $here);
 
                                WARN("TRAILING_SEMICOLON",
                                     "macros should not use a trailing semicolon\n" . "$herectx");
@@ -5223,12 +5231,8 @@ sub process {
                                }
                        }
                        if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
-                               my $herectx = $here . "\n";
                                my $cnt = statement_rawlines($block);
-
-                               for (my $n = 0; $n < $cnt; $n++) {
-                                       $herectx .= raw_line($linenr, $n) . "\n";
-                               }
+                               my $herectx = get_stat_here($linenr, $cnt, $here);
 
                                WARN("BRACES",
                                     "braces {} are not necessary for single statement blocks\n" . $herectx);
@@ -5804,36 +5808,50 @@ sub process {
                        }
                }
 
-               # check for vsprintf extension %p<foo> misuses
+# check for vsprintf extension %p<foo> misuses
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&
                    $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
                    $1 !~ /^_*volatile_*$/) {
-                       my $bad_extension = "";
+                       my $specifier;
+                       my $extension;
+                       my $bad_specifier = "";
+                       my $stat_real;
+
                        my $lc = $stat =~ tr@\n@@;
                        $lc = $lc + $linenr;
                        for (my $count = $linenr; $count <= $lc; $count++) {
                                my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
                                $fmt =~ s/%%//g;
-                               if ($fmt =~ /(\%[\*\d\.]*p(?![\WSsBKRraEhMmIiUDdgVCbGNOx]).)/) {
-                                       $bad_extension = $1;
-                                       last;
-                               }
-                       }
-                       if ($bad_extension ne "") {
-                               my $stat_real = raw_line($linenr, 0);
-                               my $ext_type = "Invalid";
-                               my $use = "";
-                               for (my $count = $linenr + 1; $count <= $lc; $count++) {
-                                       $stat_real = $stat_real . "\n" . raw_line($count, 0);
+
+                               while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
+                                       $specifier = $1;
+                                       $extension = $2;
+                                       if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) {
+                                               $bad_specifier = $specifier;
+                                               last;
+                                       }
+                                       if ($extension eq "x" && !defined($stat_real)) {
+                                               if (!defined($stat_real)) {
+                                                       $stat_real = get_stat_real($linenr, $lc);
+                                               }
+                                               WARN("VSPRINTF_SPECIFIER_PX",
+                                                    "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n");
+                                       }
                                }
-                               if ($bad_extension =~ /p[Ff]/) {
-                                       $ext_type = "Deprecated";
-                                       $use = " - use %pS instead";
-                                       $use =~ s/pS/ps/ if ($bad_extension =~ /pf/);
+                               if ($bad_specifier ne "") {
+                                       my $stat_real = get_stat_real($linenr, $lc);
+                                       my $ext_type = "Invalid";
+                                       my $use = "";
+                                       if ($bad_specifier =~ /p[Ff]/) {
+                                               $ext_type = "Deprecated";
+                                               $use = " - use %pS instead";
+                                               $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
+                                       }
+
+                                       WARN("VSPRINTF_POINTER_EXTENSION",
+                                            "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n");
                                }
-                               WARN("VSPRINTF_POINTER_EXTENSION",
-                                    "$ext_type vsprintf pointer extension '$bad_extension'$use\n" . "$here\n$stat_real\n");
                        }
                }
 
@@ -5946,10 +5964,7 @@ sub process {
                     $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
                        my $lc = $stat =~ tr@\n@@;
                        $lc = $lc + $linenr;
-                       my $stat_real = raw_line($linenr, 0);
-                       for (my $count = $linenr + 1; $count <= $lc; $count++) {
-                               $stat_real = $stat_real . "\n" . raw_line($count, 0);
-                       }
+                       my $stat_real = get_stat_real($linenr, $lc);
                        WARN("NAKED_SSCANF",
                             "unchecked sscanf return value\n" . "$here\n$stat_real\n");
                }
@@ -5960,10 +5975,7 @@ sub process {
                    $line =~ /\bsscanf\b/) {
                        my $lc = $stat =~ tr@\n@@;
                        $lc = $lc + $linenr;
-                       my $stat_real = raw_line($linenr, 0);
-                       for (my $count = $linenr + 1; $count <= $lc; $count++) {
-                               $stat_real = $stat_real . "\n" . raw_line($count, 0);
-                       }
+                       my $stat_real = get_stat_real($linenr, $lc);
                        if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
                                my $format = $6;
                                my $count = $format =~ tr@%@%@;
@@ -6093,12 +6105,9 @@ sub process {
                        }
                        if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
                            !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
-                               my $ctx = '';
-                               my $herectx = $here . "\n";
                                my $cnt = statement_rawlines($stat);
-                               for (my $n = 0; $n < $cnt; $n++) {
-                                       $herectx .= raw_line($linenr, $n) . "\n";
-                               }
+                               my $herectx = get_stat_here($linenr, $cnt, $here);
+
                                if (WARN("ALLOC_WITH_MULTIPLY",
                                         "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
                                    $cnt == 1 &&
@@ -6181,12 +6190,9 @@ sub process {
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&
                    $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
-                       my $ctx = '';
-                       my $herectx = $here . "\n";
                        my $cnt = statement_rawlines($stat);
-                       for (my $n = 0; $n < $cnt; $n++) {
-                               $herectx .= raw_line($linenr, $n) . "\n";
-                       }
+                       my $herectx = get_stat_here($linenr, $cnt, $here);
+
                        WARN("DEFAULT_NO_BREAK",
                             "switch default: should use break\n" . $herectx);
                }
@@ -6397,10 +6403,7 @@ sub process {
 
                                my $lc = $stat =~ tr@\n@@;
                                $lc = $lc + $linenr;
-                               my $stat_real = raw_line($linenr, 0);
-                               for (my $count = $linenr + 1; $count <= $lc; $count++) {
-                                       $stat_real = $stat_real . "\n" . raw_line($count, 0);
-                               }
+                               my $stat_real = get_stat_real($linenr, $lc);
 
                                my $skip_args = "";
                                if ($arg_pos > 1) {