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.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -289,11 +289,12 @@ our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u}; · 288 unmodified lines | ||
| 289 | 289 | our $Binary = qr{(?i)0b[01]+$Int_type?}; |
| 290 | 290 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; |
| 291 | 291 | our $Int = qr{[0-9]+$Int_type?}; |
| 292 | +our $Octal = qr{0[0-7]+$Int_type?}; | |
| 292 | 293 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; |
| 293 | 294 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; |
| 294 | 295 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; |
| 295 | 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 | 298 | our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; |
| 298 | 299 | our $Compare = qr{<=|>=|==|!=|<|>}; |
| 299 | 300 | our $Arithmetic = qr{\+|-|\*|\/|%}; |
| @@ -378,6 +379,15 @@ our @modifierList = ( · 78 unmodified lines | ||
| 378 | 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 | 391 | our $allowed_asm_includes = qr{(?x: |
| 382 | 392 | irq| |
| 383 | 393 | memory |
| @@ -423,7 +433,7 @@ our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; · 39 unmodified lines | ||
| 423 | 433 | # Any use must be runtime checked with $^V |
| 424 | 434 | |
| 425 | 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 | 437 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; |
| 428 | 438 | |
| 429 | 439 | sub deparenthesize { |
| @@ -4473,6 +4483,28 @@ sub process { · 4043 unmodified lines | ||
| 4473 | 4483 | WARN("EXPORTED_WORLD_WRITABLE", |
| 4474 | 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 | 4510 | # If we have no input at all, then there is nothing to report on |