From: Petr Vorel <pvorel@suse.cz>
To: linux-kernel@vger.kernel.org
Cc: Petr Vorel <pvorel@suse.cz>, Joe Perches <joe@perches.com>,
Simon Glass <sjg@chromium.org>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: [PATCH v6 2/2] checkpatch: Add option to not force /* */ for SPDX
Date: Mon, 20 Apr 2026 15:30:14 +0200 [thread overview]
Message-ID: <20260420133014.484162-2-pvorel@suse.cz> (raw)
In-Reply-To: <20260420133014.484162-1-pvorel@suse.cz>
Add option --spdx-cxx-comments to not force C comments (/* */) for SPDX,
but allow also C++ comments (//).
As documented in aa19a176df95d6, this is required for some old
toolchains still have older assembler tools which cannot handle C++
style comments. This avoids forcing this for projects which vendored
checkpatch.pl (e.g. LTP or u-boot).
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes in v6:
* Fix escaping '..' by \Q \E (Simon, sashiko)
* Fix formatting of /* */ in Documentation/dev-tools/checkpatch.rst
(sashiko)
* Fix wording in the commit message (Simon)
Link to v5:
https://lore.kernel.org/lkml/20260417170346.448758-2-pvorel@suse.cz/
Link to v4:
https://lore.kernel.org/lkml/20260415143636.272605-2-pvorel@suse.cz/
Link to v3:
https://lore.kernel.org/lkml/20260408120603.54351-2-pvorel@suse.cz/
Thanks Simon for patient review, let's see if maintainers like the
changes.
Documentation/dev-tools/checkpatch.rst | 7 +++++++
scripts/checkpatch.pl | 23 ++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index 010dfcd615afc..6139a08c34cd8 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -184,6 +184,13 @@ Available options:
Override checking of perl version. Runtime errors may be encountered after
enabling this flag if the perl version does not meet the minimum specified.
+ - --spdx-cxx-comments
+
+ Don't force C comments ``/* */`` for SPDX license (required by old
+ toolchains), allow also C++ comments ``//``.
+
+ NOTE: it should *not* be used for Linux mainline.
+
- --codespell
Use the codespell dictionary for checking spelling errors.
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d86f5ccb06fe4..18da0cbf873cb 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,10 @@ 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), allow also C++
+ comments (//).
+ 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 +351,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,
@@ -3814,26 +3820,33 @@ sub process {
$checklicenseline = 2;
} elsif ($rawline =~ /^\+/) {
my $comment = "";
- if ($realfile =~ /\.(h|s|S)$/) {
- $comment = '/*';
- } elsif ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
+ if ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
$comment = '//';
} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
$comment = '#';
} elsif ($realfile =~ /\.rst$/) {
$comment = '..';
}
+ my $pattern = qr{\Q$comment\E};
+ if ($realfile =~ /\.(h|s|S)$/) {
+ $comment = '/*';
+ $pattern = qr{/\*};
+ if ($spdx_cxx_comments) {
+ $comment = '// or /*';
+ $pattern = qr{//|/\*};
+ }
+ }
# check SPDX comment style for .[chsS] files
if ($realfile =~ /\.[chsS]$/ &&
$rawline =~ /SPDX-License-Identifier:/ &&
- $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
+ $rawline !~ m@^\+\s*$pattern\s*@) {
WARN("SPDX_LICENSE_TAG",
"Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
}
if ($comment !~ /^$/ &&
- $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
+ $rawline !~ m@^\+$pattern SPDX-License-Identifier: @) {
WARN("SPDX_LICENSE_TAG",
"Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
--
2.53.0
next prev parent reply other threads:[~2026-04-20 13:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 13:30 [PATCH v6 1/2] checkpatch: Allow passing config directory Petr Vorel
2026-04-20 13:30 ` Petr Vorel [this message]
2026-04-21 10:30 ` Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260420133014.484162-2-pvorel@suse.cz \
--to=pvorel@suse.cz \
--cc=dwaipayanray1@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=sjg@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox