diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-07 01:15:42 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-07 01:15:42 -0500 |
commit | a2e5790d841658485d642196dbb0927303d6c22f (patch) | |
tree | b3d28c9bcb7da6880806146fd22a88a7ee7f733e /scripts/checkpatch.pl | |
parent | ab2d92ad881da11331280aedf612d82e61cb6d41 (diff) | |
parent | 60c3e026d73ccabb075fb70ba02f8512ab40cf2c (diff) |
Merge branch 'akpm' (patches from Andrew)
Merge misc updates from Andrew Morton:
- kasan updates
- procfs
- lib/bitmap updates
- other lib/ updates
- checkpatch tweaks
- rapidio
- ubsan
- pipe fixes and cleanups
- lots of other misc bits
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (114 commits)
Documentation/sysctl/user.txt: fix typo
MAINTAINERS: update ARM/QUALCOMM SUPPORT patterns
MAINTAINERS: update various PALM patterns
MAINTAINERS: update "ARM/OXNAS platform support" patterns
MAINTAINERS: update Cortina/Gemini patterns
MAINTAINERS: remove ARM/CLKDEV SUPPORT file pattern
MAINTAINERS: remove ANDROID ION pattern
mm: docs: add blank lines to silence sphinx "Unexpected indentation" errors
mm: docs: fix parameter names mismatch
mm: docs: fixup punctuation
pipe: read buffer limits atomically
pipe: simplify round_pipe_size()
pipe: reject F_SETPIPE_SZ with size over UINT_MAX
pipe: fix off-by-one error when checking buffer limits
pipe: actually allow root to exceed the pipe buffer limits
pipe, sysctl: remove pipe_proc_fn()
pipe, sysctl: drop 'min' parameter from pipe-max-size converter
kasan: rework Kconfig settings
crash_dump: is_kdump_kernel can be boolean
kernel/mutex: mutex_is_locked can be boolean
...
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 144 |
1 files changed, 115 insertions, 29 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e954df2b2077..3d4040322ae1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -566,6 +566,7 @@ foreach my $entry (@mode_permission_funcs) { | |||
566 | $mode_perms_search .= '|' if ($mode_perms_search ne ""); | 566 | $mode_perms_search .= '|' if ($mode_perms_search ne ""); |
567 | $mode_perms_search .= $entry->[0]; | 567 | $mode_perms_search .= $entry->[0]; |
568 | } | 568 | } |
569 | $mode_perms_search = "(?:${mode_perms_search})"; | ||
569 | 570 | ||
570 | our $mode_perms_world_writable = qr{ | 571 | our $mode_perms_world_writable = qr{ |
571 | S_IWUGO | | 572 | S_IWUGO | |
@@ -600,6 +601,37 @@ foreach my $entry (keys %mode_permission_string_types) { | |||
600 | $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); | 601 | $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); |
601 | $mode_perms_string_search .= $entry; | 602 | $mode_perms_string_search .= $entry; |
602 | } | 603 | } |
604 | our $single_mode_perms_string_search = "(?:${mode_perms_string_search})"; | ||
605 | our $multi_mode_perms_string_search = qr{ | ||
606 | ${single_mode_perms_string_search} | ||
607 | (?:\s*\|\s*${single_mode_perms_string_search})* | ||
608 | }x; | ||
609 | |||
610 | sub perms_to_octal { | ||
611 | my ($string) = @_; | ||
612 | |||
613 | return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/); | ||
614 | |||
615 | my $val = ""; | ||
616 | my $oval = ""; | ||
617 | my $to = 0; | ||
618 | my $curpos = 0; | ||
619 | my $lastpos = 0; | ||
620 | while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) { | ||
621 | $curpos = pos($string); | ||
622 | my $match = $2; | ||
623 | my $omatch = $1; | ||
624 | last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); | ||
625 | $lastpos = $curpos; | ||
626 | $to |= $mode_permission_string_types{$match}; | ||
627 | $val .= '\s*\|\s*' if ($val ne ""); | ||
628 | $val .= $match; | ||
629 | $oval .= $omatch; | ||
630 | } | ||
631 | $oval =~ s/^\s*\|\s*//; | ||
632 | $oval =~ s/\s*\|\s*$//; | ||
633 | return sprintf("%04o", $to); | ||
634 | } | ||
603 | 635 | ||
604 | our $allowed_asm_includes = qr{(?x: | 636 | our $allowed_asm_includes = qr{(?x: |
605 | irq| | 637 | irq| |
@@ -2875,6 +2907,7 @@ sub process { | |||
2875 | # logging functions like pr_info that end in a string | 2907 | # logging functions like pr_info that end in a string |
2876 | # lines with a single string | 2908 | # lines with a single string |
2877 | # #defines that are a single string | 2909 | # #defines that are a single string |
2910 | # lines with an RFC3986 like URL | ||
2878 | # | 2911 | # |
2879 | # There are 3 different line length message types: | 2912 | # There are 3 different line length message types: |
2880 | # LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length | 2913 | # LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length |
@@ -2906,6 +2939,10 @@ sub process { | |||
2906 | $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) { | 2939 | $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) { |
2907 | $msg_type = ""; | 2940 | $msg_type = ""; |
2908 | 2941 | ||
2942 | # URL ($rawline is used in case the URL is in a comment) | ||
2943 | } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) { | ||
2944 | $msg_type = ""; | ||
2945 | |||
2909 | # Otherwise set the alternate message types | 2946 | # Otherwise set the alternate message types |
2910 | 2947 | ||
2911 | # a comment starts before $max_line_length | 2948 | # a comment starts before $max_line_length |
@@ -2983,7 +3020,7 @@ sub process { | |||
2983 | 3020 | ||
2984 | # check indentation starts on a tab stop | 3021 | # check indentation starts on a tab stop |
2985 | if ($^V && $^V ge 5.10.0 && | 3022 | if ($^V && $^V ge 5.10.0 && |
2986 | $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$))/) { | 3023 | $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) { |
2987 | my $indent = length($1); | 3024 | my $indent = length($1); |
2988 | if ($indent % 8) { | 3025 | if ($indent % 8) { |
2989 | if (WARN("TABSTOP", | 3026 | if (WARN("TABSTOP", |
@@ -3882,10 +3919,12 @@ sub process { | |||
3882 | 3919 | ||
3883 | # function brace can't be on same line, except for #defines of do while, | 3920 | # function brace can't be on same line, except for #defines of do while, |
3884 | # or if closed on same line | 3921 | # or if closed on same line |
3885 | if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and | 3922 | if ($^V && $^V ge 5.10.0 && |
3886 | !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) { | 3923 | $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ && |
3924 | $sline !~ /\#\s*define\b.*do\s*\{/ && | ||
3925 | $sline !~ /}/) { | ||
3887 | if (ERROR("OPEN_BRACE", | 3926 | if (ERROR("OPEN_BRACE", |
3888 | "open brace '{' following function declarations go on the next line\n" . $herecurr) && | 3927 | "open brace '{' following function definitions go on the next line\n" . $herecurr) && |
3889 | $fix) { | 3928 | $fix) { |
3890 | fix_delete_line($fixlinenr, $rawline); | 3929 | fix_delete_line($fixlinenr, $rawline); |
3891 | my $fixed_line = $rawline; | 3930 | my $fixed_line = $rawline; |
@@ -4489,7 +4528,9 @@ sub process { | |||
4489 | } | 4528 | } |
4490 | 4529 | ||
4491 | # check for unnecessary parentheses around comparisons in if uses | 4530 | # check for unnecessary parentheses around comparisons in if uses |
4492 | if ($^V && $^V ge 5.10.0 && defined($stat) && | 4531 | # when !drivers/staging or command-line uses --strict |
4532 | if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) && | ||
4533 | $^V && $^V ge 5.10.0 && defined($stat) && | ||
4493 | $stat =~ /(^.\s*if\s*($balanced_parens))/) { | 4534 | $stat =~ /(^.\s*if\s*($balanced_parens))/) { |
4494 | my $if_stat = $1; | 4535 | my $if_stat = $1; |
4495 | my $test = substr($2, 1, -1); | 4536 | my $test = substr($2, 1, -1); |
@@ -5307,7 +5348,7 @@ sub process { | |||
5307 | } | 5348 | } |
5308 | 5349 | ||
5309 | # check for line continuations in quoted strings with odd counts of " | 5350 | # check for line continuations in quoted strings with odd counts of " |
5310 | if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { | 5351 | if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) { |
5311 | WARN("LINE_CONTINUATIONS", | 5352 | WARN("LINE_CONTINUATIONS", |
5312 | "Avoid line continuations in quoted strings\n" . $herecurr); | 5353 | "Avoid line continuations in quoted strings\n" . $herecurr); |
5313 | } | 5354 | } |
@@ -6269,8 +6310,69 @@ sub process { | |||
6269 | "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); | 6310 | "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); |
6270 | } | 6311 | } |
6271 | 6312 | ||
6313 | # check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO> | ||
6314 | # and whether or not function naming is typical and if | ||
6315 | # DEVICE_ATTR permissions uses are unusual too | ||
6316 | if ($^V && $^V ge 5.10.0 && | ||
6317 | defined $stat && | ||
6318 | $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) { | ||
6319 | my $var = $1; | ||
6320 | my $perms = $2; | ||
6321 | my $show = $3; | ||
6322 | my $store = $4; | ||
6323 | my $octal_perms = perms_to_octal($perms); | ||
6324 | if ($show =~ /^${var}_show$/ && | ||
6325 | $store =~ /^${var}_store$/ && | ||
6326 | $octal_perms eq "0644") { | ||
6327 | if (WARN("DEVICE_ATTR_RW", | ||
6328 | "Use DEVICE_ATTR_RW\n" . $herecurr) && | ||
6329 | $fix) { | ||
6330 | $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/; | ||
6331 | } | ||
6332 | } elsif ($show =~ /^${var}_show$/ && | ||
6333 | $store =~ /^NULL$/ && | ||
6334 | $octal_perms eq "0444") { | ||
6335 | if (WARN("DEVICE_ATTR_RO", | ||
6336 | "Use DEVICE_ATTR_RO\n" . $herecurr) && | ||
6337 | $fix) { | ||
6338 | $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/; | ||
6339 | } | ||
6340 | } elsif ($show =~ /^NULL$/ && | ||
6341 | $store =~ /^${var}_store$/ && | ||
6342 | $octal_perms eq "0200") { | ||
6343 | if (WARN("DEVICE_ATTR_WO", | ||
6344 | "Use DEVICE_ATTR_WO\n" . $herecurr) && | ||
6345 | $fix) { | ||
6346 | $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/; | ||
6347 | } | ||
6348 | } elsif ($octal_perms eq "0644" || | ||
6349 | $octal_perms eq "0444" || | ||
6350 | $octal_perms eq "0200") { | ||
6351 | my $newshow = "$show"; | ||
6352 | $newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show"); | ||
6353 | my $newstore = $store; | ||
6354 | $newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store"); | ||
6355 | my $rename = ""; | ||
6356 | if ($show ne $newshow) { | ||
6357 | $rename .= " '$show' to '$newshow'"; | ||
6358 | } | ||
6359 | if ($store ne $newstore) { | ||
6360 | $rename .= " '$store' to '$newstore'"; | ||
6361 | } | ||
6362 | WARN("DEVICE_ATTR_FUNCTIONS", | ||
6363 | "Consider renaming function(s)$rename\n" . $herecurr); | ||
6364 | } else { | ||
6365 | WARN("DEVICE_ATTR_PERMS", | ||
6366 | "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr); | ||
6367 | } | ||
6368 | } | ||
6369 | |||
6272 | # Mode permission misuses where it seems decimal should be octal | 6370 | # Mode permission misuses where it seems decimal should be octal |
6273 | # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop | 6371 | # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop |
6372 | # o Ignore module_param*(...) uses with a decimal 0 permission as that has a | ||
6373 | # specific definition of not visible in sysfs. | ||
6374 | # o Ignore proc_create*(...) uses with a decimal 0 permission as that means | ||
6375 | # use the default permissions | ||
6274 | if ($^V && $^V ge 5.10.0 && | 6376 | if ($^V && $^V ge 5.10.0 && |
6275 | defined $stat && | 6377 | defined $stat && |
6276 | $line =~ /$mode_perms_search/) { | 6378 | $line =~ /$mode_perms_search/) { |
@@ -6294,8 +6396,9 @@ sub process { | |||
6294 | if ($stat =~ /$test/) { | 6396 | if ($stat =~ /$test/) { |
6295 | my $val = $1; | 6397 | my $val = $1; |
6296 | $val = $6 if ($skip_args ne ""); | 6398 | $val = $6 if ($skip_args ne ""); |
6297 | if (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || | 6399 | if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") && |
6298 | ($val =~ /^$Octal$/ && length($val) ne 4)) { | 6400 | (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || |
6401 | ($val =~ /^$Octal$/ && length($val) ne 4))) { | ||
6299 | ERROR("NON_OCTAL_PERMISSIONS", | 6402 | ERROR("NON_OCTAL_PERMISSIONS", |
6300 | "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real); | 6403 | "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real); |
6301 | } | 6404 | } |
@@ -6308,30 +6411,13 @@ sub process { | |||
6308 | } | 6411 | } |
6309 | 6412 | ||
6310 | # check for uses of S_<PERMS> that could be octal for readability | 6413 | # check for uses of S_<PERMS> that could be octal for readability |
6311 | if ($line =~ /\b$mode_perms_string_search\b/) { | 6414 | if ($line =~ /\b($multi_mode_perms_string_search)\b/) { |
6312 | my $val = ""; | 6415 | my $oval = $1; |
6313 | my $oval = ""; | 6416 | my $octal = perms_to_octal($oval); |
6314 | my $to = 0; | ||
6315 | my $curpos = 0; | ||
6316 | my $lastpos = 0; | ||
6317 | while ($line =~ /\b(($mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) { | ||
6318 | $curpos = pos($line); | ||
6319 | my $match = $2; | ||
6320 | my $omatch = $1; | ||
6321 | last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); | ||
6322 | $lastpos = $curpos; | ||
6323 | $to |= $mode_permission_string_types{$match}; | ||
6324 | $val .= '\s*\|\s*' if ($val ne ""); | ||
6325 | $val .= $match; | ||
6326 | $oval .= $omatch; | ||
6327 | } | ||
6328 | $oval =~ s/^\s*\|\s*//; | ||
6329 | $oval =~ s/\s*\|\s*$//; | ||
6330 | my $octal = sprintf("%04o", $to); | ||
6331 | if (WARN("SYMBOLIC_PERMS", | 6417 | if (WARN("SYMBOLIC_PERMS", |
6332 | "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) && | 6418 | "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) && |
6333 | $fix) { | 6419 | $fix) { |
6334 | $fixed[$fixlinenr] =~ s/$val/$octal/; | 6420 | $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/; |
6335 | } | 6421 | } |
6336 | } | 6422 | } |
6337 | 6423 | ||