[PATCH v4 2/2] checkpatch: Add option to not force /* */ for SPDX
From: Petr Vorel
Date: Wed Apr 15 2026 - 10:43:08 EST
Add option --spdx-cxx-comments to not force C comments (/* */) for SPDX.
As documented in aa19a176df95d6, this is required for some old
toolchains still have older assembler tools which cannot handle C++
style comments. This allows avoid forcing this for for projects which
vendored checkpatch.pl (e.g. LTP or u-boot).
Signed-off-by: Petr Vorel <pvorel@xxxxxxx>
---
Changes in v4 (all by Simon):
* Rename option to more specific (--ignore-old-toolchain =>
--spdx-cxx-comments)
* Fix the help text (C++ => C comments)
Link to v3:
https://lore.kernel.org/lkml/20260408120603.54351-2-pvorel@xxxxxxx/
scripts/checkpatch.pl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 38c448a8b7629..e5c320e0f230f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -61,6 +61,7 @@ my $def_configuration_dirs = ".:$ENV{HOME}:.scripts";
my $env_config_dir = 'CHECKPATCH_CONFIG_DIR';
my $max_line_length = 100;
my $ignore_perl_version = 0;
+my $spdx_cxx_comments = 0;
my $minimum_perl_version = 5.10.0;
my $min_conf_desc_length = 4;
my $spelling_file = "$D/spelling.txt";
@@ -137,6 +138,9 @@ Options:
file. It's your fault if there's no backup or git
--ignore-perl-version override checking of perl version. expect
runtime errors.
+ --spdx-cxx-comments don't force C comments (/* */) for SPDX license
+ (required by old toolchains). NOTE: it should *not*
+ be used for Linux mainline.
--codespell Use the codespell dictionary for spelling/typos
(default:$codespellfile)
--codespellfile Use this codespell dictionary
@@ -346,6 +350,7 @@ GetOptions(
'fix!' => \$fix,
'fix-inplace!' => \$fix_inplace,
'ignore-perl-version!' => \$ignore_perl_version,
+ 'spdx-cxx-comments!' => \$spdx_cxx_comments,
'debug=s' => \%debug,
'test-only=s' => \$tst_only,
'codespell!' => \$codespell,
@@ -3815,7 +3820,7 @@ sub process {
} elsif ($rawline =~ /^\+/) {
my $comment = "";
if ($realfile =~ /\.(h|s|S)$/) {
- $comment = '/*';
+ $comment = $spdx_cxx_comments ? '//' : '/*';
} elsif ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
$comment = '//';
} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
--
2.53.0