Merge git://git.infradead.org/users/eparis/audit
[firefly-linux-kernel-4.4.55.git] / scripts / checkpatch.pl
index 23d55bfcb5af68b4731274f4d4b974e9ff7802c4..61090e0ff613aefeb5429c26d4efc7775ad97739 100755 (executable)
@@ -1769,11 +1769,11 @@ sub process {
                # extract the filename as it passes
                if ($line =~ /^diff --git.*?(\S+)$/) {
                        $realfile = $1;
-                       $realfile =~ s@^([^/]*)/@@;
+                       $realfile =~ s@^([^/]*)/@@ if (!$file);
                        $in_commit_log = 0;
                } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
                        $realfile = $1;
-                       $realfile =~ s@^([^/]*)/@@;
+                       $realfile =~ s@^([^/]*)/@@ if (!$file);
                        $in_commit_log = 0;
 
                        $p1_prefix = $1;
@@ -1962,6 +1962,18 @@ sub process {
                        $rpt_cleaners = 1;
                }
 
+# Check for FSF mailing addresses.
+               if ($rawline =~ /You should have received a copy/ ||
+                   $rawline =~ /write to the Free Software/ ||
+                   $rawline =~ /59 Temple Place/ ||
+                   $rawline =~ /51 Franklin Street/) {
+                       my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+                       my $msg_type = \&ERROR;
+                       $msg_type = \&CHK if ($file);
+                       &{$msg_type}("FSF_MAILING_ADDRESS",
+                               "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
+               }
+
 # check for Kconfig help text having a real description
 # Only applies when adding the entry originally, after that we do not have
 # sufficient context to determine whether it is indeed long enough.
@@ -3221,21 +3233,10 @@ sub process {
                }
 
 # Return is not a function.
-               if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) {
+               if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
                        my $spacing = $1;
-                       my $value = $2;
-
-                       # Flatten any parentheses
-                       $value =~ s/\(/ \(/g;
-                       $value =~ s/\)/\) /g;
-                       while ($value =~ s/\[[^\[\]]*\]/1/ ||
-                              $value !~ /(?:$Ident|-?$Constant)\s*
-                                            $Compare\s*
-                                            (?:$Ident|-?$Constant)/x &&
-                              $value =~ s/\([^\(\)]*\)/1/) {
-                       }
-#print "value<$value>\n";
-                       if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
+                       if ($^V && $^V ge 5.10.0 &&
+                           $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
                                ERROR("RETURN_PARENTHESES",
                                      "return is not a function, parentheses are not required\n" . $herecurr);
 
@@ -3244,6 +3245,7 @@ sub process {
                                      "space required before the open parenthesis '('\n" . $herecurr);
                        }
                }
+
 # Return of what appears to be an errno should normally be -'ve
                if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
                        my $name = $1;
@@ -3850,8 +3852,8 @@ sub process {
 # check for memory barriers without a comment.
                if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
                        if (!ctx_has_comment($first_line, $linenr)) {
-                               CHK("MEMORY_BARRIER",
-                                   "memory barrier without comment\n" . $herecurr);
+                               WARN("MEMORY_BARRIER",
+                                    "memory barrier without comment\n" . $herecurr);
                        }
                }
 # check of hardware specific defines
@@ -3875,7 +3877,8 @@ sub process {
                }
 
 # Check for __inline__ and __inline, prefer inline
-               if ($line =~ /\b(__inline__|__inline)\b/) {
+               if ($realfile !~ m@\binclude/uapi/@ &&
+                   $line =~ /\b(__inline__|__inline)\b/) {
                        if (WARN("INLINE",
                                 "plain inline is preferred over $1\n" . $herecurr) &&
                            $fix) {
@@ -3885,19 +3888,22 @@ sub process {
                }
 
 # Check for __attribute__ packed, prefer __packed
-               if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
+               if ($realfile !~ m@\binclude/uapi/@ &&
+                   $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
                        WARN("PREFER_PACKED",
                             "__packed is preferred over __attribute__((packed))\n" . $herecurr);
                }
 
 # Check for __attribute__ aligned, prefer __aligned
-               if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
+               if ($realfile !~ m@\binclude/uapi/@ &&
+                   $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
                        WARN("PREFER_ALIGNED",
                             "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
                }
 
 # Check for __attribute__ format(printf, prefer __printf
-               if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
+               if ($realfile !~ m@\binclude/uapi/@ &&
+                   $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
                        if (WARN("PREFER_PRINTF",
                                 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
                            $fix) {
@@ -3907,7 +3913,8 @@ sub process {
                }
 
 # Check for __attribute__ format(scanf, prefer __scanf
-               if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
+               if ($realfile !~ m@\binclude/uapi/@ &&
+                   $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
                        if (WARN("PREFER_SCANF",
                                 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
                            $fix) {
@@ -4012,6 +4019,23 @@ sub process {
                        }
                }
 
+# check for naked sscanf
+               if ($^V && $^V ge 5.10.0 &&
+                   defined $stat &&
+                   $stat =~ /\bsscanf\b/ &&
+                   ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
+                    $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
+                    $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);
+                       }
+                       WARN("NAKED_SSCANF",
+                            "unchecked sscanf return value\n" . "$here\n$stat_real\n");
+               }
+
 # check for new externs in .h files.
                if ($realfile =~ /\.h$/ &&
                    $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {