i2c: pca-platform: fix broken email address
[cascardo/linux.git] / scripts / checkpatch.pl
index 5748c35..89b1df4 100755 (executable)
@@ -323,6 +323,7 @@ our $Operators      = qr{
 
 our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
 
+our $BasicType;
 our $NonptrType;
 our $NonptrTypeMisordered;
 our $NonptrTypeWithAttr;
@@ -514,6 +515,11 @@ sub build_types {
        my $Misordered = "(?x:  \n" . join("|\n  ", @typeListMisordered) . "\n)";
        my $allWithAttr = "(?x:  \n" . join("|\n  ", @typeListWithAttr) . "\n)";
        $Modifier       = qr{(?:$Attribute|$Sparse|$mods)};
+       $BasicType      = qr{
+                               (?:$typeOtherOSTypedefs\b)|
+                               (?:$typeTypedefs\b)|
+                               (?:${all}\b)
+               }x;
        $NonptrType     = qr{
                        (?:$Modifier\s+|const\s+)*
                        (?:
@@ -1684,7 +1690,7 @@ sub fix_inserted_deleted_lines {
        foreach my $old_line (@{$linesRef}) {
                my $save_line = 1;
                my $line = $old_line;   #don't modify the array
-               if ($line =~ /^(?:\+\+\+\|\-\-\-)\s+\S+/) {     #new filename
+               if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) {      #new filename
                        $delta_offset = 0;
                } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) {    #new hunk
                        $range_last_linenr = $new_linenr;
@@ -1892,6 +1898,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 $reported_maintainer_file = 0;
        my $non_utf8_charset = 0;
 
@@ -2227,6 +2234,14 @@ sub process {
                              "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr);
                }
 
+# Check for line lengths > 75 in commit log, warn once
+               if ($in_commit_log && !$commit_log_long_line &&
+                   length($line) > 75) {
+                       WARN("COMMIT_LOG_LONG_LINE",
+                            "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
+                       $commit_log_long_line = 1;
+               }
+
 # Check for git id commit length and improperly formed commit descriptions
                if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) {
                        my $init_char = $1;
@@ -2498,8 +2513,9 @@ sub process {
 #line length limit
                if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
                    $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
-                   !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
-                   $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
+                   !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?$String\s*(?:|,|\)\s*;)\s*$/ ||
+                     $line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
+                     $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) &&
                    $length > $max_line_length)
                {
                        WARN("LONG_LINE",
@@ -3192,6 +3208,18 @@ sub process {
                                $herecurr);
                }
 
+# check for const <foo> const where <foo> is not a pointer or array type
+               if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
+                       my $found = $1;
+                       if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
+                               WARN("CONST_CONST",
+                                    "'const $found const *' should probably be 'const $found * const'\n" . $herecurr);
+                       } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
+                               WARN("CONST_CONST",
+                                    "'const $found const' should probably be 'const $found'\n" . $herecurr);
+                       }
+               }
+
 # check for non-global char *foo[] = {"bar", ...} declarations.
                if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
                        WARN("STATIC_CONST_CHAR_ARRAY",
@@ -3199,6 +3227,19 @@ sub process {
                                $herecurr);
                }
 
+# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
+               if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
+                       my $array = $1;
+                       if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
+                               my $array_div = $1;
+                               if (WARN("ARRAY_SIZE",
+                                        "Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
+                                   $fix) {
+                                       $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
+                               }
+                       }
+               }
+
 # check for function declarations without arguments like "int foo()"
                if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
                        if (ERROR("FUNCTION_WITHOUT_ARGS",
@@ -3355,6 +3396,14 @@ sub process {
                             "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
                }
 
+# ENOSYS means "bad syscall nr" and nothing else.  This will have a small
+# number of false positives, but assembly files are not checked, so at
+# least the arch entry code will not trigger this warning.
+               if ($line =~ /\bENOSYS\b/) {
+                       WARN("ENOSYS",
+                            "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr);
+               }
+
 # function brace can't be on same line, except for #defines of do while,
 # or if closed on same line
                if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and
@@ -3611,7 +3660,7 @@ sub process {
 
                                # Ignore operators passed as parameters.
                                if ($op_type ne 'V' &&
-                                   $ca =~ /\s$/ && $cc =~ /^\s*,/) {
+                                   $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
 
 #                              # Ignore comments
 #                              } elsif ($op =~ /^$;+$/) {
@@ -3796,6 +3845,14 @@ sub process {
                                                $ok = 1;
                                        }
 
+                                       # for asm volatile statements
+                                       # ignore a colon with another
+                                       # colon immediately before or after
+                                       if (($op eq ':') &&
+                                           ($ca =~ /:$/ || $cc =~ /^:/)) {
+                                               $ok = 1;
+                                       }
+
                                        # messages are ERROR, but ?: are CHK
                                        if ($ok == 0) {
                                                my $msg_type = \&ERROR;
@@ -4009,12 +4066,12 @@ sub process {
                        }
                }
 
-# Return of what appears to be an errno should normally be -'ve
-               if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
+# Return of what appears to be an errno should normally be negative
+               if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
                        my $name = $1;
                        if ($name ne 'EOF' && $name ne 'ERROR') {
                                WARN("USE_NEGATIVE_ERRNO",
-                                    "return of an errno should typically be -ve (return -$1)\n" . $herecurr);
+                                    "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
                        }
                }
 
@@ -4224,7 +4281,8 @@ sub process {
                        }
                }
 
-#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
+# warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes
+# itself <asm/foo.h> (uses RAW line)
                if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
                        my $file = "$1.h";
                        my $checkfile = "include/linux/$file";
@@ -4232,12 +4290,15 @@ sub process {
                            $realfile ne $checkfile &&
                            $1 !~ /$allowed_asm_includes/)
                        {
-                               if ($realfile =~ m{^arch/}) {
-                                       CHK("ARCH_INCLUDE_LINUX",
-                                           "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
-                               } else {
-                                       WARN("INCLUDE_LINUX",
-                                            "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+                               my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
+                               if ($asminclude > 0) {
+                                       if ($realfile =~ m{^arch/}) {
+                                               CHK("ARCH_INCLUDE_LINUX",
+                                                   "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+                                       } else {
+                                               WARN("INCLUDE_LINUX",
+                                                    "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+                                       }
                                }
                        }
                }
@@ -4746,6 +4807,16 @@ sub process {
                        }
                }
 
+# check for __read_mostly with const non-pointer (should just be const)
+               if ($line =~ /\b__read_mostly\b/ &&
+                   $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
+                       if (ERROR("CONST_READ_MOSTLY",
+                                 "Invalid use of __read_mostly with const type\n" . $herecurr) &&
+                           $fix) {
+                               $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
+                       }
+               }
+
 # don't use __constant_<foo> functions outside of include/uapi/
                if ($realfile !~ m@^include/uapi/@ &&
                    $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
@@ -5307,6 +5378,7 @@ sub process {
                                stacktrace_ops|
                                sysfs_ops|
                                tty_operations|
+                               uart_ops|
                                usb_mon_operations|
                                wd_ops}x;
                if ($line !~ /\bconst\b/ &&