All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-02-23 15:56 ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-02-23 15:56 UTC (permalink / raw)
  To: devicetree, linux-kernel; +Cc: Andy Whitcroft, Joe Perches

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.

Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 982c52ca6473..ce802b3146e3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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)$/);
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-02-23 15:56 ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-02-23 15:56 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Andy Whitcroft, Joe Perches

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.

Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Andy Whitcroft <apw-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Cc: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 982c52ca6473..ce802b3146e3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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)$/);
 
-- 
2.10.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
  2017-02-23 15:56 ` Rob Herring
  (?)
@ 2017-02-23 17:51 ` Joe Perches
  2017-02-23 18:45     ` Rob Herring
  -1 siblings, 1 reply; 10+ messages in thread
From: Joe Perches @ 2017-02-23 17:51 UTC (permalink / raw)
  To: Rob Herring, devicetree, linux-kernel; +Cc: Andy Whitcroft

On Thu, 2017-02-23 at 09:56 -0600, Rob Herring wrote:
> 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.

> Signed-off-by: Rob Herring <robh@kernel.org>
> Cc: Andy Whitcroft <apw@canonical.com>
> Cc: Joe Perches <joe@perches.com>
> ---
>  scripts/checkpatch.pl | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 982c52ca6473..ce802b3146e3 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -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?

> +# 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$@

> +		    $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.

> +			$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)$/);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-02-23 18:45     ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-02-23 18:45 UTC (permalink / raw)
  To: Joe Perches; +Cc: devicetree, linux-kernel, Andy Whitcroft

On Thu, Feb 23, 2017 at 11:51 AM, Joe Perches <joe@perches.com> wrote:
> On Thu, 2017-02-23 at 09:56 -0600, Rob Herring wrote:
>> 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.
>
>> Signed-off-by: Rob Herring <robh@kernel.org>
>> Cc: Andy Whitcroft <apw@canonical.com>
>> Cc: Joe Perches <joe@perches.com>
>> ---
>>  scripts/checkpatch.pl | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 982c52ca6473..ce802b3146e3 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-02-23 18:45     ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-02-23 18:45 UTC (permalink / raw)
  To: Joe Perches
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Andy Whitcroft

On Thu, Feb 23, 2017 at 11:51 AM, Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org> wrote:
> On Thu, 2017-02-23 at 09:56 -0600, Rob Herring wrote:
>> 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.
>
>> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
>> Cc: Andy Whitcroft <apw-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
>> Cc: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
>> ---
>>  scripts/checkpatch.pl | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 982c52ca6473..ce802b3146e3 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-02-23 19:10       ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-23 19:10 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, linux-kernel, Andy Whitcroft

On Thu, 2017-02-23 at 12:45 -0600, Rob Herring wrote:
> On Thu, Feb 23, 2017 at 11:51 AM, Joe Perches <joe@perches.com> wrote:
> > On Thu, 2017-02-23 at 09:56 -0600, Rob Herring wrote:
> > > 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.
> > 
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > Cc: Andy Whitcroft <apw@canonical.com>
> > > Cc: Joe Perches <joe@perches.com>
> > > ---
> > >  scripts/checkpatch.pl | 13 +++++++++++++
> > >  1 file changed, 13 insertions(+)
> > > 
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > > index 982c52ca6473..ce802b3146e3 100755
> > > --- a/scripts/checkpatch.pl
> > > +++ b/scripts/checkpatch.pl
> > > @@ -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.

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-02-23 19:10       ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-23 19:10 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Andy Whitcroft

On Thu, 2017-02-23 at 12:45 -0600, Rob Herring wrote:
> On Thu, Feb 23, 2017 at 11:51 AM, Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org> wrote:
> > On Thu, 2017-02-23 at 09:56 -0600, Rob Herring wrote:
> > > 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.
> > 
> > > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > > Cc: Andy Whitcroft <apw-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> > > Cc: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
> > > ---
> > >  scripts/checkpatch.pl | 13 +++++++++++++
> > >  1 file changed, 13 insertions(+)
> > > 
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > > index 982c52ca6473..ce802b3146e3 100755
> > > --- a/scripts/checkpatch.pl
> > > +++ b/scripts/checkpatch.pl
> > > @@ -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.

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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
  2017-02-23 15:56 ` Rob Herring
  (?)
  (?)
@ 2017-06-07  8:45 ` Masahiro Yamada
  2017-06-09 13:56     ` Rob Herring
  -1 siblings, 1 reply; 10+ messages in thread
From: Masahiro Yamada @ 2017-06-07  8:45 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree, Linux Kernel Mailing List, Andy Whitcroft, Joe Perches

Hi Rob,

2017-02-24 0:56 GMT+09:00 Rob Herring <robh@kernel.org>:
> 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.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
> Cc: Andy Whitcroft <apw@canonical.com>
> Cc: Joe Perches <joe@perches.com>

I have a question.

Is SPDX encouraged only for DT?

What should we do with C source files?


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-06-09 13:56     ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-06-09 13:56 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: devicetree, Linux Kernel Mailing List, Andy Whitcroft, Joe Perches

On Wed, Jun 07, 2017 at 05:45:03PM +0900, Masahiro Yamada wrote:
> Hi Rob,
> 
> 2017-02-24 0:56 GMT+09:00 Rob Herring <robh@kernel.org>:
> > 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.
> >
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > Cc: Andy Whitcroft <apw@canonical.com>
> > Cc: Joe Perches <joe@perches.com>
> 
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers
@ 2017-06-09 13:56     ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-06-09 13:56 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, Linux Kernel Mailing List,
	Andy Whitcroft, Joe Perches

On Wed, Jun 07, 2017 at 05:45:03PM +0900, Masahiro Yamada wrote:
> Hi Rob,
> 
> 2017-02-24 0:56 GMT+09:00 Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>:
> > 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.
> >
> > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > Cc: Andy Whitcroft <apw-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> > Cc: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
> 
> 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-06-09 13:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23 15:56 [PATCH] checkpatch.pl: Add SPDX license tag check for dts files and headers Rob Herring
2017-02-23 15:56 ` Rob Herring
2017-02-23 17:51 ` Joe Perches
2017-02-23 18:45   ` Rob Herring
2017-02-23 18:45     ` Rob Herring
2017-02-23 19:10     ` Joe Perches
2017-02-23 19:10       ` Joe Perches
2017-06-07  8:45 ` Masahiro Yamada
2017-06-09 13:56   ` Rob Herring
2017-06-09 13:56     ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.