]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - scripts/checkpatch.pl
checkpatch: fix false positive on __initconst
[net-next-2.6.git] / scripts / checkpatch.pl
index 3257d3d96767da60103c3e7d91beef537541f3cc..1530dbf1dab51335ed7e9055e0a6abc25ef8249b 100755 (executable)
@@ -145,11 +145,14 @@ our $Sparse       = qr{
                        __kprobes|
                        __ref
                }x;
+
+# Notes to $Attribute:
+# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
 our $Attribute = qr{
                        const|
                        __read_mostly|
                        __kprobes|
-                       __(?:mem|cpu|dev|)(?:initdata|init)|
+                       __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
                        ____cacheline_aligned|
                        ____cacheline_aligned_in_smp|
                        ____cacheline_internodealigned_in_smp|
@@ -189,6 +192,14 @@ our $typeTypedefs = qr{(?x:
        atomic_t
 )};
 
+our $logFunctions = qr{(?x:
+       printk|
+       pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)|
+       dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
+       WARN|
+       panic
+)};
+
 our @typeList = (
        qr{void},
        qr{(?:unsigned\s+)?char},
@@ -1377,7 +1388,7 @@ sub process {
 #80 column limit
                if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
                    $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
-                   $line !~ /^\+\s*printk\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ &&
+                   $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ &&
                    $length > 80)
                {
                        WARN("line over 80 characters\n" . $herecurr);
@@ -2182,8 +2193,10 @@ sub process {
                                # Find out how long the conditional actually is.
                                my @newlines = ($c =~ /\n/gs);
                                my $cond_lines = 1 + $#newlines;
+                               my $stat_real = '';
 
-                               my $stat_real = raw_line($linenr, $cond_lines);
+                               $stat_real = raw_line($linenr, $cond_lines)
+                                                       . "\n" if ($cond_lines);
                                if (defined($stat_real) && $cond_lines > 1) {
                                        $stat_real = "[...]\n$stat_real";
                                }
@@ -2572,6 +2585,11 @@ sub process {
                        WARN("plain inline is preferred over $1\n" . $herecurr);
                }
 
+# check for sizeof(&)
+               if ($line =~ /\bsizeof\s*\(\s*\&/) {
+                       WARN("sizeof(& should be avoided\n" . $herecurr);
+               }
+
 # check for new externs in .c files.
                if ($realfile =~ /\.c$/ && defined $stat &&
                    $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)