Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 515a235e authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

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: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent daa8b059
Loading
Loading
Loading
Loading
+31 −20
Original line number Diff line number Diff line
@@ -388,6 +388,13 @@ our @mode_permission_funcs = (
	["(?: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:
	irq|
	memory
@@ -4524,6 +4531,10 @@ sub process {
			     "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
		}

# Mode permission misuses where it seems decimal should be octal
# This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
		if ($^V && $^V ge 5.10.0 &&
		    $line =~ /$mode_perms_search/) {
			foreach my $entry (@mode_permission_funcs) {
				my $func = $entry->[0];
				my $arg_pos = $entry->[1];
@@ -4534,8 +4545,7 @@ sub process {
					$skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
				}
				my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]";
			if ($^V && $^V ge 5.10.0 &&
			    $line =~ /$test/) {
				if ($line =~ /$test/) {
					my $val = $1;
					$val = $6 if ($skip_args ne "");

@@ -4548,6 +4558,7 @@ sub process {
				}
			}
		}
	}

	# If we have no input at all, then there is nothing to report on
	# so just keep quiet.