From 6ab3a9701e00c2a085bac6a7a9bdcf8fc5eca6c5 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:05 -0700 Subject: checkpatch: improve "no space is necessary after a cast" test The "no space is necessary after a cast" sizeof exclusion doesn't work properly. The test reports a false positive for code like: BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6); Make it work, simplify the exclusions, and add some comments. Signed-off-by: Joe Perches Reported-by: Marek Lindner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d12435992dea..421bbb47844f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2552,8 +2552,15 @@ sub process { } } - if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && - (!defined($1) || $1 !~ /sizeof\s*/)) { +# check for space after cast like "(int) foo" or "(struct foo) bar" +# avoid checking a few false positives: +# "sizeof()" or "__alignof__()" +# function pointer declarations like "(*foo)(int) = bar;" +# structure definitions like "(struct foo) { 0 };" +# multiline macros that define functions +# known attributes or the __attribute__ keyword + if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ && + (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) { if (CHK("SPACING", "No space is necessary after a cast\n" . $herecurr) && $fix) { -- cgit v1.2.3 From 66d7a382cb5d2d40b468e68b665bbf6f9bc3400e Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:08 -0700 Subject: checkpatch: add spell checking of email subject line Only commit log and patch additions are checked for typos and spelling errors currently. Add a check of the email subject line too. Signed-off-by: Joe Perches Suggested-by: Jani Nikula Tested-by: Jani Nikula Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 421bbb47844f..c061a63afa20 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2303,7 +2303,8 @@ sub process { } # Check for various typo / spelling mistakes - if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) { + if (defined($misspellings) && + ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { my $typo = $1; my $typo_fix = $spelling_fix{lc($typo)}; -- cgit v1.2.3 From ebfd7d62375316ff532b6b9bae9d88a29f434ba7 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:14 -0700 Subject: checkpatch: add optional --codespell dictionary to find more typos If a codespell dictionary exists, use it if desired. default is off, maybe it could be turned on later. codespell's dictionary format allows multiple possible corrections, ignore that for now and only use the first suggestion. Also add \b to spelling test so that consecutive misspelled words are found properly. Signed-off-by: Joe Perches Cc: Andy Whitcroft Cc: Kees Cook Cc: Masanari Iida Cc: Lucas De Marchi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c061a63afa20..6b79beb2751d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -47,6 +47,8 @@ my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; my $spelling_file = "$D/spelling.txt"; +my $codespell = 0; +my $codespellfile = "/usr/local/share/codespell/dictionary.txt"; sub help { my ($exitcode) = @_; @@ -88,6 +90,9 @@ Options: file. It's your fault if there's no backup or git --ignore-perl-version override checking of perl version. expect runtime errors. + --codespell Use the codespell dictionary for spelling/typos + (default:/usr/local/share/codespell/dictionary.txt) + --codespellfile Use this codespell dictionary -h, --help, --version display this help and exit When FILE is - read standard input. @@ -146,6 +151,8 @@ GetOptions( 'ignore-perl-version!' => \$ignore_perl_version, 'debug=s' => \%debug, 'test-only=s' => \$tst_only, + 'codespell!' => \$codespell, + 'codespellfile=s' => \$codespellfile, 'h|help' => \$help, 'version' => \$help ) or help(1); @@ -449,7 +456,6 @@ my $misspellings; my %spelling_fix; if (open(my $spelling, '<', $spelling_file)) { - my @spelling_list; while (<$spelling>) { my $line = $_; @@ -461,15 +467,39 @@ if (open(my $spelling, '<', $spelling_file)) { my ($suspect, $fix) = split(/\|\|/, $line); - push(@spelling_list, $suspect); $spelling_fix{$suspect} = $fix; } close($spelling); - $misspellings = join("|", @spelling_list); } else { warn "No typos will be found - file '$spelling_file': $!\n"; } +if ($codespell) { + if (open(my $spelling, '<', $codespellfile)) { + while (<$spelling>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + next if ($line =~ m/, disabled/i); + + $line =~ s/,.*$//; + + my ($suspect, $fix) = split(/->/, $line); + + $spelling_fix{$suspect} = $fix; + } + close($spelling); + } else { + warn "No codespell typos will be found - file '$codespellfile': $!\n"; + } +} + +$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; + sub build_types { my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; @@ -2305,7 +2335,7 @@ sub process { # Check for various typo / spelling mistakes if (defined($misspellings) && ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { - while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { + while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) { my $typo = $1; my $typo_fix = $spelling_fix{lc($typo)}; $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); -- cgit v1.2.3 From b392c64f59d7b088aefb4e86d208cd6d3b93eefb Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:16 -0700 Subject: checkpatch: match more world writable permissions Currently checkpatch will fuss if one uses world writable settings in debugfs files and DEVICE_ATTR uses by testing S_IWUGO but not testing S_IWOTH, S_IRWXUGO or S_IALLUGO. Extend the check to catch all cases exporting world writable permissions including octal values. [akpm@linux-foundation.org: remove stray $] Signed-off-by: Joe Perches Original-patch-by: Nicholas Mc Guire Cc: Guenter Roeck Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 6b79beb2751d..5748c35d0342 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -443,6 +443,14 @@ foreach my $entry (@mode_permission_funcs) { $mode_perms_search .= $entry->[0]; } +our $mode_perms_world_writable = qr{ + S_IWUGO | + S_IWOTH | + S_IRWXUGO | + S_IALLUGO | + 0[0-7][0-7][2367] +}x; + our $allowed_asm_includes = qr{(?x: irq| memory| @@ -5356,8 +5364,8 @@ sub process { } } - if ($line =~ /debugfs_create_file.*S_IWUGO/ || - $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { + if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ || + $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) { WARN("EXPORTED_WORLD_WRITABLE", "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); } -- cgit v1.2.3 From f34e4a4f979c0d39f741bc809127fcf2167a7389 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:19 -0700 Subject: checkpatch: improve return negative errno check Add a few conditions to the test to find return (ERRNO); Make the output message a bit less cryptic too. Signed-off-by: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 5748c35d0342..45babf2243f3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4009,12 +4009,12 @@ sub process { } } -# Return of what appears to be an errno should normally be -'ve - if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { +# Return of what appears to be an errno should normally be negative + if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) { my $name = $1; if ($name ne 'EOF' && $name ne 'ERROR') { WARN("USE_NEGATIVE_ERRNO", - "return of an errno should typically be -ve (return -$1)\n" . $herecurr); + "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); } } -- cgit v1.2.3 From ab7e23f3448e55f4808f443a7b98ded6707701bb Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:22 -0700 Subject: checkpatch: add test for repeated const uses Using 'const const *' is generally meant to be written 'const * const'. Add a test for the miswritten form. Signed-off-by: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 45babf2243f3..d54a814a4bc8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -323,6 +323,7 @@ our $Operators = qr{ our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; +our $BasicType; our $NonptrType; our $NonptrTypeMisordered; our $NonptrTypeWithAttr; @@ -514,6 +515,11 @@ sub build_types { my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; + $BasicType = qr{ + (?:$typeOtherOSTypedefs\b)| + (?:$typeTypedefs\b)| + (?:${all}\b) + }x; $NonptrType = qr{ (?:$Modifier\s+|const\s+)* (?: @@ -3192,6 +3198,18 @@ sub process { $herecurr); } +# check for const const where is not a pointer or array type + if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { + my $found = $1; + if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) { + WARN("CONST_CONST", + "'const $found const *' should probably be 'const $found * const'\n" . $herecurr); + } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) { + WARN("CONST_CONST", + "'const $found const' should probably be 'const $found'\n" . $herecurr); + } + } + # check for non-global char *foo[] = {"bar", ...} declarations. if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { WARN("STATIC_CONST_CHAR_ARRAY", -- cgit v1.2.3 From 0e212e0a720601fabda102f7998d27625f9e144a Mon Sep 17 00:00:00 2001 From: Fabian Frederick Date: Thu, 16 Apr 2015 12:44:25 -0700 Subject: checkpatch: don't ask for asm/file.h to linux/file.h unconditionally Currently checkpatch warns when asm/file.h is included and linux/file.h exists. That conversion can be made when linux/file.h includes asm/file.h which is not always the case.(See signal.h) Signed-off-by: Fabian Frederick Cc: Andy Whitcroft Acked-by: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d54a814a4bc8..c72e7ee1000b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4242,7 +4242,8 @@ sub process { } } -#warn if is #included and is available (uses RAW line) +# warn if is #included and is available and includes +# itself (uses RAW line) if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\}) { my $file = "$1.h"; my $checkfile = "include/linux/$file"; @@ -4250,12 +4251,15 @@ sub process { $realfile ne $checkfile && $1 !~ /$allowed_asm_includes/) { - if ($realfile =~ m{^arch/}) { - CHK("ARCH_INCLUDE_LINUX", - "Consider using #include instead of \n" . $herecurr); - } else { - WARN("INCLUDE_LINUX", - "Use #include instead of \n" . $herecurr); + my $asminclude = `grep -Ec "#include\\s+" $root/$checkfile`; + if ($asminclude > 0) { + if ($realfile =~ m{^arch/}) { + CHK("ARCH_INCLUDE_LINUX", + "Consider using #include instead of \n" . $herecurr); + } else { + WARN("INCLUDE_LINUX", + "Use #include instead of \n" . $herecurr); + } } } } -- cgit v1.2.3 From 2a076f40d8c9be95bee7bcf18436655e1140447f Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:28 -0700 Subject: checkpatch, SubmittingPatches: suggest line wrapping commit messages at 75 columns Commit messages lines are sometimes overly long. Suggest line wrapping at 75 columns so the default git commit log indentation of 4 plus the commit message text still fits on an 80 column screen. Add a checkpatch test for long commit messages lines too. Signed-off-by: Joe Perches Cc: David Miller Cc: Jonathan Corbet Cc: Ian Morris Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- Documentation/SubmittingPatches | 4 ++-- scripts/checkpatch.pl | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches index 447671bd2927..b03a832a08e2 100644 --- a/Documentation/SubmittingPatches +++ b/Documentation/SubmittingPatches @@ -614,8 +614,8 @@ The canonical patch message body contains the following: - An empty line. - - The body of the explanation, which will be copied to the - permanent changelog to describe this patch. + - The body of the explanation, line wrapped at 75 columns, which will + be copied to the permanent changelog to describe this patch. - The "Signed-off-by:" lines, described above, which will also go in the changelog. diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c72e7ee1000b..9a8b2bd14dc2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1898,6 +1898,7 @@ sub process { my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch + my $commit_log_long_line = 0; my $reported_maintainer_file = 0; my $non_utf8_charset = 0; @@ -2233,6 +2234,14 @@ sub process { "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); } +# Check for line lengths > 75 in commit log, warn once + if ($in_commit_log && !$commit_log_long_line && + length($line) > 75) { + WARN("COMMIT_LOG_LONG_LINE", + "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr); + $commit_log_long_line = 1; + } + # Check for git id commit length and improperly formed commit descriptions if ($in_commit_log && $line =~ /\b(c)ommit\s+([0-9a-f]{5,})/i) { my $init_char = $1; -- cgit v1.2.3 From 29a3c46673a5e3ee22feaba7020a280486c78f0a Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:30 -0700 Subject: checkpatch: add #define foo "string" long line exception There are #defines with long string constants like: #define foo "some really long string > 80 columns" Add a long line exception for them. Miscellanea: Use the $String variable for slightly better readability Signed-off-by: Joe Perches Reported-by: Madalin-Cristian Bucur Cc: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9a8b2bd14dc2..36d7e704af8f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2513,8 +2513,9 @@ sub process { #line length limit if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && $rawline !~ /^.\s*\*\s*\@$Ident\s/ && - !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ || - $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && + !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?$String\s*(?:|,|\)\s*;)\s*$/ || + $line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ || + $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) && $length > $max_line_length) { WARN("LONG_LINE", -- cgit v1.2.3 From 6d07d01b62b2d81500803058f736b46677ec873a Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:33 -0700 Subject: checkpatch: add uart_ops to normally const structs Add another struct to the list of normally const struct types Signed-off-by: Joe Perches Cc: Andy Whitcroft Cc: Maxime Coquelin Cc: Greg Kroah-Hartman Cc: Jiri Slaby Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 36d7e704af8f..ea628ebfa20e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -5339,6 +5339,7 @@ sub process { stacktrace_ops| sysfs_ops| tty_operations| + uart_ops| usb_mon_operations| wd_ops}x; if ($line !~ /\bconst\b/ && -- cgit v1.2.3 From b598b67060f14eb8c34d0cef1db4727dab56ef91 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:36 -0700 Subject: checkpatch: add 'Prefer ARRAY_SIZE" test Add a test for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo). Signed-off-by: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ea628ebfa20e..6c11cb61e9f4 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3227,6 +3227,19 @@ sub process { $herecurr); } +# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo) + if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) { + my $array = $1; + if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) { + my $array_div = $1; + if (WARN("ARRAY_SIZE", + "Prefer ARRAY_SIZE($array)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/; + } + } + } + # check for function declarations without arguments like "int foo()" if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { if (ERROR("FUNCTION_WITHOUT_ARGS", -- cgit v1.2.3 From d7fe8065ad891a2ad38b73ff10b97d08f0fb3b0b Mon Sep 17 00:00:00 2001 From: Sam Bobroff Date: Thu, 16 Apr 2015 12:44:39 -0700 Subject: checkpatch: improve operator spacing check Code such as: x = timercmp(&now, &end, <); Will currently trigger a checkpatch error. e.g. ERROR: spaces required around that '<' This is because the "Ignore operators passed as parameters" check looks only for a comma following the operator. Improve the check by also looking for a close parenthesis. Signed-off-by: Sam Bobroff Cc: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 6c11cb61e9f4..78a951f80706 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3652,7 +3652,7 @@ sub process { # Ignore operators passed as parameters. if ($op_type ne 'V' && - $ca =~ /\s$/ && $cc =~ /^\s*,/) { + $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) { # # Ignore comments # } elsif ($op =~ /^$;+$/) { -- cgit v1.2.3 From c17893c7407fbe988f5901596c3e5e75c0dc0f67 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:42 -0700 Subject: checkpatch: add a test for const with __read_mostly uses const objects shouldn't be __read_mostly. They are read-only. Marking these objects as __read_mostly causes section conflicts with LTO linking. So add a test to try to avoid this issue. Signed-off-by: Joe Perches Cc: Andy Whitcroft Cc: Andi Kleen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 78a951f80706..28516587baba 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4791,6 +4791,16 @@ sub process { } } +# check for __read_mostly with const non-pointer (should just be const) + if ($line =~ /\b__read_mostly\b/ && + $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) { + if (ERROR("CONST_READ_MOSTLY", + "Invalid use of __read_mostly with const type\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//; + } + } + # don't use __constant_ functions outside of include/uapi/ if ($realfile !~ m@^include/uapi/@ && $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) { -- cgit v1.2.3 From 91c9afaf97ee554d2cd3042a5ad01ad21c99e8c4 Mon Sep 17 00:00:00 2001 From: Andy Lutomirski Date: Thu, 16 Apr 2015 12:44:44 -0700 Subject: checkpatch.pl: new instances of ENOSYS are errors ENOSYS means that a nonexistent system call was called. We have a bad habit of using it for things like invalid operations on otherwise valid syscalls. We should avoid this in new code. Pervasive incorrect usage of ENOSYS came up at the kernel summit ABI review discussion. Let's see if checkpatch can help. I'll submit a separate patch for include/uapi/asm-generic/errno.h. Signed-off-by: Andy Lutomirski Cc: Pavel Machek Cc: Michael Kerrisk Cc: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 28516587baba..561f41ef531f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3396,6 +3396,14 @@ sub process { "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr); } +# ENOSYS means "bad syscall nr" and nothing else. This will have a small +# number of false positives, but assembly files are not checked, so at +# least the arch entry code will not trigger this warning. + if ($line =~ /\bENOSYS\b/) { + WARN("ENOSYS", + "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr); + } + # function brace can't be on same line, except for #defines of do while, # or if closed on same line if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and -- cgit v1.2.3 From 323b267faff4db5f2424b6c09ab78a272393b69e Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:50 -0700 Subject: checkpatch: fix --fix use with a patch of multiple files If a patch touches multiple files, the --fix and --fix-inplace option doesn't keep the proper line count and makes the new patch file not able to be applied via bad offset line numbers when lines are added or deleted by the --fix option. Dunno how that extra backslash snuck in there. Signed-off-by: Joe Perches Cc: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 561f41ef531f..35aecb3b013c 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1690,7 +1690,7 @@ sub fix_inserted_deleted_lines { foreach my $old_line (@{$linesRef}) { my $save_line = 1; my $line = $old_line; #don't modify the array - if ($line =~ /^(?:\+\+\+\|\-\-\-)\s+\S+/) { #new filename + if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename $delta_offset = 0; } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk $range_last_linenr = $new_linenr; -- cgit v1.2.3 From e0df7e1faebad9a7ac0931d03f86fcd5c0d1896e Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Apr 2015 12:44:53 -0700 Subject: checkpatch: avoid "spaces required around that ':'" false positive Since commit 1f65f947a6a8 ("checkpatch: add checks for question mark and colon spacing") back in 2008, checkpatch has reported false positive for asm volatile uses of "::" checkpatch thinks colons should always have spaces around it. Add an exception for colons with colons on either side for this valid asm volatile (and c++) use. Signed-off-by: Joe Perches Reported-by: Yehuda Yitschak Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts/checkpatch.pl') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 35aecb3b013c..89b1df4e72ab 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3845,6 +3845,14 @@ sub process { $ok = 1; } + # for asm volatile statements + # ignore a colon with another + # colon immediately before or after + if (($op eq ':') && + ($ca =~ /:$/ || $cc =~ /^:/)) { + $ok = 1; + } + # messages are ERROR, but ?: are CHK if ($ok == 0) { my $msg_type = \&ERROR; -- cgit v1.2.3