diff options
| author | Joe Perches <joe@perches.com> | 2014-12-10 18:51:57 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-10 20:41:12 -0500 |
| commit | 0ab9019184f1de09409434204cb8fbffe8286e00 (patch) | |
| tree | f1afe23858fb53702ee9a30f0fa2740e60efea25 /scripts | |
| parent | f512357646268451da0d7e1e0100c55df6c8cea6 (diff) | |
checkpatch: add --strict preference for #defines using BIT(foo)
Using BIT(foo) and BIT_ULL(bar) is more common now. Suggest using these
macros over #defines with 1<<value.
Add a --fix option too.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: David Miller <davem@davemloft.net>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 518cc2e58439..d06b6be2841e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -4975,6 +4975,17 @@ sub process { | |||
| 4975 | } | 4975 | } |
| 4976 | } | 4976 | } |
| 4977 | 4977 | ||
| 4978 | # check for #defines like: 1 << <digit> that could be BIT(digit) | ||
| 4979 | if ($line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) { | ||
| 4980 | my $ull = ""; | ||
| 4981 | $ull = "_ULL" if (defined($1) && $1 =~ /ll/i); | ||
| 4982 | if (CHK("BIT_MACRO", | ||
| 4983 | "Prefer using the BIT$ull macro\n" . $herecurr) && | ||
| 4984 | $fix) { | ||
| 4985 | $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/; | ||
| 4986 | } | ||
| 4987 | } | ||
| 4988 | |||
| 4978 | # check for case / default statements not preceded by break/fallthrough/switch | 4989 | # check for case / default statements not preceded by break/fallthrough/switch |
| 4979 | if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { | 4990 | if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { |
| 4980 | my $has_break = 0; | 4991 | my $has_break = 0; |
