aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-04 19:55:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-04 19:55:13 -0400
commit00170fdd0846df7cdb5ad421d3a340440f930b8f (patch)
tree1883cfbda846cd65faed011bda54a52c1d40ecdd /scripts
parentd09cc3659db494aca4b3bb2393c533fb4946b794 (diff)
parent3ff6db3287e8a5e8f5bb9529b8e1259ca6b10def (diff)
Merge branch 'akpm' (patchbomb from Andrew) into next
Merge misc updates from Andrew Morton: - a few fixes for 3.16. Cc'ed to stable so they'll get there somehow. - various misc fixes and cleanups - most of the ocfs2 queue. Review is slow... - most of MM. The MM queue is pretty huge this time, but not much in the way of feature work. - some tweaks under kernel/ - printk maintenance work - updates to lib/ - checkpatch updates - tweaks to init/ * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (276 commits) fs/autofs4/dev-ioctl.c: add __init to autofs_dev_ioctl_init fs/ncpfs/getopt.c: replace simple_strtoul by kstrtoul init/main.c: remove an ifdef kthreads: kill CLONE_KERNEL, change kernel_thread(kernel_init) to avoid CLONE_SIGHAND init/main.c: add initcall_blacklist kernel parameter init/main.c: don't use pr_debug() fs/binfmt_flat.c: make old_reloc() static fs/binfmt_elf.c: fix bool assignements fs/efs: convert printk(KERN_DEBUG to pr_debug fs/efs: add pr_fmt / use __func__ fs/efs: convert printk to pr_foo() scripts/checkpatch.pl: device_initcall is not the only __initcall substitute checkpatch: check stable email address checkpatch: warn on unnecessary void function return statements checkpatch: prefer kstrto<foo> to sscanf(buf, "%<lhuidx>", &bar); checkpatch: add warning for kmalloc/kzalloc with multiply checkpatch: warn on #defines ending in semicolon checkpatch: make --strict a default for files in drivers/net and net/ checkpatch: always warn on missing blank line after variable declaration block checkpatch: fix wildcard DT compatible string checking ...
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl136
1 files changed, 122 insertions, 14 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 34eb2160489d..010b18ef4ea0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -24,6 +24,7 @@ my $emacs = 0;
24my $terse = 0; 24my $terse = 0;
25my $file = 0; 25my $file = 0;
26my $check = 0; 26my $check = 0;
27my $check_orig = 0;
27my $summary = 1; 28my $summary = 1;
28my $mailback = 0; 29my $mailback = 0;
29my $summary_file = 0; 30my $summary_file = 0;
@@ -146,6 +147,7 @@ GetOptions(
146help(0) if ($help); 147help(0) if ($help);
147 148
148$fix = 1 if ($fix_inplace); 149$fix = 1 if ($fix_inplace);
150$check_orig = $check;
149 151
150my $exit = 0; 152my $exit = 0;
151 153
@@ -397,6 +399,11 @@ foreach my $entry (@mode_permission_funcs) {
397 $mode_perms_search .= $entry->[0]; 399 $mode_perms_search .= $entry->[0];
398} 400}
399 401
402our $declaration_macros = qr{(?x:
403 (?:$Storage\s+)?(?:DECLARE|DEFINE)_[A-Z]+\s*\(|
404 (?:$Storage\s+)?LIST_HEAD\s*\(
405)};
406
400our $allowed_asm_includes = qr{(?x: 407our $allowed_asm_includes = qr{(?x:
401 irq| 408 irq|
402 memory 409 memory
@@ -1808,11 +1815,13 @@ sub process {
1808 $here = "#$linenr: " if (!$file); 1815 $here = "#$linenr: " if (!$file);
1809 $here = "#$realline: " if ($file); 1816 $here = "#$realline: " if ($file);
1810 1817
1818 my $found_file = 0;
1811 # extract the filename as it passes 1819 # extract the filename as it passes
1812 if ($line =~ /^diff --git.*?(\S+)$/) { 1820 if ($line =~ /^diff --git.*?(\S+)$/) {
1813 $realfile = $1; 1821 $realfile = $1;
1814 $realfile =~ s@^([^/]*)/@@ if (!$file); 1822 $realfile =~ s@^([^/]*)/@@ if (!$file);
1815 $in_commit_log = 0; 1823 $in_commit_log = 0;
1824 $found_file = 1;
1816 } elsif ($line =~ /^\+\+\+\s+(\S+)/) { 1825 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1817 $realfile = $1; 1826 $realfile = $1;
1818 $realfile =~ s@^([^/]*)/@@ if (!$file); 1827 $realfile =~ s@^([^/]*)/@@ if (!$file);
@@ -1829,6 +1838,15 @@ sub process {
1829 ERROR("MODIFIED_INCLUDE_ASM", 1838 ERROR("MODIFIED_INCLUDE_ASM",
1830 "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); 1839 "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
1831 } 1840 }
1841 $found_file = 1;
1842 }
1843
1844 if ($found_file) {
1845 if ($realfile =~ m@^(drivers/net/|net/)@) {
1846 $check = 1;
1847 } else {
1848 $check = $check_orig;
1849 }
1832 next; 1850 next;
1833 } 1851 }
1834 1852
@@ -1926,6 +1944,12 @@ sub process {
1926 } 1944 }
1927 } 1945 }
1928 1946
1947# Check for old stable address
1948 if ($line =~ /^\s*cc:\s*.*<?\bstable\@kernel\.org\b>?.*$/i) {
1949 ERROR("STABLE_ADDRESS",
1950 "The 'stable' address should be 'stable\@vger.kernel.org'\n" . $herecurr);
1951 }
1952
1929# Check for unwanted Gerrit info 1953# Check for unwanted Gerrit info
1930 if ($in_commit_log && $line =~ /^\s*change-id:/i) { 1954 if ($in_commit_log && $line =~ /^\s*change-id:/i) {
1931 ERROR("GERRIT_CHANGE_ID", 1955 ERROR("GERRIT_CHANGE_ID",
@@ -2093,8 +2117,10 @@ sub process {
2093 2117
2094 foreach my $compat (@compats) { 2118 foreach my $compat (@compats) {
2095 my $compat2 = $compat; 2119 my $compat2 = $compat;
2096 $compat2 =~ s/\,[a-z]*\-/\,<\.\*>\-/; 2120 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
2097 `grep -Erq "$compat|$compat2" $dt_path`; 2121 my $compat3 = $compat;
2122 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
2123 `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
2098 if ( $? >> 8 ) { 2124 if ( $? >> 8 ) {
2099 WARN("UNDOCUMENTED_DT_STRING", 2125 WARN("UNDOCUMENTED_DT_STRING",
2100 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr); 2126 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
@@ -2266,18 +2292,37 @@ sub process {
2266 } 2292 }
2267 2293
2268# check for missing blank lines after declarations 2294# check for missing blank lines after declarations
2269 if ($realfile =~ m@^(drivers/net/|net/)@ && 2295 if ($sline =~ /^\+\s+\S/ && #Not at char 1
2270 $prevline =~ /^\+\s+$Declare\s+$Ident/ && 2296 # actual declarations
2271 !($prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || 2297 ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
2272 $prevline =~ /(?:\{\s*|\\)$/) && #extended lines 2298 # foo bar; where foo is some local typedef or #define
2273 $sline =~ /^\+\s+/ && #Not at char 1 2299 $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
2274 !($sline =~ /^\+\s+$Declare/ || 2300 # known declaration macros
2275 $sline =~ /^\+\s+$Ident\s+$Ident/ || #eg: typedef foo 2301 $prevline =~ /^\+\s+$declaration_macros/) &&
2302 # for "else if" which can look like "$Ident $Ident"
2303 !($prevline =~ /^\+\s+$c90_Keywords\b/ ||
2304 # other possible extensions of declaration lines
2305 $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
2306 # not starting a section or a macro "\" extended line
2307 $prevline =~ /(?:\{\s*|\\)$/) &&
2308 # looks like a declaration
2309 !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
2310 # foo bar; where foo is some local typedef or #define
2311 $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
2312 # known declaration macros
2313 $sline =~ /^\+\s+$declaration_macros/ ||
2314 # start of struct or union or enum
2276 $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ || 2315 $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ ||
2277 $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(])/ || 2316 # start or end of block or continuation of declaration
2278 $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) { 2317 $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
2318 # bitfield continuation
2319 $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
2320 # other possible extensions of declaration lines
2321 $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
2322 # indentation of previous and current line are the same
2323 (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
2279 WARN("SPACING", 2324 WARN("SPACING",
2280 "networking uses a blank line after declarations\n" . $hereprev); 2325 "Missing a blank line after declarations\n" . $hereprev);
2281 } 2326 }
2282 2327
2283# check for spaces at the beginning of a line. 2328# check for spaces at the beginning of a line.
@@ -3431,6 +3476,13 @@ sub process {
3431 } 3476 }
3432 } 3477 }
3433 3478
3479# unnecessary return in a void function? (a single leading tab, then return;)
3480 if ($sline =~ /^\+\treturn\s*;\s*$/ &&
3481 $prevline =~ /^\+/) {
3482 WARN("RETURN_VOID",
3483 "void function return statements are not generally useful\n" . $herecurr);
3484 }
3485
3434# if statements using unnecessary parentheses - ie: if ((foo == bar)) 3486# if statements using unnecessary parentheses - ie: if ((foo == bar))
3435 if ($^V && $^V ge 5.10.0 && 3487 if ($^V && $^V ge 5.10.0 &&
3436 $line =~ /\bif\s*((?:\(\s*){2,})/) { 3488 $line =~ /\bif\s*((?:\(\s*){2,})/) {
@@ -3782,6 +3834,17 @@ sub process {
3782 WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON", 3834 WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
3783 "do {} while (0) macros should not be semicolon terminated\n" . "$herectx"); 3835 "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
3784 } 3836 }
3837 } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
3838 $ctx =~ s/\n*$//;
3839 my $cnt = statement_rawlines($ctx);
3840 my $herectx = $here . "\n";
3841
3842 for (my $n = 0; $n < $cnt; $n++) {
3843 $herectx .= raw_line($linenr, $n) . "\n";
3844 }
3845
3846 WARN("TRAILING_SEMICOLON",
3847 "macros should not use a trailing semicolon\n" . "$herectx");
3785 } 3848 }
3786 } 3849 }
3787 3850
@@ -4264,6 +4327,27 @@ sub process {
4264 "unchecked sscanf return value\n" . "$here\n$stat_real\n"); 4327 "unchecked sscanf return value\n" . "$here\n$stat_real\n");
4265 } 4328 }
4266 4329
4330# check for simple sscanf that should be kstrto<foo>
4331 if ($^V && $^V ge 5.10.0 &&
4332 defined $stat &&
4333 $line =~ /\bsscanf\b/) {
4334 my $lc = $stat =~ tr@\n@@;
4335 $lc = $lc + $linenr;
4336 my $stat_real = raw_line($linenr, 0);
4337 for (my $count = $linenr + 1; $count <= $lc; $count++) {
4338 $stat_real = $stat_real . "\n" . raw_line($count, 0);
4339 }
4340 if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
4341 my $format = $6;
4342 my $count = $format =~ tr@%@%@;
4343 if ($count == 1 &&
4344 $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) {
4345 WARN("SSCANF_TO_KSTRTO",
4346 "Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n");
4347 }
4348 }
4349 }
4350
4267# check for new externs in .h files. 4351# check for new externs in .h files.
4268 if ($realfile =~ /\.h$/ && 4352 if ($realfile =~ /\.h$/ &&
4269 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { 4353 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
@@ -4328,6 +4412,30 @@ sub process {
4328 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); 4412 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
4329 } 4413 }
4330 4414
4415# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
4416 if ($^V && $^V ge 5.10.0 &&
4417 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/) {
4418 my $oldfunc = $3;
4419 my $a1 = $4;
4420 my $a2 = $10;
4421 my $newfunc = "kmalloc_array";
4422 $newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
4423 if ($a1 =~ /^sizeof\s*\S/ || $a2 =~ /^sizeof\s*\S/) {
4424 if (WARN("ALLOC_WITH_MULTIPLY",
4425 "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) &&
4426 $fix) {
4427 my $r1 = $a1;
4428 my $r2 = $a2;
4429 if ($a1 =~ /^sizeof\s*\S/) {
4430 $r1 = $a2;
4431 $r2 = $a1;
4432 }
4433 $fixed[$linenr - 1] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
4434
4435 }
4436 }
4437 }
4438
4331# check for krealloc arg reuse 4439# check for krealloc arg reuse
4332 if ($^V && $^V ge 5.10.0 && 4440 if ($^V && $^V ge 5.10.0 &&
4333 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { 4441 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) {
@@ -4443,10 +4551,10 @@ sub process {
4443 "$1 is obsolete, use k$3 instead\n" . $herecurr); 4551 "$1 is obsolete, use k$3 instead\n" . $herecurr);
4444 } 4552 }
4445 4553
4446# check for __initcall(), use device_initcall() explicitly please 4554# check for __initcall(), use device_initcall() explicitly or more appropriate function please
4447 if ($line =~ /^.\s*__initcall\s*\(/) { 4555 if ($line =~ /^.\s*__initcall\s*\(/) {
4448 WARN("USE_DEVICE_INITCALL", 4556 WARN("USE_DEVICE_INITCALL",
4449 "please use device_initcall() instead of __initcall()\n" . $herecurr); 4557 "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
4450 } 4558 }
4451 4559
4452# check for various ops structs, ensure they are const. 4560# check for various ops structs, ensure they are const.