diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 109 |
1 files changed, 104 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3257d3d96767..bd88f11b0953 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -145,11 +145,14 @@ our $Sparse = qr{ | |||
| 145 | __kprobes| | 145 | __kprobes| |
| 146 | __ref | 146 | __ref |
| 147 | }x; | 147 | }x; |
| 148 | |||
| 149 | # Notes to $Attribute: | ||
| 150 | # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check | ||
| 148 | our $Attribute = qr{ | 151 | our $Attribute = qr{ |
| 149 | const| | 152 | const| |
| 150 | __read_mostly| | 153 | __read_mostly| |
| 151 | __kprobes| | 154 | __kprobes| |
| 152 | __(?:mem|cpu|dev|)(?:initdata|init)| | 155 | __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)| |
| 153 | ____cacheline_aligned| | 156 | ____cacheline_aligned| |
| 154 | ____cacheline_aligned_in_smp| | 157 | ____cacheline_aligned_in_smp| |
| 155 | ____cacheline_internodealigned_in_smp| | 158 | ____cacheline_internodealigned_in_smp| |
| @@ -189,6 +192,14 @@ our $typeTypedefs = qr{(?x: | |||
| 189 | atomic_t | 192 | atomic_t |
| 190 | )}; | 193 | )}; |
| 191 | 194 | ||
| 195 | our $logFunctions = qr{(?x: | ||
| 196 | printk| | ||
| 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)| | ||
| 199 | WARN| | ||
| 200 | panic | ||
| 201 | )}; | ||
| 202 | |||
| 192 | our @typeList = ( | 203 | our @typeList = ( |
| 193 | qr{void}, | 204 | qr{void}, |
| 194 | qr{(?:unsigned\s+)?char}, | 205 | qr{(?:unsigned\s+)?char}, |
| @@ -1371,18 +1382,38 @@ sub process { | |||
| 1371 | ERROR("trailing whitespace\n" . $herevet); | 1382 | ERROR("trailing whitespace\n" . $herevet); |
| 1372 | } | 1383 | } |
| 1373 | 1384 | ||
| 1385 | # check for Kconfig help text having a real description | ||
| 1386 | if ($realfile =~ /Kconfig/ && | ||
| 1387 | $line =~ /\+?\s*(---)?help(---)?$/) { | ||
| 1388 | my $length = 0; | ||
| 1389 | for (my $l = $linenr; defined($lines[$l]); $l++) { | ||
| 1390 | my $f = $lines[$l]; | ||
| 1391 | $f =~ s/#.*//; | ||
| 1392 | $f =~ s/^\s+//; | ||
| 1393 | next if ($f =~ /^$/); | ||
| 1394 | last if ($f =~ /^\s*config\s/); | ||
| 1395 | $length++; | ||
| 1396 | } | ||
| 1397 | WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($length < 4); | ||
| 1398 | } | ||
| 1399 | |||
| 1374 | # check we are in a valid source file if not then ignore this hunk | 1400 | # check we are in a valid source file if not then ignore this hunk |
| 1375 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); | 1401 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
| 1376 | 1402 | ||
| 1377 | #80 column limit | 1403 | #80 column limit |
| 1378 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && | 1404 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && |
| 1379 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && | 1405 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && |
| 1380 | $line !~ /^\+\s*printk\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && | 1406 | $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && |
| 1381 | $length > 80) | 1407 | $length > 80) |
| 1382 | { | 1408 | { |
| 1383 | WARN("line over 80 characters\n" . $herecurr); | 1409 | WARN("line over 80 characters\n" . $herecurr); |
| 1384 | } | 1410 | } |
| 1385 | 1411 | ||
| 1412 | # check for spaces before a quoted newline | ||
| 1413 | if ($rawline =~ /^.*\".*\s\\n/) { | ||
| 1414 | WARN("unnecessary whitespace before a quoted newline\n" . $herecurr); | ||
| 1415 | } | ||
| 1416 | |||
| 1386 | # check for adding lines without a newline. | 1417 | # check for adding lines without a newline. |
| 1387 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { | 1418 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { |
| 1388 | WARN("adding a line without newline at end of file\n" . $herecurr); | 1419 | WARN("adding a line without newline at end of file\n" . $herecurr); |
| @@ -1411,6 +1442,12 @@ sub process { | |||
| 1411 | ERROR("code indent should use tabs where possible\n" . $herevet); | 1442 | ERROR("code indent should use tabs where possible\n" . $herevet); |
| 1412 | } | 1443 | } |
| 1413 | 1444 | ||
| 1445 | # check for space before tabs. | ||
| 1446 | if ($rawline =~ /^\+/ && $rawline =~ / \t/) { | ||
| 1447 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | ||
| 1448 | WARN("please, no space before tabs\n" . $herevet); | ||
| 1449 | } | ||
| 1450 | |||
| 1414 | # check we are in a valid C source file if not then ignore this hunk | 1451 | # check we are in a valid C source file if not then ignore this hunk |
| 1415 | next if ($realfile !~ /\.(h|c)$/); | 1452 | next if ($realfile !~ /\.(h|c)$/); |
| 1416 | 1453 | ||
| @@ -2182,8 +2219,10 @@ sub process { | |||
| 2182 | # Find out how long the conditional actually is. | 2219 | # Find out how long the conditional actually is. |
| 2183 | my @newlines = ($c =~ /\n/gs); | 2220 | my @newlines = ($c =~ /\n/gs); |
| 2184 | my $cond_lines = 1 + $#newlines; | 2221 | my $cond_lines = 1 + $#newlines; |
| 2222 | my $stat_real = ''; | ||
| 2185 | 2223 | ||
| 2186 | my $stat_real = raw_line($linenr, $cond_lines); | 2224 | $stat_real = raw_line($linenr, $cond_lines) |
| 2225 | . "\n" if ($cond_lines); | ||
| 2187 | if (defined($stat_real) && $cond_lines > 1) { | 2226 | if (defined($stat_real) && $cond_lines > 1) { |
| 2188 | $stat_real = "[...]\n$stat_real"; | 2227 | $stat_real = "[...]\n$stat_real"; |
| 2189 | } | 2228 | } |
| @@ -2348,6 +2387,8 @@ sub process { | |||
| 2348 | DECLARE_PER_CPU| | 2387 | DECLARE_PER_CPU| |
| 2349 | DEFINE_PER_CPU| | 2388 | DEFINE_PER_CPU| |
| 2350 | __typeof__\(| | 2389 | __typeof__\(| |
| 2390 | union| | ||
| 2391 | struct| | ||
| 2351 | \.$Ident\s*=\s*| | 2392 | \.$Ident\s*=\s*| |
| 2352 | ^\"|\"$ | 2393 | ^\"|\"$ |
| 2353 | }x; | 2394 | }x; |
| @@ -2560,6 +2601,11 @@ sub process { | |||
| 2560 | CHK("architecture specific defines should be avoided\n" . $herecurr); | 2601 | CHK("architecture specific defines should be avoided\n" . $herecurr); |
| 2561 | } | 2602 | } |
| 2562 | 2603 | ||
| 2604 | # Check that the storage class is at the beginning of a declaration | ||
| 2605 | if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) { | ||
| 2606 | WARN("storage class should be at the beginning of the declaration\n" . $herecurr) | ||
| 2607 | } | ||
| 2608 | |||
| 2563 | # check the location of the inline attribute, that it is between | 2609 | # check the location of the inline attribute, that it is between |
| 2564 | # storage class and type. | 2610 | # storage class and type. |
| 2565 | if ($line =~ /\b$Type\s+$Inline\b/ || | 2611 | if ($line =~ /\b$Type\s+$Inline\b/ || |
| @@ -2572,6 +2618,11 @@ sub process { | |||
| 2572 | WARN("plain inline is preferred over $1\n" . $herecurr); | 2618 | WARN("plain inline is preferred over $1\n" . $herecurr); |
| 2573 | } | 2619 | } |
| 2574 | 2620 | ||
| 2621 | # check for sizeof(&) | ||
| 2622 | if ($line =~ /\bsizeof\s*\(\s*\&/) { | ||
| 2623 | WARN("sizeof(& should be avoided\n" . $herecurr); | ||
| 2624 | } | ||
| 2625 | |||
| 2575 | # check for new externs in .c files. | 2626 | # check for new externs in .c files. |
| 2576 | if ($realfile =~ /\.c$/ && defined $stat && | 2627 | if ($realfile =~ /\.c$/ && defined $stat && |
| 2577 | $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) | 2628 | $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) |
| @@ -2625,6 +2676,7 @@ sub process { | |||
| 2625 | # check for semaphores used as mutexes | 2676 | # check for semaphores used as mutexes |
| 2626 | if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) { | 2677 | if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) { |
| 2627 | WARN("consider using a completion\n" . $herecurr); | 2678 | WARN("consider using a completion\n" . $herecurr); |
| 2679 | |||
| 2628 | } | 2680 | } |
| 2629 | # recommend strict_strto* over simple_strto* | 2681 | # recommend strict_strto* over simple_strto* |
| 2630 | if ($line =~ /\bsimple_(strto.*?)\s*\(/) { | 2682 | if ($line =~ /\bsimple_(strto.*?)\s*\(/) { |
| @@ -2634,9 +2686,46 @@ sub process { | |||
| 2634 | if ($line =~ /^.\s*__initcall\s*\(/) { | 2686 | if ($line =~ /^.\s*__initcall\s*\(/) { |
| 2635 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); | 2687 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); |
| 2636 | } | 2688 | } |
| 2637 | # check for struct file_operations, ensure they are const. | 2689 | # check for various ops structs, ensure they are const. |
| 2690 | my $struct_ops = qr{acpi_dock_ops| | ||
| 2691 | address_space_operations| | ||
| 2692 | backlight_ops| | ||
| 2693 | block_device_operations| | ||
| 2694 | dentry_operations| | ||
| 2695 | dev_pm_ops| | ||
| 2696 | dma_map_ops| | ||
| 2697 | extent_io_ops| | ||
| 2698 | file_lock_operations| | ||
| 2699 | file_operations| | ||
| 2700 | hv_ops| | ||
| 2701 | ide_dma_ops| | ||
| 2702 | intel_dvo_dev_ops| | ||
| 2703 | item_operations| | ||
| 2704 | iwl_ops| | ||
| 2705 | kgdb_arch| | ||
| 2706 | kgdb_io| | ||
| 2707 | kset_uevent_ops| | ||
| 2708 | lock_manager_operations| | ||
| 2709 | microcode_ops| | ||
| 2710 | mtrr_ops| | ||
| 2711 | neigh_ops| | ||
| 2712 | nlmsvc_binding| | ||
| 2713 | pci_raw_ops| | ||
| 2714 | pipe_buf_operations| | ||
| 2715 | platform_hibernation_ops| | ||
| 2716 | platform_suspend_ops| | ||
| 2717 | proto_ops| | ||
| 2718 | rpc_pipe_ops| | ||
| 2719 | seq_operations| | ||
| 2720 | snd_ac97_build_ops| | ||
| 2721 | soc_pcmcia_socket_ops| | ||
| 2722 | stacktrace_ops| | ||
| 2723 | sysfs_ops| | ||
| 2724 | tty_operations| | ||
| 2725 | usb_mon_operations| | ||
| 2726 | wd_ops}x; | ||
| 2638 | if ($line !~ /\bconst\b/ && | 2727 | if ($line !~ /\bconst\b/ && |
| 2639 | $line =~ /\bstruct\s+(file_operations|seq_operations)\b/) { | 2728 | $line =~ /\bstruct\s+($struct_ops)\b/) { |
| 2640 | WARN("struct $1 should normally be const\n" . | 2729 | WARN("struct $1 should normally be const\n" . |
| 2641 | $herecurr); | 2730 | $herecurr); |
| 2642 | } | 2731 | } |
| @@ -2672,6 +2761,16 @@ sub process { | |||
| 2672 | WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); | 2761 | WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); |
| 2673 | } | 2762 | } |
| 2674 | } | 2763 | } |
| 2764 | |||
| 2765 | # check for lockdep_set_novalidate_class | ||
| 2766 | if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || | ||
| 2767 | $line =~ /__lockdep_no_validate__\s*\)/ ) { | ||
| 2768 | if ($realfile !~ m@^kernel/lockdep@ && | ||
| 2769 | $realfile !~ m@^include/linux/lockdep@ && | ||
| 2770 | $realfile !~ m@^drivers/base/core@) { | ||
| 2771 | ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); | ||
| 2772 | } | ||
| 2773 | } | ||
| 2675 | } | 2774 | } |
| 2676 | 2775 | ||
| 2677 | # If we have no input at all, then there is nothing to report on | 2776 | # If we have no input at all, then there is nothing to report on |
