Merge tag 'cpuinit-v4.1-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg...
[sfrench/cifs-2.6.git] / scripts / checkpatch.pl
index ef24f92e10e5fec3586961481d83a96e31ddf420..90e1edc8dd42fbfba3c31d03214f99d4e3c361b4 100755 (executable)
@@ -203,7 +203,7 @@ sub hash_save_array_words {
 sub hash_show_words {
        my ($hashRef, $prefix) = @_;
 
-       if ($quiet == 0 && keys %$hashRef) {
+       if (keys %$hashRef) {
                print "\nNOTE: $prefix message types:";
                foreach my $word (sort keys %$hashRef) {
                        print " $word";
@@ -770,6 +770,9 @@ for my $filename (@ARGV) {
 }
 
 if (!$quiet) {
+       hash_show_words(\%use_type, "Used");
+       hash_show_words(\%ignore_type, "Ignored");
+
        if ($^V lt 5.10.0) {
                print << "EOM"
 
@@ -1954,6 +1957,7 @@ sub process {
        my $in_header_lines = $file ? 0 : 1;
        my $in_commit_log = 0;          #Scanning lines before patch
        my $commit_log_long_line = 0;
+       my $commit_log_has_diff = 0;
        my $reported_maintainer_file = 0;
        my $non_utf8_charset = 0;
 
@@ -2087,7 +2091,8 @@ sub process {
                my $rawline = $rawlines[$linenr - 1];
 
 #extract the line range in the file after the patch is applied
-               if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+               if (!$in_commit_log &&
+                   $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
                        $is_patch = 1;
                        $first_line = $linenr + 1;
                        $realline=$1-1;
@@ -2181,6 +2186,17 @@ sub process {
 
                $cnt_lines++ if ($realcnt != 0);
 
+# Check if the commit log has what seems like a diff which can confuse patch
+               if ($in_commit_log && !$commit_log_has_diff &&
+                   (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
+                     $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
+                    $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+                    $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+                       ERROR("DIFF_IN_COMMIT_MSG",
+                             "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
+                       $commit_log_has_diff = 1;
+               }
+
 # Check for incorrect file permissions
                if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
                        my $permhere = $here . "FILE: $realfile\n";
@@ -5132,7 +5148,7 @@ sub process {
 # Check for misused memsets
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&
-                   $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
+                   $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
 
                        my $ms_addr = $2;
                        my $ms_val = $7;
@@ -5149,14 +5165,46 @@ sub process {
 
 # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
                if ($^V && $^V ge 5.10.0 &&
-                   $line =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) {
+                   defined $stat &&
+                   $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
                        if (WARN("PREFER_ETHER_ADDR_COPY",
-                                "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . $herecurr) &&
+                                "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") &&
                            $fix) {
                                $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
                        }
                }
 
+# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
+               if ($^V && $^V ge 5.10.0 &&
+                   defined $stat &&
+                   $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+                       WARN("PREFER_ETHER_ADDR_EQUAL",
+                            "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
+               }
+
+# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
+# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
+               if ($^V && $^V ge 5.10.0 &&
+                   defined $stat &&
+                   $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+
+                       my $ms_val = $7;
+
+                       if ($ms_val =~ /^(?:0x|)0+$/i) {
+                               if (WARN("PREFER_ETH_ZERO_ADDR",
+                                        "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
+                                   $fix) {
+                                       $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
+                               }
+                       } elsif ($ms_val =~ /^(?:0xff|255)$/i) {
+                               if (WARN("PREFER_ETH_BROADCAST_ADDR",
+                                        "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
+                                   $fix) {
+                                       $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
+                               }
+                       }
+               }
+
 # typecasts on min/max could be min_t/max_t
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&
@@ -5594,6 +5642,24 @@ sub process {
                                }
                        }
                }
+
+# validate content of MODULE_LICENSE against list from include/linux/module.h
+               if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
+                       my $extracted_string = get_quoted_string($line, $rawline);
+                       my $valid_licenses = qr{
+                                               GPL|
+                                               GPL\ v2|
+                                               GPL\ and\ additional\ rights|
+                                               Dual\ BSD/GPL|
+                                               Dual\ MIT/GPL|
+                                               Dual\ MPL/GPL|
+                                               Proprietary
+                                       }x;
+                       if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) {
+                               WARN("MODULE_LICENSE",
+                                    "unknown module license " . $extracted_string . "\n" . $herecurr);
+                       }
+               }
        }
 
        # If we have no input at all, then there is nothing to report on
@@ -5614,7 +5680,7 @@ sub process {
                exit(0);
        }
 
-       if (!$is_patch) {
+       if (!$is_patch && $file !~ /cover-letter\.patch$/) {
                ERROR("NOT_UNIFIED_DIFF",
                      "Does not appear to be a unified-diff format patch\n");
        }
@@ -5644,9 +5710,6 @@ EOM
                }
        }
 
-       hash_show_words(\%use_type, "Used");
-       hash_show_words(\%ignore_type, "Ignored");
-
        if ($clean == 0 && $fix &&
            ("@rawlines" ne "@fixed" ||
             $#fixed_inserted >= 0 || $#fixed_deleted >= 0)) {