Skip to contentSkip to conversation

checkpatch.pl: Add SPDX license tag check for dts files and headers

PATCH In review Rob Herring 3 participants 6 messages Feb 23, 2017 – Jun 9, 2017 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch.pl: Add SPDX license tag check for dts files and headers

Add a check for using SPDX-License-Identifier tags to define the license of .dts{i} and DT header files rather than using free form license text. This check looks for GPL, BSD, or X11(really incorrectly labeled MIT license) license text which are the commonly used DT licenses.

Cc Andy Whitcroft <[email protected]>
Cc Joe Perches <[email protected]>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)
scripts/checkpatch.pl +13 -0
index 982c52ca6473..ce802b3146e3 100755
@@ -2139,6 +2139,7 @@ sub process {
 	my $commit_log_has_diff = 0;
 	my $reported_maintainer_file = 0;
 	my $non_utf8_charset = 0;
+	my $licensefile = '';
 
 	my $last_blank_line = 0;
 	my $last_coalesced_string_linenr = -1;
@@ -2805,6 +2806,18 @@ sub process {
 			}
 		}
 
+# check for using SPDX tag instead of free form license text in dts and binding header files
+		if ($licensefile ne $realfile &&
+		    ($realfile =~ /\.dtsi?$/ || $realfile =~ /dt-bindings\/.*\.h$/) &&
+		    $rawline !~ /\bSPDX-License-Identifier/ &&
+		    ($rawline =~ /^\+.*\bGeneral\s+Public\s+License/i ||
+		    $rawline =~ /^\+.*\bTHE\s+SOFTWARE\s+IS\s+PROVIDED\s+\"AS\s+IS\"/i ||
+		    $rawline =~ /^\+.*\b(GPL|BSD|X11)/)) {
+			$licensefile = $realfile;
+			WARN("SPDX_LICENSE_TAG",
+			     "Use SPDX-License-Identifier tags instead of full license text\n" . $herecurr);
+		}
+
 # check we are in a valid source file if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
 
Signature · 6 lines
2.10.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#1 lore raw
Quoted 4 lines · Rob Herring

Add a check for using SPDX-License-Identifier tags to define the license of .dts{i} and DT header files rather than using free form license text. This check looks for GPL, BSD, or X11(really incorrectly labeled MIT license) license text which are the commonly used DT licenses.

Hi Rob.

Quoted 12 lines
Cc Andy Whitcroft <[email protected]>
Cc Joe Perches <[email protected]>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)
scripts/checkpatch.pl +0 -0
index 982c52ca6473..ce802b3146e3 100755

scripts/checkpatch.pl sub process { · line 2142

Quoted 4 lines
scripts/checkpatch.pl +1 -0
@@ -2139,6 +2139,7 @@ sub process {
 	my $commit_log_has_diff = 0;
 	my $reported_maintainer_file = 0;
 	my $non_utf8_charset = 0;
+	my $licensefile = '';

Maybe this should be $spdx_license_file but what's the actual reason to check if multiple license bits are in a single file?

scripts/checkpatch.pl sub process { · line 2811

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+# check for using SPDX tag instead of free form license text in dts and binding header files
+		if ($licensefile ne $realfile &&
+		    ($realfile =~ /\.dtsi?$/ || $realfile =~ /dt-bindings\/.*\.h$/) &&

It's nicer to use a non / leading char like @ so you don't have to escape the /.

maybe

	$realfile =~ m@/dt-bindings/.*\.h$@

scripts/checkpatch.pl sub process { · line 2815

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		    $rawline !~ /\bSPDX-License-Identifier/ &&
+		    ($rawline =~ /^\+.*\bGeneral\s+Public\s+License/i ||
+		    $rawline =~ /^\+.*\bTHE\s+SOFTWARE\s+IS\s+PROVIDED\s+\"AS\s+IS\"/i ||
+		    $rawline =~ /^\+.*\b(GPL|BSD|X11)/)) {

nicer to indent these last 2 lines one more space to keep alignment to open parenthesis.

Quoted 7 lines
scripts/checkpatch.pl +5 -0
+			$licensefile = $realfile;
+			WARN("SPDX_LICENSE_TAG",
+			     "Use SPDX-License-Identifier tags instead of full license text\n" . $herecurr);
+		}
+
 # check we are in a valid source file if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
#2 lore raw
Quoted 15 lines · Joe Perches
Quoted 4 lines · Rob Herring

Add a check for using SPDX-License-Identifier tags to define the license of .dts{i} and DT header files rather than using free form license text. This check looks for GPL, BSD, or X11(really incorrectly labeled MIT license) license text which are the commonly used DT licenses.

Hi Rob.

Quoted 7 lines
Cc Andy Whitcroft <[email protected]>
Cc Joe Perches <[email protected]>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 13 lines

scripts/checkpatch.pl sub process { · line 2142

Quoted 9 lines
scripts/checkpatch.pl +1 -0
index 982c52ca6473..ce802b3146e3 100755
@@ -2139,6 +2139,7 @@ sub process {
      my $commit_log_has_diff = 0;
      my $reported_maintainer_file = 0;
      my $non_utf8_charset = 0;
+     my $licensefile = '';

Maybe this should be $spdx_license_file
but what's the actual reason to check if
multiple license bits are in a single file?

Yes, just to get a single warning per file since the license matching can get multiple hits.

Really what I'd like to do is warn if an SPDX tag is not present in any added file. Having a check for something missing doesn't really work well with checkpatch at least in a scalable way that I saw.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#3 lore raw
Quoted 30 lines · Rob Herring
Quoted 15 lines · Joe Perches
Quoted 4 lines · Rob Herring

Add a check for using SPDX-License-Identifier tags to define the license of .dts{i} and DT header files rather than using free form license text. This check looks for GPL, BSD, or X11(really incorrectly labeled MIT license) license text which are the commonly used DT licenses.

Hi Rob.

Quoted 7 lines
Cc Andy Whitcroft <[email protected]>
Cc Joe Perches <[email protected]>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 13 lines

scripts/checkpatch.pl sub process { · line 2142

Quoted 9 lines
scripts/checkpatch.pl +1 -0
index 982c52ca6473..ce802b3146e3 100755
@@ -2139,6 +2139,7 @@ sub process {
      my $commit_log_has_diff = 0;
      my $reported_maintainer_file = 0;
      my $non_utf8_charset = 0;
+     my $licensefile = '';

Maybe this should be $spdx_license_file
but what's the actual reason to check if
multiple license bits are in a single file?

Quoted 6 lines

Yes, just to get a single warning per file since the license matching can get multiple hits.

Really what I'd like to do is warn if an SPDX tag is not present in any added file. Having a check for something missing doesn't really work well with checkpatch at least in a scalable way that I saw.

That isn't really possible with checkpatch as
I'm sure you know that it looks at patch
contexts and it isn't really meant to scan
entire files.

You might be better off with a separate script
like the checkincludes.pl one.

You might possibly integrate that script into
checkpatch by looking at the "new file mode"
block, remember those and see if in the patch
each appropriate file has one of the spdx tags.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Rob Herring

Hi Rob,

2017-02-24 0:56 GMT+09:00 Rob Herring <[email protected]>:

Quoted 8 lines

Add a check for using SPDX-License-Identifier tags to define the license of .dts{i} and DT header files rather than using free form license text. This check looks for GPL, BSD, or X11(really incorrectly labeled MIT license) license text which are the commonly used DT licenses.

Cc Andy Whitcroft <[email protected]>
Cc Joe Perches <[email protected]>

I have a question.

Is SPDX encouraged only for DT?

What should we do with C source files?

Signature · 2 lines
Best Regards
Masahiro Yamada
#5 lore raw
Quoted 12 lines · Masahiro Yamada

Hi Rob,

2017-02-24 0:56 GMT+09:00 Rob Herring <[email protected]>:

Quoted 8 lines

Add a check for using SPDX-License-Identifier tags to define the license of .dts{i} and DT header files rather than using free form license text. This check looks for GPL, BSD, or X11(really incorrectly labeled MIT license) license text which are the commonly used DT licenses.

Cc Andy Whitcroft <[email protected]>
Cc Joe Perches <[email protected]>
Quoted 5 lines

I have a question.

Is SPDX encouraged only for DT?

What should we do with C source files?

Depends on the maintainer and your lawyer I guess. gregkh is supportive[1]. I wouldn't recommend changing existing license text though.

Rob

[1] https://lkml.org/lkml/2017/2/15/968
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html