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

Mrinal Pandey mrinalmni at gmail.com
Mon Jul 13 09:57:40 UTC 2020


In all the scripts, the SPDX license should be on the second line,
the first line being the "sh-bang", but checkpatch issues a warning
"Misplaced SPDX-License-Identifier tag - use line 1 instead" for the
scripts that have SPDX license in the second line.

However, this warning is not issued when checkpatch is run on a file using
`-f` option. The case for files has been handled gracefully by changing
`$checklicenseline` to `2` but a corresponding check when running checkpatch
on a commit hash is missing.

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 commits which modified
a script file.

This check is missing in checkpatch since commit a8da38a9cf0e
("checkpatch: add test for SPDX-License-Identifier on wrong line #")
when the corresponding rule was first commited.

Fix this by setting `$checklicenseline` to `2` when the diff content that
is being checked originates from a script, thus, informing checkpatch that
the SPDX license should be on the second line.

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..bbffd0c4449d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3218,6 +3218,9 @@ sub process {
 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
 
 # check for using SPDX-License-Identifier on the wrong line number
+		if ($realfile =~ /^scripts/) {
+                    $checklicenseline = 2;
+	        }
 		if ($realline != $checklicenseline &&
 		    $rawline =~ /\bSPDX-License-Identifier:/ &&
 		    substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
-- 
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/20200713/952e6a6f/attachment.sig>


More information about the Linux-kernel-mentees mailing list