Skip to content

Commit 9f3a899

Browse files
robherringtorvalds
authored andcommitted
checkpatch.pl: add SPDX license tag check
Add SPDX license tag check based on the rules defined in Documentation/process/license-rules.rst. To summarize, SPDX license tags should be on the 1st line (or 2nd line in scripts) using the appropriate comment style for the file type. Link: http://lkml.kernel.org/r/20180202154026.15298-1-robh@kernel.org Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Philippe Ombredanne <pombredanne@nexb.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: Joe Perches <joe@perches.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Igor Stoppa <igor.stoppa@huawei.com> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 85e1206 commit 9f3a899

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scripts/checkpatch.pl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,8 @@ sub process {
22572257

22582258
my $camelcase_file_seeded = 0;
22592259

2260+
my $checklicenseline = 1;
2261+
22602262
sanitise_line_reset();
22612263
my $line;
22622264
foreach my $rawline (@rawlines) {
@@ -2448,6 +2450,7 @@ sub process {
24482450
} else {
24492451
$check = $check_orig;
24502452
}
2453+
$checklicenseline = 1;
24512454
next;
24522455
}
24532456

@@ -2911,6 +2914,30 @@ sub process {
29112914
}
29122915
}
29132916

2917+
# check for using SPDX license tag at beginning of files
2918+
if ($realline == $checklicenseline) {
2919+
if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
2920+
$checklicenseline = 2;
2921+
} elsif ($rawline =~ /^\+/) {
2922+
my $comment = "";
2923+
if ($realfile =~ /\.(h|s|S)$/) {
2924+
$comment = '/*';
2925+
} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
2926+
$comment = '//';
2927+
} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) {
2928+
$comment = '#';
2929+
} elsif ($realfile =~ /\.rst$/) {
2930+
$comment = '..';
2931+
}
2932+
2933+
if ($comment !~ /^$/ &&
2934+
$rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) {
2935+
WARN("SPDX_LICENSE_TAG",
2936+
"Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
2937+
}
2938+
}
2939+
}
2940+
29142941
# check we are in a valid source file if not then ignore this hunk
29152942
next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
29162943

0 commit comments

Comments
 (0)