Skip to contentSkip to conversation

checkpatch: add check for missing */ in spdx line

PATCH In review Tim Bird 2 participants 2 messages Feb 4

Subsystems (2)
lore
Share & tools
lore

Tim Bird

author
#0 lore raw

PATCH 1/1 checkpatch: add check for missing */ in spdx line

Add an explicit check for leading /* but missing */ to avoid a malformed SPDX line.

In many cases an SPDX-License-Identifier line immediately precedes another C-style comment. In that case, if the SPDX line starts with '/*' but is missing the closing '*/', the compiler may not catch it (the leading '/*' on the next line and the rest of the header comment is just treated as part of the SPDX comment).

---
 scripts/checkpatch.pl | 5 +++++
 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +5 -0
index c0250244cf7a..1cc3fd5e72af 100755
@@ -3794,6 +3794,11 @@ sub process {
 					WARN("SPDX_LICENSE_TAG",
 					     "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
 				}
+				if ($comment eq '/*' &&
+				    $rawline !~ m@\*/@) {
+					WARN("SPDX_LICENSE_TAG",
+					     "Improper SPDX comment style for '$realfile', missing closing '*/'\n" . $herecurr);
+				}
 
 				if ($comment !~ /^$/ &&
 				    $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · Tim Bird

Add an explicit check for leading /* but missing */ to avoid a malformed SPDX line.

In many cases an SPDX-License-Identifier line immediately precedes another C-style comment. In that case, if the SPDX line starts with '/*' but is missing the closing '*/', the compiler may not catch it (the leading '/*' on the next line and the rest of the header comment is just treated as part of the SPDX comment).

Nack. There too many existing uses.

$ git grep '^/\*.*SPDX' | grep -v '\*/'| wc -l
855
Quoted 22 lines
---
 scripts/checkpatch.pl | 5 +++++
 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +5 -0
index c0250244cf7a..1cc3fd5e72af 100755
@@ -3794,6 +3794,11 @@ sub process {
 					WARN("SPDX_LICENSE_TAG",
 					     "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
 				}
+				if ($comment eq '/*' &&
+				    $rawline !~ m@\*/@) {
+					WARN("SPDX_LICENSE_TAG",
+					     "Improper SPDX comment style for '$realfile', missing closing '*/'\n" . $herecurr);
+				}
 
 				if ($comment !~ /^$/ &&
 				    $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {