[PATCH 02/10] checkpatch: cache SPDX license checks and gate on SPDX_LICENSE_TAG
From: Bart Van Assche
Date: Tue Dec 01 2026 - 17:54:16 EST
Memoize is_SPDX_License_valid() results in %spdx_license_cache keyed by
license string, and gate the call site in process() on
show_type("SPDX_LICENSE_TAG").
Avoid launching a new Python interpreter for scripts/spdxcheck.py (~140 ms
per call) when checking repeated license expressions across multiple files
or when SPDX_LICENSE_TAG warnings are ignored.
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
scripts/checkpatch.pl | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 543fd002ee29..3602e79fc091 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1323,15 +1323,19 @@ sub is_maintained_obsolete {
return $maintained_status{$filename} =~ /obsolete/i;
}
+my %spdx_license_cache = ();
+
sub is_SPDX_License_valid {
my ($license) = @_;
return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
- my $root_path = abs_path($root);
- my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
- return 0 if ($status ne "");
- return 1;
+ if (!exists($spdx_license_cache{$license})) {
+ my $root_path = abs_path($root);
+ my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
+ $spdx_license_cache{$license} = ($status ne "") ? 0 : 1;
+ }
+ return $spdx_license_cache{$license};
}
my $camelcase_seeded = 0;
@@ -3996,7 +4000,8 @@ sub process {
"Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
my $spdx_license = $1;
- if (!is_SPDX_License_valid($spdx_license)) {
+ if (show_type("SPDX_LICENSE_TAG") &&
+ !is_SPDX_License_valid($spdx_license)) {
WARN("SPDX_LICENSE_TAG",
"'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
}