From 0ab9019184f1de09409434204cb8fbffe8286e00 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 10 Dec 2014 15:51:57 -0800 Subject: [PATCH] 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< Cc: David Miller Cc: Jiri Pirko Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 { } } +# check for #defines like: 1 << 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 if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { my $has_break = 0;