aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl42
1 files changed, 37 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index bd88f11b0953..2039acdf5122 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -195,7 +195,7 @@ our $typeTypedefs = qr{(?x:
195our $logFunctions = qr{(?x: 195our $logFunctions = qr{(?x:
196 printk| 196 printk|
197 pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| 197 pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)|
198 dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| 198 (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
199 WARN| 199 WARN|
200 panic 200 panic
201)}; 201)};
@@ -224,6 +224,12 @@ our @modifierList = (
224 qr{fastcall}, 224 qr{fastcall},
225); 225);
226 226
227our $allowed_asm_includes = qr{(?x:
228 irq|
229 memory
230)};
231# memory.h: ARM has a custom one
232
227sub build_types { 233sub build_types {
228 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; 234 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
229 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; 235 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
@@ -552,6 +558,9 @@ sub ctx_statement_block {
552 $type = ($level != 0)? '{' : ''; 558 $type = ($level != 0)? '{' : '';
553 559
554 if ($level == 0) { 560 if ($level == 0) {
561 if (substr($blk, $off + 1, 1) eq ';') {
562 $off++;
563 }
555 last; 564 last;
556 } 565 }
557 } 566 }
@@ -1403,7 +1412,8 @@ sub process {
1403#80 column limit 1412#80 column limit
1404 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 1413 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
1405 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 1414 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
1406 $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && 1415 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ ||
1416 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
1407 $length > 80) 1417 $length > 80)
1408 { 1418 {
1409 WARN("line over 80 characters\n" . $herecurr); 1419 WARN("line over 80 characters\n" . $herecurr);
@@ -1448,6 +1458,13 @@ sub process {
1448 WARN("please, no space before tabs\n" . $herevet); 1458 WARN("please, no space before tabs\n" . $herevet);
1449 } 1459 }
1450 1460
1461# check for spaces at the beginning of a line.
1462 if ($rawline =~ /^\+ / && $rawline !~ /\+ +\*/) {
1463 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1464 WARN("please, no space for starting a line, \
1465 excluding comments\n" . $herevet);
1466 }
1467
1451# check we are in a valid C source file if not then ignore this hunk 1468# check we are in a valid C source file if not then ignore this hunk
1452 next if ($realfile !~ /\.(h|c)$/); 1469 next if ($realfile !~ /\.(h|c)$/);
1453 1470
@@ -1778,9 +1795,9 @@ sub process {
1778 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); 1795 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1779 } 1796 }
1780 1797
1781# check for external initialisers. 1798# check for global initialisers.
1782 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { 1799 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
1783 ERROR("do not initialise externals to 0 or NULL\n" . 1800 ERROR("do not initialise globals to 0 or NULL\n" .
1784 $herecurr); 1801 $herecurr);
1785 } 1802 }
1786# check for static initialisers. 1803# check for static initialisers.
@@ -2308,7 +2325,7 @@ sub process {
2308 my $checkfile = "include/linux/$file"; 2325 my $checkfile = "include/linux/$file";
2309 if (-f "$root/$checkfile" && 2326 if (-f "$root/$checkfile" &&
2310 $realfile ne $checkfile && 2327 $realfile ne $checkfile &&
2311 $1 ne 'irq') 2328 $1 !~ /$allowed_asm_includes/)
2312 { 2329 {
2313 if ($realfile =~ m{^arch/}) { 2330 if ($realfile =~ m{^arch/}) {
2314 CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 2331 CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
@@ -2570,6 +2587,21 @@ sub process {
2570 } 2587 }
2571 } 2588 }
2572 2589
2590# prefer usleep_range over udelay
2591 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
2592 # ignore udelay's < 10, however
2593 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
2594 CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
2595 }
2596 }
2597
2598# warn about unexpectedly long msleep's
2599 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
2600 if ($1 < 20) {
2601 WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
2602 }
2603 }
2604
2573# warn about #ifdefs in C files 2605# warn about #ifdefs in C files
2574# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { 2606# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
2575# print "#ifdef in C files should be avoided\n"; 2607# print "#ifdef in C files should be avoided\n";