aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2013-09-11 17:23:54 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-09-11 18:58:39 -0400
commitd5e616fc1c1dd673c53b682877e2d35a2862263c (patch)
treec1eec612d62f6c6d6ade9a843f89ff34ad94fab4 /scripts
parent1431574a1c4c669a0c198e4763627837416e4443 (diff)
checkpatch: add a few more --fix corrections
Suggest a few more single-line corrections. Remove DOS line endings Simplify removing trailing whitespace Remove global/static initializations to 0/NULL Convert pr_warning to pr_warn Add space after brace Convert binary constants to hex Remove whitespace after line continuation Use inline not __inline or __inline__ Use __printf and __scanf Use a single ; for statement terminations Convert __FUNCTION__ to __func__ Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl122
1 files changed, 84 insertions, 38 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2ee9eb750560..9163651edc50 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1845,15 +1845,17 @@ sub process {
1845#trailing whitespace 1845#trailing whitespace
1846 if ($line =~ /^\+.*\015/) { 1846 if ($line =~ /^\+.*\015/) {
1847 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1847 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1848 ERROR("DOS_LINE_ENDINGS", 1848 if (ERROR("DOS_LINE_ENDINGS",
1849 "DOS line endings\n" . $herevet); 1849 "DOS line endings\n" . $herevet) &&
1850 1850 $fix) {
1851 $fixed[$linenr - 1] =~ s/[\s\015]+$//;
1852 }
1851 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { 1853 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1852 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1854 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1853 if (ERROR("TRAILING_WHITESPACE", 1855 if (ERROR("TRAILING_WHITESPACE",
1854 "trailing whitespace\n" . $herevet) && 1856 "trailing whitespace\n" . $herevet) &&
1855 $fix) { 1857 $fix) {
1856 $fixed[$linenr - 1] =~ s/^(\+.*?)\s+$/$1/; 1858 $fixed[$linenr - 1] =~ s/\s+$//;
1857 } 1859 }
1858 1860
1859 $rpt_cleaners = 1; 1861 $rpt_cleaners = 1;
@@ -2486,16 +2488,22 @@ sub process {
2486 } 2488 }
2487 2489
2488# check for global initialisers. 2490# check for global initialisers.
2489 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { 2491 if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
2490 ERROR("GLOBAL_INITIALISERS", 2492 if (ERROR("GLOBAL_INITIALISERS",
2491 "do not initialise globals to 0 or NULL\n" . 2493 "do not initialise globals to 0 or NULL\n" .
2492 $herecurr); 2494 $herecurr) &&
2495 $fix) {
2496 $fixed[$linenr - 1] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/;
2497 }
2493 } 2498 }
2494# check for static initialisers. 2499# check for static initialisers.
2495 if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) { 2500 if ($line =~ /^\+.*\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
2496 ERROR("INITIALISED_STATIC", 2501 if (ERROR("INITIALISED_STATIC",
2497 "do not initialise statics to 0 or NULL\n" . 2502 "do not initialise statics to 0 or NULL\n" .
2498 $herecurr); 2503 $herecurr) &&
2504 $fix) {
2505 $fixed[$linenr - 1] =~ s/(\bstatic\s.*?)\s*=\s*(0|NULL|false)\s*;/$1;/;
2506 }
2499 } 2507 }
2500 2508
2501# check for static const char * arrays. 2509# check for static const char * arrays.
@@ -2638,8 +2646,12 @@ sub process {
2638 } 2646 }
2639 2647
2640 if ($line =~ /\bpr_warning\s*\(/) { 2648 if ($line =~ /\bpr_warning\s*\(/) {
2641 WARN("PREFER_PR_LEVEL", 2649 if (WARN("PREFER_PR_LEVEL",
2642 "Prefer pr_warn(... to pr_warning(...\n" . $herecurr); 2650 "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) &&
2651 $fix) {
2652 $fixed[$linenr - 1] =~
2653 s/\bpr_warning\b/pr_warn/;
2654 }
2643 } 2655 }
2644 2656
2645 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) { 2657 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
@@ -3031,8 +3043,7 @@ sub process {
3031 if (ERROR("SPACING", 3043 if (ERROR("SPACING",
3032 "space required before the open brace '{'\n" . $herecurr) && 3044 "space required before the open brace '{'\n" . $herecurr) &&
3033 $fix) { 3045 $fix) {
3034 $fixed[$linenr - 1] =~ 3046 $fixed[$linenr - 1] =~ s/^(\+.*(?:do|\))){/$1 {/;
3035 s/^(\+.*(?:do|\))){/$1 {/;
3036 } 3047 }
3037 } 3048 }
3038 3049
@@ -3047,8 +3058,12 @@ sub process {
3047# closing brace should have a space following it when it has anything 3058# closing brace should have a space following it when it has anything
3048# on the line 3059# on the line
3049 if ($line =~ /}(?!(?:,|;|\)))\S/) { 3060 if ($line =~ /}(?!(?:,|;|\)))\S/) {
3050 ERROR("SPACING", 3061 if (ERROR("SPACING",
3051 "space required after that close brace '}'\n" . $herecurr); 3062 "space required after that close brace '}'\n" . $herecurr) &&
3063 $fix) {
3064 $fixed[$linenr - 1] =~
3065 s/}((?!(?:,|;|\)))\S)/} $1/;
3066 }
3052 } 3067 }
3053 3068
3054# check spacing on square brackets 3069# check spacing on square brackets
@@ -3271,8 +3286,13 @@ sub process {
3271 3286
3272#gcc binary extension 3287#gcc binary extension
3273 if ($var =~ /^$Binary$/) { 3288 if ($var =~ /^$Binary$/) {
3274 WARN("GCC_BINARY_CONSTANT", 3289 if (WARN("GCC_BINARY_CONSTANT",
3275 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr); 3290 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) &&
3291 $fix) {
3292 my $hexval = sprintf("0x%x", oct($var));
3293 $fixed[$linenr - 1] =~
3294 s/\b$var\b/$hexval/;
3295 }
3276 } 3296 }
3277 3297
3278#CamelCase 3298#CamelCase
@@ -3292,9 +3312,12 @@ sub process {
3292 } 3312 }
3293 3313
3294#no spaces allowed after \ in define 3314#no spaces allowed after \ in define
3295 if ($line=~/\#\s*define.*\\\s$/) { 3315 if ($line =~ /\#\s*define.*\\\s+$/) {
3296 WARN("WHITESPACE_AFTER_LINE_CONTINUATION", 3316 if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
3297 "Whitepspace after \\ makes next lines useless\n" . $herecurr); 3317 "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
3318 $fix) {
3319 $fixed[$linenr - 1] =~ s/\s+$//;
3320 }
3298 } 3321 }
3299 3322
3300#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) 3323#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
@@ -3691,8 +3714,12 @@ sub process {
3691 3714
3692# Check for __inline__ and __inline, prefer inline 3715# Check for __inline__ and __inline, prefer inline
3693 if ($line =~ /\b(__inline__|__inline)\b/) { 3716 if ($line =~ /\b(__inline__|__inline)\b/) {
3694 WARN("INLINE", 3717 if (WARN("INLINE",
3695 "plain inline is preferred over $1\n" . $herecurr); 3718 "plain inline is preferred over $1\n" . $herecurr) &&
3719 $fix) {
3720 $fixed[$linenr - 1] =~ s/\b(__inline__|__inline)\b/inline/;
3721
3722 }
3696 } 3723 }
3697 3724
3698# Check for __attribute__ packed, prefer __packed 3725# Check for __attribute__ packed, prefer __packed
@@ -3709,14 +3736,21 @@ sub process {
3709 3736
3710# Check for __attribute__ format(printf, prefer __printf 3737# Check for __attribute__ format(printf, prefer __printf
3711 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { 3738 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
3712 WARN("PREFER_PRINTF", 3739 if (WARN("PREFER_PRINTF",
3713 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr); 3740 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
3741 $fix) {
3742 $fixed[$linenr - 1] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;
3743
3744 }
3714 } 3745 }
3715 3746
3716# Check for __attribute__ format(scanf, prefer __scanf 3747# Check for __attribute__ format(scanf, prefer __scanf
3717 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { 3748 if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
3718 WARN("PREFER_SCANF", 3749 if (WARN("PREFER_SCANF",
3719 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr); 3750 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
3751 $fix) {
3752 $fixed[$linenr - 1] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;
3753 }
3720 } 3754 }
3721 3755
3722# check for sizeof(&) 3756# check for sizeof(&)
@@ -3727,8 +3761,11 @@ sub process {
3727 3761
3728# check for sizeof without parenthesis 3762# check for sizeof without parenthesis
3729 if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) { 3763 if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
3730 WARN("SIZEOF_PARENTHESIS", 3764 if (WARN("SIZEOF_PARENTHESIS",
3731 "sizeof $1 should be sizeof($1)\n" . $herecurr); 3765 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
3766 $fix) {
3767 $fixed[$linenr - 1] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
3768 }
3732 } 3769 }
3733 3770
3734# check for line continuations in quoted strings with odd counts of " 3771# check for line continuations in quoted strings with odd counts of "
@@ -3747,8 +3784,11 @@ sub process {
3747 if ($line =~ /\bseq_printf\s*\(/) { 3784 if ($line =~ /\bseq_printf\s*\(/) {
3748 my $fmt = get_quoted_string($line, $rawline); 3785 my $fmt = get_quoted_string($line, $rawline);
3749 if ($fmt !~ /[^\\]\%/) { 3786 if ($fmt !~ /[^\\]\%/) {
3750 WARN("PREFER_SEQ_PUTS", 3787 if (WARN("PREFER_SEQ_PUTS",
3751 "Prefer seq_puts to seq_printf\n" . $herecurr); 3788 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
3789 $fix) {
3790 $fixed[$linenr - 1] =~ s/\bseq_printf\b/seq_puts/;
3791 }
3752 } 3792 }
3753 } 3793 }
3754 3794
@@ -3879,8 +3919,11 @@ sub process {
3879 3919
3880# check for multiple semicolons 3920# check for multiple semicolons
3881 if ($line =~ /;\s*;\s*$/) { 3921 if ($line =~ /;\s*;\s*$/) {
3882 WARN("ONE_SEMICOLON", 3922 if (WARN("ONE_SEMICOLON",
3883 "Statements terminations use 1 semicolon\n" . $herecurr); 3923 "Statements terminations use 1 semicolon\n" . $herecurr) &&
3924 $fix) {
3925 $fixed[$linenr - 1] =~ s/(\s*;\s*){2,}$/;/g;
3926 }
3884 } 3927 }
3885 3928
3886# check for switch/default statements without a break; 3929# check for switch/default statements without a break;
@@ -3898,9 +3941,12 @@ sub process {
3898 } 3941 }
3899 3942
3900# check for gcc specific __FUNCTION__ 3943# check for gcc specific __FUNCTION__
3901 if ($line =~ /__FUNCTION__/) { 3944 if ($line =~ /\b__FUNCTION__\b/) {
3902 WARN("USE_FUNC", 3945 if (WARN("USE_FUNC",
3903 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); 3946 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&
3947 $fix) {
3948 $fixed[$linenr - 1] =~ s/\b__FUNCTION__\b/__func__/g;
3949 }
3904 } 3950 }
3905 3951
3906# check for use of yield() 3952# check for use of yield()