diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 78 |
1 files changed, 73 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3257d3d96767..a4d74344d805 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}, |
@@ -1377,12 +1388,17 @@ sub process { | |||
1377 | #80 column limit | 1388 | #80 column limit |
1378 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && | 1389 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && |
1379 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && | 1390 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && |
1380 | $line !~ /^\+\s*printk\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && | 1391 | $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && |
1381 | $length > 80) | 1392 | $length > 80) |
1382 | { | 1393 | { |
1383 | WARN("line over 80 characters\n" . $herecurr); | 1394 | WARN("line over 80 characters\n" . $herecurr); |
1384 | } | 1395 | } |
1385 | 1396 | ||
1397 | # check for spaces before a quoted newline | ||
1398 | if ($rawline =~ /^.*\".*\s\\n/) { | ||
1399 | WARN("unnecessary whitespace before a quoted newline\n" . $herecurr); | ||
1400 | } | ||
1401 | |||
1386 | # check for adding lines without a newline. | 1402 | # check for adding lines without a newline. |
1387 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { | 1403 | 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); | 1404 | WARN("adding a line without newline at end of file\n" . $herecurr); |
@@ -1411,6 +1427,12 @@ sub process { | |||
1411 | ERROR("code indent should use tabs where possible\n" . $herevet); | 1427 | ERROR("code indent should use tabs where possible\n" . $herevet); |
1412 | } | 1428 | } |
1413 | 1429 | ||
1430 | # check for space before tabs. | ||
1431 | if ($rawline =~ /^\+/ && $rawline =~ / \t/) { | ||
1432 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | ||
1433 | WARN("please, no space before tabs\n" . $herevet); | ||
1434 | } | ||
1435 | |||
1414 | # check we are in a valid C source file if not then ignore this hunk | 1436 | # check we are in a valid C source file if not then ignore this hunk |
1415 | next if ($realfile !~ /\.(h|c)$/); | 1437 | next if ($realfile !~ /\.(h|c)$/); |
1416 | 1438 | ||
@@ -2182,8 +2204,10 @@ sub process { | |||
2182 | # Find out how long the conditional actually is. | 2204 | # Find out how long the conditional actually is. |
2183 | my @newlines = ($c =~ /\n/gs); | 2205 | my @newlines = ($c =~ /\n/gs); |
2184 | my $cond_lines = 1 + $#newlines; | 2206 | my $cond_lines = 1 + $#newlines; |
2207 | my $stat_real = ''; | ||
2185 | 2208 | ||
2186 | my $stat_real = raw_line($linenr, $cond_lines); | 2209 | $stat_real = raw_line($linenr, $cond_lines) |
2210 | . "\n" if ($cond_lines); | ||
2187 | if (defined($stat_real) && $cond_lines > 1) { | 2211 | if (defined($stat_real) && $cond_lines > 1) { |
2188 | $stat_real = "[...]\n$stat_real"; | 2212 | $stat_real = "[...]\n$stat_real"; |
2189 | } | 2213 | } |
@@ -2348,6 +2372,8 @@ sub process { | |||
2348 | DECLARE_PER_CPU| | 2372 | DECLARE_PER_CPU| |
2349 | DEFINE_PER_CPU| | 2373 | DEFINE_PER_CPU| |
2350 | __typeof__\(| | 2374 | __typeof__\(| |
2375 | union| | ||
2376 | struct| | ||
2351 | \.$Ident\s*=\s*| | 2377 | \.$Ident\s*=\s*| |
2352 | ^\"|\"$ | 2378 | ^\"|\"$ |
2353 | }x; | 2379 | }x; |
@@ -2572,6 +2598,11 @@ sub process { | |||
2572 | WARN("plain inline is preferred over $1\n" . $herecurr); | 2598 | WARN("plain inline is preferred over $1\n" . $herecurr); |
2573 | } | 2599 | } |
2574 | 2600 | ||
2601 | # check for sizeof(&) | ||
2602 | if ($line =~ /\bsizeof\s*\(\s*\&/) { | ||
2603 | WARN("sizeof(& should be avoided\n" . $herecurr); | ||
2604 | } | ||
2605 | |||
2575 | # check for new externs in .c files. | 2606 | # check for new externs in .c files. |
2576 | if ($realfile =~ /\.c$/ && defined $stat && | 2607 | if ($realfile =~ /\.c$/ && defined $stat && |
2577 | $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) | 2608 | $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) |
@@ -2634,9 +2665,46 @@ sub process { | |||
2634 | if ($line =~ /^.\s*__initcall\s*\(/) { | 2665 | if ($line =~ /^.\s*__initcall\s*\(/) { |
2635 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); | 2666 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); |
2636 | } | 2667 | } |
2637 | # check for struct file_operations, ensure they are const. | 2668 | # check for various ops structs, ensure they are const. |
2669 | my $struct_ops = qr{acpi_dock_ops| | ||
2670 | address_space_operations| | ||
2671 | backlight_ops| | ||
2672 | block_device_operations| | ||
2673 | dentry_operations| | ||
2674 | dev_pm_ops| | ||
2675 | dma_map_ops| | ||
2676 | extent_io_ops| | ||
2677 | file_lock_operations| | ||
2678 | file_operations| | ||
2679 | hv_ops| | ||
2680 | ide_dma_ops| | ||
2681 | intel_dvo_dev_ops| | ||
2682 | item_operations| | ||
2683 | iwl_ops| | ||
2684 | kgdb_arch| | ||
2685 | kgdb_io| | ||
2686 | kset_uevent_ops| | ||
2687 | lock_manager_operations| | ||
2688 | microcode_ops| | ||
2689 | mtrr_ops| | ||
2690 | neigh_ops| | ||
2691 | nlmsvc_binding| | ||
2692 | pci_raw_ops| | ||
2693 | pipe_buf_operations| | ||
2694 | platform_hibernation_ops| | ||
2695 | platform_suspend_ops| | ||
2696 | proto_ops| | ||
2697 | rpc_pipe_ops| | ||
2698 | seq_operations| | ||
2699 | snd_ac97_build_ops| | ||
2700 | soc_pcmcia_socket_ops| | ||
2701 | stacktrace_ops| | ||
2702 | sysfs_ops| | ||
2703 | tty_operations| | ||
2704 | usb_mon_operations| | ||
2705 | wd_ops}x; | ||
2638 | if ($line !~ /\bconst\b/ && | 2706 | if ($line !~ /\bconst\b/ && |
2639 | $line =~ /\bstruct\s+(file_operations|seq_operations)\b/) { | 2707 | $line =~ /\bstruct\s+($struct_ops)\b/) { |
2640 | WARN("struct $1 should normally be const\n" . | 2708 | WARN("struct $1 should normally be const\n" . |
2641 | $herecurr); | 2709 | $herecurr); |
2642 | } | 2710 | } |