diff options
author | Joe Perches <joe@perches.com> | 2014-04-03 17:49:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-03 19:21:12 -0400 |
commit | 2435880fe5cd51cd73c403aa4c07eadc3de799db (patch) | |
tree | 0699aa30fb71bf84ac8d0cc295b0b0eaddf52a2b /scripts | |
parent | 91f72e9c6ed1433b65c2944a2953968088607987 (diff) |
checkpatch: add checks for constant non-octal permissions
umode_t permissions are sometimes mistakenly written with decimal
constants. Verify that numeric permissions are using octal.
Add a list of the most commonly used functions and macros that have
umode_t permissions and the argument position.
Add a $Octal type to $Constant.
Allow $LvalOrFunc to be a pointer indirection too.
Signed-off-by: Joe Perches <joe@perches.com>
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 | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 19591af206c5..0b40af57e71e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -289,11 +289,12 @@ our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u}; | |||
289 | our $Binary = qr{(?i)0b[01]+$Int_type?}; | 289 | our $Binary = qr{(?i)0b[01]+$Int_type?}; |
290 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; | 290 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; |
291 | our $Int = qr{[0-9]+$Int_type?}; | 291 | our $Int = qr{[0-9]+$Int_type?}; |
292 | our $Octal = qr{0[0-7]+$Int_type?}; | ||
292 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; | 293 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; |
293 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; | 294 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; |
294 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; | 295 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; |
295 | our $Float = qr{$Float_hex|$Float_dec|$Float_int}; | 296 | our $Float = qr{$Float_hex|$Float_dec|$Float_int}; |
296 | our $Constant = qr{$Float|$Binary|$Hex|$Int}; | 297 | our $Constant = qr{$Float|$Binary|$Octal|$Hex|$Int}; |
297 | our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; | 298 | our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; |
298 | our $Compare = qr{<=|>=|==|!=|<|>}; | 299 | our $Compare = qr{<=|>=|==|!=|<|>}; |
299 | our $Arithmetic = qr{\+|-|\*|\/|%}; | 300 | our $Arithmetic = qr{\+|-|\*|\/|%}; |
@@ -378,6 +379,15 @@ our @modifierList = ( | |||
378 | qr{fastcall}, | 379 | qr{fastcall}, |
379 | ); | 380 | ); |
380 | 381 | ||
382 | our @mode_permission_funcs = ( | ||
383 | ["module_param", 3], | ||
384 | ["module_param_(?:array|named|string)", 4], | ||
385 | ["module_param_array_named", 5], | ||
386 | ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2], | ||
387 | ["proc_create(?:_data|)", 2], | ||
388 | ["(?:CLASS|DEVICE|SENSOR)_ATTR", 2], | ||
389 | ); | ||
390 | |||
381 | our $allowed_asm_includes = qr{(?x: | 391 | our $allowed_asm_includes = qr{(?x: |
382 | irq| | 392 | irq| |
383 | memory | 393 | memory |
@@ -423,7 +433,7 @@ our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; | |||
423 | # Any use must be runtime checked with $^V | 433 | # Any use must be runtime checked with $^V |
424 | 434 | ||
425 | our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; | 435 | our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; |
426 | our $LvalOrFunc = qr{($Lval)\s*($balanced_parens{0,1})\s*}; | 436 | our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*}; |
427 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; | 437 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; |
428 | 438 | ||
429 | sub deparenthesize { | 439 | sub deparenthesize { |
@@ -4473,6 +4483,28 @@ sub process { | |||
4473 | WARN("EXPORTED_WORLD_WRITABLE", | 4483 | WARN("EXPORTED_WORLD_WRITABLE", |
4474 | "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); | 4484 | "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); |
4475 | } | 4485 | } |
4486 | |||
4487 | foreach my $entry (@mode_permission_funcs) { | ||
4488 | my $func = $entry->[0]; | ||
4489 | my $arg_pos = $entry->[1]; | ||
4490 | |||
4491 | my $skip_args = ""; | ||
4492 | if ($arg_pos > 1) { | ||
4493 | $arg_pos--; | ||
4494 | $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}"; | ||
4495 | } | ||
4496 | my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]"; | ||
4497 | if ($^V && $^V ge 5.10.0 && | ||
4498 | $line =~ /$test/) { | ||
4499 | my $val = $1; | ||
4500 | $val = $6 if ($skip_args ne ""); | ||
4501 | |||
4502 | if ($val =~ /^$Int$/ && $val !~ /^$Octal$/) { | ||
4503 | ERROR("NON_OCTAL_PERMISSIONS", | ||
4504 | "Use octal not decimal permissions\n" . $herecurr); | ||
4505 | } | ||
4506 | } | ||
4507 | } | ||
4476 | } | 4508 | } |
4477 | 4509 | ||
4478 | # If we have no input at all, then there is nothing to report on | 4510 | # If we have no input at all, then there is nothing to report on |