提交 0ab90191 编写于 作者: J Joe Perches 提交者: Linus Torvalds

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: NJoe Perches <joe@perches.com>
Cc: David Miller <davem@davemloft.net>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 f5123576
...@@ -4975,6 +4975,17 @@ sub process { ...@@ -4975,6 +4975,17 @@ sub process {
} }
} }
# check for #defines like: 1 << <digit> that could be BIT(digit)
if ($line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
my $ull = "";
$ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
if (CHK("BIT_MACRO",
"Prefer using the BIT$ull macro\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
}
}
# check for case / default statements not preceded by break/fallthrough/switch # check for case / default statements not preceded by break/fallthrough/switch
if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) {
my $has_break = 0; my $has_break = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册