[Linux-kernel-mentees] [PATCH] checkpatch: Fix SPDX license check for script files

Mrinal Pandey mrinalmni at gmail.com
Sat Jul 25 11:20:49 UTC 2020


In all the script files(except yaml), SPDX license identifier is expected
on the second line, the first line being the shebang. Sometimes, the
diff content includes the SPDX licensing information but excludes the
shebang when a commit is made to a script file.

This can be seen in the commits like commit 37f8173dd849 ("locking/atomics:
Flip fallbacks and instrumentation") and commit 075c8aa79d54 ("selftests:
forwarding: tc_actions.sh: add matchall mirror test"). In these cases
checkpatch issues a false positive warning:
"Misplaced SPDX-License-Identifier tag - use line 1 instead".

I noticed this false positive, while running checkpatch on the set of
commits from v5.7 to v5.8-rc1 of the kernel, on the said commits.
This false positive exists in checkpatch since commit a8da38a9cf0e
("checkpatch: add test for SPDX-License-Identifier on wrong line #")
when the corresponding rule was first added.

The existing logic looks for a shebang in the patch/file being checked
and if a shebang is encountered it directs checkpatch to expect
license on the second line by setting `$checklicenseline` to `2`.

However, this approach doesn't work when we don't have a shebang in the
patch and `$checklicensline` continues to be `1` in this case leading to
the unnecessary warning.

Fix this by setting `$checklicenseline` to `2` by checking if the patch
comes from a script for the cases when the shebang doesn't appear in the
patch.

Signed-off-by: Mrinal Pandey <mrinalmni at gmail.com>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..80dfa83ed0fb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3167,7 +3167,7 @@ sub process {
 
 # check for using SPDX license tag at beginning of files
 		if ($realline == $checklicenseline) {
-			if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
+			if ($rawline =~ /^[ \+]\s*\#\!\s*\// || $realfile =~ /.*\.\(py\|sh\|pl\|awk\|tc\)/) {
 				$checklicenseline = 2;
 			} elsif ($rawline =~ /^\+/) {
 				my $comment = "";
-- 
2.25.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.linuxfoundation.org/pipermail/linux-kernel-mentees/attachments/20200725/71593464/attachment.sig>


More information about the Linux-kernel-mentees mailing list