diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 4de4bc48493b..b954de58304f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -281,6 +281,7 @@ our $signature_tags = qr{(?xi: | |||
| 281 | Tested-by:| | 281 | Tested-by:| |
| 282 | Reviewed-by:| | 282 | Reviewed-by:| |
| 283 | Reported-by:| | 283 | Reported-by:| |
| 284 | Suggested-by:| | ||
| 284 | To:| | 285 | To:| |
| 285 | Cc: | 286 | Cc: |
| 286 | )}; | 287 | )}; |
| @@ -628,6 +629,13 @@ sub sanitise_line { | |||
| 628 | return $res; | 629 | return $res; |
| 629 | } | 630 | } |
| 630 | 631 | ||
| 632 | sub get_quoted_string { | ||
| 633 | my ($line, $rawline) = @_; | ||
| 634 | |||
| 635 | return "" if ($line !~ m/(\"[X]+\")/g); | ||
| 636 | return substr($rawline, $-[0], $+[0] - $-[0]); | ||
| 637 | } | ||
| 638 | |||
| 631 | sub ctx_statement_block { | 639 | sub ctx_statement_block { |
| 632 | my ($linenr, $remain, $off) = @_; | 640 | my ($linenr, $remain, $off) = @_; |
| 633 | my $line = $linenr - 1; | 641 | my $line = $linenr - 1; |
| @@ -1576,7 +1584,8 @@ sub process { | |||
| 1576 | # Check for incorrect file permissions | 1584 | # Check for incorrect file permissions |
| 1577 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { | 1585 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { |
| 1578 | my $permhere = $here . "FILE: $realfile\n"; | 1586 | my $permhere = $here . "FILE: $realfile\n"; |
| 1579 | if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { | 1587 | if ($realfile !~ m@scripts/@ && |
| 1588 | $realfile !~ /\.(py|pl|awk|sh)$/) { | ||
| 1580 | ERROR("EXECUTE_PERMISSIONS", | 1589 | ERROR("EXECUTE_PERMISSIONS", |
| 1581 | "do not set execute permissions for source files\n" . $permhere); | 1590 | "do not set execute permissions for source files\n" . $permhere); |
| 1582 | } | 1591 | } |
| @@ -2514,8 +2523,8 @@ sub process { | |||
| 2514 | 2523 | ||
| 2515 | # check for whitespace before a non-naked semicolon | 2524 | # check for whitespace before a non-naked semicolon |
| 2516 | if ($line =~ /^\+.*\S\s+;/) { | 2525 | if ($line =~ /^\+.*\S\s+;/) { |
| 2517 | CHK("SPACING", | 2526 | WARN("SPACING", |
| 2518 | "space prohibited before semicolon\n" . $herecurr); | 2527 | "space prohibited before semicolon\n" . $herecurr); |
| 2519 | } | 2528 | } |
| 2520 | 2529 | ||
| 2521 | # Check operator spacing. | 2530 | # Check operator spacing. |
| @@ -3221,7 +3230,7 @@ sub process { | |||
| 3221 | } | 3230 | } |
| 3222 | 3231 | ||
| 3223 | # check for unnecessary blank lines around braces | 3232 | # check for unnecessary blank lines around braces |
| 3224 | if (($line =~ /^..*}\s*$/ && $prevline =~ /^.\s*$/)) { | 3233 | if (($line =~ /^.\s*}\s*$/ && $prevline =~ /^.\s*$/)) { |
| 3225 | CHK("BRACES", | 3234 | CHK("BRACES", |
| 3226 | "Blank lines aren't necessary before a close brace '}'\n" . $hereprev); | 3235 | "Blank lines aren't necessary before a close brace '}'\n" . $hereprev); |
| 3227 | } | 3236 | } |
| @@ -3373,6 +3382,15 @@ sub process { | |||
| 3373 | "struct spinlock should be spinlock_t\n" . $herecurr); | 3382 | "struct spinlock should be spinlock_t\n" . $herecurr); |
| 3374 | } | 3383 | } |
| 3375 | 3384 | ||
| 3385 | # check for seq_printf uses that could be seq_puts | ||
| 3386 | if ($line =~ /\bseq_printf\s*\(/) { | ||
| 3387 | my $fmt = get_quoted_string($line, $rawline); | ||
| 3388 | if ($fmt !~ /[^\\]\%/) { | ||
| 3389 | WARN("PREFER_SEQ_PUTS", | ||
| 3390 | "Prefer seq_puts to seq_printf\n" . $herecurr); | ||
| 3391 | } | ||
| 3392 | } | ||
| 3393 | |||
| 3376 | # Check for misused memsets | 3394 | # Check for misused memsets |
| 3377 | if ($^V && $^V ge 5.10.0 && | 3395 | if ($^V && $^V ge 5.10.0 && |
| 3378 | defined $stat && | 3396 | defined $stat && |
| @@ -3477,6 +3495,13 @@ sub process { | |||
| 3477 | "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); | 3495 | "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); |
| 3478 | } | 3496 | } |
| 3479 | 3497 | ||
| 3498 | # check for krealloc arg reuse | ||
| 3499 | if ($^V && $^V ge 5.10.0 && | ||
| 3500 | $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { | ||
| 3501 | WARN("KREALLOC_ARG_REUSE", | ||
| 3502 | "Reusing the krealloc arg is almost always a bug\n" . $herecurr); | ||
| 3503 | } | ||
| 3504 | |||
| 3480 | # check for alloc argument mismatch | 3505 | # check for alloc argument mismatch |
| 3481 | if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) { | 3506 | if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) { |
| 3482 | WARN("ALLOC_ARRAY_ARGS", | 3507 | WARN("ALLOC_ARRAY_ARGS", |
