]> Pileus Git - ~andy/linux/blobdiff - scripts/checkpatch.pl
tun: avoid owner checks on IFF_ATTACH_QUEUE
[~andy/linux] / scripts / checkpatch.pl
index 6fa167758f82b43cef61c8343d9b526346de909c..4d2c7dfdaabd44abd21e53072eee8f8f884890e8 100755 (executable)
@@ -230,7 +230,11 @@ our $Inline        = qr{inline|__always_inline|noinline};
 our $Member    = qr{->$Ident|\.$Ident|\[[^]]*\]};
 our $Lval      = qr{$Ident(?:$Member)*};
 
-our $Constant  = qr{(?i:(?:[0-9]+|0x[0-9a-f]+)[ul]*)};
+our $Float_hex = qr{(?i:0x[0-9a-f]+p-?[0-9]+[fl]?)};
+our $Float_dec = qr{(?i:((?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?))};
+our $Float_int = qr{(?i:[0-9]+e-?[0-9]+[fl]?)};
+our $Float     = qr{$Float_hex|$Float_dec|$Float_int};
+our $Constant  = qr{(?:$Float|(?i:(?:0x[0-9a-f]+|[0-9]+)[ul]*))};
 our $Assignment        = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
 our $Compare    = qr{<=|>=|==|!=|<|>};
 our $Operators = qr{
@@ -1394,6 +1398,8 @@ sub process {
        my %suppress_export;
        my $suppress_statement = 0;
 
+       my %camelcase = ();
+
        # Pre-scan the patch sanitizing the lines.
        # Pre-scan the patch looking for any __setup documentation.
        #
@@ -2220,8 +2226,11 @@ sub process {
                        my $path = $1;
                        if ($path =~ m{//}) {
                                ERROR("MALFORMED_INCLUDE",
-                                     "malformed #include filename\n" .
-                                       $herecurr);
+                                     "malformed #include filename\n" . $herecurr);
+                       }
+                       if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
+                               ERROR("UAPI_INCLUDE",
+                                     "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
                        }
                }
 
@@ -2901,12 +2910,17 @@ sub process {
                        }
                }
 
-#studly caps, commented out until figure out how to distinguish between use of existing and adding new
-#              if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
-#                  print "No studly caps, use _\n";
-#                  print "$herecurr";
-#                  $clean = 0;
-#              }
+#CamelCase
+               while ($line =~ m{($Constant|$Lval)}g) {
+                       my $var = $1;
+                       if ($var !~ /$Constant/ &&
+                           $var =~ /[A-Z]\w*[a-z]|[a-z]\w*[A-Z]/ &&
+                           !defined $camelcase{$var}) {
+                               $camelcase{$var} = 1;
+                               WARN("CAMELCASE",
+                                    "Avoid CamelCase: <$var>\n" . $herecurr);
+                       }
+               }
 
 #no spaces allowed after \ in define
                if ($line=~/\#\s*define.*\\\s$/) {
@@ -3009,10 +3023,12 @@ sub process {
                                }
                        }
 
-# check for line continuations outside of #defines
+# check for line continuations outside of #defines, preprocessor #, and asm
 
                } else {
                        if ($prevline !~ /^..*\\$/ &&
+                           $line !~ /^\+\s*\#.*\\$/ &&         # preprocessor
+                           $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ &&   # asm
                            $line =~ /^\+.*\\$/) {
                                WARN("LINE_CONTINUATIONS",
                                     "Avoid unnecessary line continuations\n" . $herecurr);
@@ -3187,6 +3203,16 @@ sub process {
                        }
                }
 
+# check for unnecessary blank lines around braces
+               if (($line =~ /^..*}\s*$/ && $prevline =~ /^.\s*$/)) {
+                       CHK("BRACES",
+                           "Blank lines aren't necessary before a close brace '}'\n" . $hereprev);
+               }
+               if (($line =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
+                       CHK("BRACES",
+                           "Blank lines aren't necessary after an open brace '{'\n" . $hereprev);
+               }
+
 # no volatiles please
                my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
                if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
@@ -3324,6 +3350,12 @@ sub process {
                             "Avoid line continuations in quoted strings\n" . $herecurr);
                }
 
+# check for struct spinlock declarations
+               if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
+                       WARN("USE_SPINLOCK_T",
+                            "struct spinlock should be spinlock_t\n" . $herecurr);
+               }
+
 # Check for misused memsets
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&
@@ -3430,8 +3462,22 @@ sub process {
 
 # check for multiple semicolons
                if ($line =~ /;\s*;\s*$/) {
-                   WARN("ONE_SEMICOLON",
-                        "Statements terminations use 1 semicolon\n" . $herecurr);
+                       WARN("ONE_SEMICOLON",
+                            "Statements terminations use 1 semicolon\n" . $herecurr);
+               }
+
+# check for switch/default statements without a break;
+               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";
+                       }
+                       WARN("DEFAULT_NO_BREAK",
+                            "switch default: should use break\n" . $herectx);
                }
 
 # check for gcc specific __FUNCTION__