aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl71
1 files changed, 68 insertions, 3 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e5bd60ff48e3..913d6bdfdda3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1600,13 +1600,17 @@ sub process {
1600 1600
1601# Check signature styles 1601# Check signature styles
1602 if (!$in_header_lines && 1602 if (!$in_header_lines &&
1603 $line =~ /^(\s*)($signature_tags)(\s*)(.*)/) { 1603 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
1604 my $space_before = $1; 1604 my $space_before = $1;
1605 my $sign_off = $2; 1605 my $sign_off = $2;
1606 my $space_after = $3; 1606 my $space_after = $3;
1607 my $email = $4; 1607 my $email = $4;
1608 my $ucfirst_sign_off = ucfirst(lc($sign_off)); 1608 my $ucfirst_sign_off = ucfirst(lc($sign_off));
1609 1609
1610 if ($sign_off !~ /$signature_tags/) {
1611 WARN("BAD_SIGN_OFF",
1612 "Non-standard signature: $sign_off\n" . $herecurr);
1613 }
1610 if (defined $space_before && $space_before ne "") { 1614 if (defined $space_before && $space_before ne "") {
1611 WARN("BAD_SIGN_OFF", 1615 WARN("BAD_SIGN_OFF",
1612 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); 1616 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr);
@@ -1848,8 +1852,8 @@ sub process {
1848 1852
1849 my $pos = pos_last_openparen($rest); 1853 my $pos = pos_last_openparen($rest);
1850 if ($pos >= 0) { 1854 if ($pos >= 0) {
1851 $line =~ /^\+([ \t]*)/; 1855 $line =~ /^(\+| )([ \t]*)/;
1852 my $newindent = $1; 1856 my $newindent = $2;
1853 1857
1854 my $goodtabindent = $oldindent . 1858 my $goodtabindent = $oldindent .
1855 "\t" x ($pos / 8) . 1859 "\t" x ($pos / 8) .
@@ -2984,6 +2988,45 @@ sub process {
2984 } 2988 }
2985 } 2989 }
2986 2990
2991# do {} while (0) macro tests:
2992# single-statement macros do not need to be enclosed in do while (0) loop,
2993# macro should not end with a semicolon
2994 if ($^V && $^V ge 5.10.0 &&
2995 $realfile !~ m@/vmlinux.lds.h$@ &&
2996 $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
2997 my $ln = $linenr;
2998 my $cnt = $realcnt;
2999 my ($off, $dstat, $dcond, $rest);
3000 my $ctx = '';
3001 ($dstat, $dcond, $ln, $cnt, $off) =
3002 ctx_statement_block($linenr, $realcnt, 0);
3003 $ctx = $dstat;
3004
3005 $dstat =~ s/\\\n.//g;
3006
3007 if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
3008 my $stmts = $2;
3009 my $semis = $3;
3010
3011 $ctx =~ s/\n*$//;
3012 my $cnt = statement_rawlines($ctx);
3013 my $herectx = $here . "\n";
3014
3015 for (my $n = 0; $n < $cnt; $n++) {
3016 $herectx .= raw_line($linenr, $n) . "\n";
3017 }
3018
3019 if (($stmts =~ tr/;/;/) == 1) {
3020 WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
3021 "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
3022 }
3023 if (defined $semis && $semis ne "") {
3024 WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
3025 "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
3026 }
3027 }
3028 }
3029
2987# make sure symbols are always wrapped with VMLINUX_SYMBOL() ... 3030# make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
2988# all assignments may have only one of the following with an assignment: 3031# all assignments may have only one of the following with an assignment:
2989# . 3032# .
@@ -3261,6 +3304,12 @@ sub process {
3261 "sizeof(& should be avoided\n" . $herecurr); 3304 "sizeof(& should be avoided\n" . $herecurr);
3262 } 3305 }
3263 3306
3307# check for sizeof without parenthesis
3308 if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
3309 WARN("SIZEOF_PARENTHESIS",
3310 "sizeof $1 should be sizeof($1)\n" . $herecurr);
3311 }
3312
3264# check for line continuations in quoted strings with odd counts of " 3313# check for line continuations in quoted strings with odd counts of "
3265 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { 3314 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
3266 WARN("LINE_CONTINUATIONS", 3315 WARN("LINE_CONTINUATIONS",
@@ -3309,6 +3358,22 @@ sub process {
3309 } 3358 }
3310 } 3359 }
3311 3360
3361# check usleep_range arguments
3362 if ($^V && $^V ge 5.10.0 &&
3363 defined $stat &&
3364 $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
3365 my $min = $1;
3366 my $max = $7;
3367 if ($min eq $max) {
3368 WARN("USLEEP_RANGE",
3369 "usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
3370 } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
3371 $min > $max) {
3372 WARN("USLEEP_RANGE",
3373 "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
3374 }
3375 }
3376
3312# check for new externs in .c files. 3377# check for new externs in .c files.
3313 if ($realfile =~ /\.c$/ && defined $stat && 3378 if ($realfile =~ /\.c$/ && defined $stat &&
3314 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) 3379 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)