提交 515a235e 编写于 作者: J Joe Perches 提交者: Linus Torvalds

checkpatch: improve octal permissions test speed

The current octal permissions test is very slow.

When patch ("checkpatch: add checks for constant non-octal permissions")
was added, processing time approximately tripled.

Regain almost all of the performance by not looping through all the
possible functions unless the line contains one of the functions.
Signed-off-by: NJoe Perches <joe@perches.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 daa8b059
...@@ -388,6 +388,13 @@ our @mode_permission_funcs = ( ...@@ -388,6 +388,13 @@ our @mode_permission_funcs = (
["(?:CLASS|DEVICE|SENSOR)_ATTR", 2], ["(?:CLASS|DEVICE|SENSOR)_ATTR", 2],
); );
#Create a search pattern for all these functions to speed up a loop below
our $mode_perms_search = "";
foreach my $entry (@mode_permission_funcs) {
$mode_perms_search .= '|' if ($mode_perms_search ne "");
$mode_perms_search .= $entry->[0];
}
our $allowed_asm_includes = qr{(?x: our $allowed_asm_includes = qr{(?x:
irq| irq|
memory memory
...@@ -4524,26 +4531,30 @@ sub process { ...@@ -4524,26 +4531,30 @@ sub process {
"Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
} }
foreach my $entry (@mode_permission_funcs) { # Mode permission misuses where it seems decimal should be octal
my $func = $entry->[0]; # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
my $arg_pos = $entry->[1]; if ($^V && $^V ge 5.10.0 &&
$line =~ /$mode_perms_search/) {
my $skip_args = ""; foreach my $entry (@mode_permission_funcs) {
if ($arg_pos > 1) { my $func = $entry->[0];
$arg_pos--; my $arg_pos = $entry->[1];
$skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
} my $skip_args = "";
my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]"; if ($arg_pos > 1) {
if ($^V && $^V ge 5.10.0 && $arg_pos--;
$line =~ /$test/) { $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
my $val = $1; }
$val = $6 if ($skip_args ne ""); my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]";
if ($line =~ /$test/) {
if ($val !~ /^0$/ && my $val = $1;
(($val =~ /^$Int$/ && $val !~ /^$Octal$/) || $val = $6 if ($skip_args ne "");
length($val) ne 4)) {
ERROR("NON_OCTAL_PERMISSIONS", if ($val !~ /^0$/ &&
"Use 4 digit octal (0777) not decimal permissions\n" . $herecurr); (($val =~ /^$Int$/ && $val !~ /^$Octal$/) ||
length($val) ne 4)) {
ERROR("NON_OCTAL_PERMISSIONS",
"Use 4 digit octal (0777) not decimal permissions\n" . $herecurr);
}
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册