aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2013-07-03 18:05:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:44 -0400
commit95e2c6023b0e4c8499fb521697f79215f69135fe (patch)
tree25eb9f42cf21e5476bbdcd4375fa71a546e0b503 /scripts/checkpatch.pl
parentbe79794bc116fc0c264be1a599433c92ec9e34f5 (diff)
checkpatch: warn when using gcc's binary constant ("0b") extension
The gcc extension for binary constants that start with 0b is only supported with gcc version 4.3 or higher. The kernel can still be compiled with earlier versions of gcc, so have checkpatch emit a warning for these constants. Restructure checkpatch's constant finding code a bit to support finding these binary constants. Signed-off-by: Joe Perches <joe@perches.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Whitcroft <apw@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl16
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f1aad19b475c..517da26d9a2d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -230,11 +230,15 @@ our $Inline = qr{inline|__always_inline|noinline};
230our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; 230our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
231our $Lval = qr{$Ident(?:$Member)*}; 231our $Lval = qr{$Ident(?:$Member)*};
232 232
233our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
234our $Binary = qr{(?i)0b[01]+$Int_type?};
235our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
236our $Int = qr{[0-9]+$Int_type?};
233our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; 237our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
234our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; 238our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
235our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; 239our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
236our $Float = qr{$Float_hex|$Float_dec|$Float_int}; 240our $Float = qr{$Float_hex|$Float_dec|$Float_int};
237our $Constant = qr{$Float|(?i)(?:0x[0-9a-f]+|[0-9]+)[ul]*}; 241our $Constant = qr{$Float|$Binary|$Hex|$Int};
238our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; 242our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
239our $Compare = qr{<=|>=|==|!=|<|>}; 243our $Compare = qr{<=|>=|==|!=|<|>};
240our $Operators = qr{ 244our $Operators = qr{
@@ -2934,9 +2938,17 @@ sub process {
2934 } 2938 }
2935 } 2939 }
2936 2940
2937#CamelCase 2941#Specific variable tests
2938 while ($line =~ m{($Constant|$Lval)}g) { 2942 while ($line =~ m{($Constant|$Lval)}g) {
2939 my $var = $1; 2943 my $var = $1;
2944
2945#gcc binary extension
2946 if ($var =~ /^$Binary$/) {
2947 WARN("GCC_BINARY_CONSTANT",
2948 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr);
2949 }
2950
2951#CamelCase
2940 if ($var !~ /$Constant/ && 2952 if ($var !~ /$Constant/ &&
2941 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ && 2953 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
2942 $var !~ /"^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && 2954 $var !~ /"^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&