2019-01-17 04:25:23

by Thomas Gleixner

[permalink] [raw]
Subject: [patch 2/2] scripts/spdxcheck.py: Handle special quotation mark comments

The SuperH boot code files use a magic format for the SPDX identifier
comment:

LIST "SPDX-License-Identifier: .... "

The trailing quotation mark is not stripped before the token parser is
invoked and causes the scan to fail. Handle it gracefully.

Fixes: 6a0abce4c4cc ("sh: include: convert to SPDX identifiers")
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Kuninori Morimoto <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Kate Stewart <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jonathan Corbet <[email protected]>
---
scripts/spdxcheck.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

--- a/scripts/spdxcheck.py
+++ b/scripts/spdxcheck.py
@@ -175,7 +175,13 @@ import os
self.lines_checked += 1
if line.find("SPDX-License-Identifier:") < 0:
continue
- expr = line.split(':')[1].replace('*/', '').strip()
+ expr = line.split(':')[1].strip()
+ # Remove trailing comment closure
+ if line.startswith('/*'):
+ expr = expr.rstrip('*/').strip()
+ # Special case for SH magic boot code files
+ if line.startswith('LIST \"'):
+ expr = expr.rstrip('\"').strip()
self.parse(expr)
self.spdx_valid += 1
#




2019-01-16 22:52:33

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [patch 2/2] scripts/spdxcheck.py: Handle special quotation mark comments

On Wed, Jan 16, 2019 at 11:26:53AM +0100, Thomas Gleixner wrote:
> The SuperH boot code files use a magic format for the SPDX identifier
> comment:
>
> LIST "SPDX-License-Identifier: .... "
>
> The trailing quotation mark is not stripped before the token parser is
> invoked and causes the scan to fail. Handle it gracefully.
>
> Fixes: 6a0abce4c4cc ("sh: include: convert to SPDX identifiers")
> Signed-off-by: Thomas Gleixner <[email protected]>
> Cc: Kuninori Morimoto <[email protected]>
> Cc: Simon Horman <[email protected]>
> Cc: Yoshinori Sato <[email protected]>
> Cc: Rich Felker <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Kate Stewart <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Jonathan Corbet <[email protected]>
> ---
> scripts/spdxcheck.py | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> --- a/scripts/spdxcheck.py
> +++ b/scripts/spdxcheck.py
> @@ -175,7 +175,13 @@ import os
> self.lines_checked += 1
> if line.find("SPDX-License-Identifier:") < 0:
> continue
> - expr = line.split(':')[1].replace('*/', '').strip()
> + expr = line.split(':')[1].strip()
> + # Remove trailing comment closure
> + if line.startswith('/*'):
> + expr = expr.rstrip('*/').strip()
> + # Special case for SH magic boot code files
> + if line.startswith('LIST \"'):
> + expr = expr.rstrip('\"').strip()
> self.parse(expr)
> self.spdx_valid += 1
> #
>
>

Reviewed-by: Greg Kroah-Hartman <[email protected]>

2019-01-20 15:34:56

by Sven Eckelmann

[permalink] [raw]
Subject: Re: [patch 2/2] scripts/spdxcheck.py: Handle special quotation mark comments

On Wednesday, 16 January 2019 11.26.53 CET Thomas Gleixner wrote:
> The SuperH boot code files use a magic format for the SPDX identifier
> comment:
>
> LIST "SPDX-License-Identifier: .... "
>
> The trailing quotation mark is not stripped before the token parser is
> invoked and causes the scan to fail. Handle it gracefully.
[...]

This patch introduces a false positive when checking files with an ANSI-C
style /* SPDX-License-Identifier: .... */ comment line.

$ ./scripts/checkpatch.pl -q -f include/linux/bug.h
WARNING: 'SPDX-License-Identifier: GPL-2.0 */' is not supported in LICENSES/...
#1: FILE: include/linux/bug.h:1:
+/* SPDX-License-Identifier: GPL-2.0 */

total: 0 errors, 1 warnings, 79 lines checked

checkpatch.pl is already stripping the "/* " prefix and only sends the
remaining "SPDX-License-Identifier: GPL-2.0 */" via stdin to
scripts/spdxcheck.py. Thus the newly introduced check

> + # Remove trailing comment closure
> + if line.startswith('/*'):
> + expr = expr.rstrip('*/').strip()

doesn't match and thus the code doesn't remove the " */" at the end of the
line.

Kind regards,
Sven


Attachments:
signature.asc (849.00 B)
This is a digitally signed message part.

2019-01-20 18:52:33

by Joe Perches

[permalink] [raw]
Subject: Re: [patch 2/2] scripts/spdxcheck.py: Handle special quotation mark comments

On Sun, 2019-01-20 at 16:32 +0100, Sven Eckelmann wrote:
> On Wednesday, 16 January 2019 11.26.53 CET Thomas Gleixner wrote:
> > The SuperH boot code files use a magic format for the SPDX identifier
> > comment:
> >
> > LIST "SPDX-License-Identifier: .... "
> >
> > The trailing quotation mark is not stripped before the token parser is
> > invoked and causes the scan to fail. Handle it gracefully.
> [...]
>
> This patch introduces a false positive when checking files with an ANSI-C
> style /* SPDX-License-Identifier: .... */ comment line.
>
> $ ./scripts/checkpatch.pl -q -f include/linux/bug.h
> WARNING: 'SPDX-License-Identifier: GPL-2.0 */' is not supported in LICENSES/...
> #1: FILE: include/linux/bug.h:1:
> +/* SPDX-License-Identifier: GPL-2.0 */
>
> total: 0 errors, 1 warnings, 79 lines checked
>
> checkpatch.pl is already stripping the "/* " prefix and only sends the
> remaining "SPDX-License-Identifier: GPL-2.0 */" via stdin to
> scripts/spdxcheck.py. Thus the newly introduced check
>
> > + # Remove trailing comment closure
> > + if line.startswith('/*'):
> > + expr = expr.rstrip('*/').strip()
>
> doesn't match and thus the code doesn't remove the " */" at the end of the
> line.

Well, maybe checkpatch should remove the comment trailer.
---
Miscellanea:

o Indent a block properly too

scripts/checkpatch.pl | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 155fa9305166..e0b542008256 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3029,8 +3029,10 @@ sub process {
$checklicenseline = 2;
} elsif ($rawline =~ /^\+/) {
my $comment = "";
+ my $trailer = "";
if ($realfile =~ /\.(h|s|S)$/) {
$comment = '/*';
+ $trailer = '*/';
} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
$comment = '//';
} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) {
@@ -3044,11 +3046,12 @@ sub process {
WARN("SPDX_LICENSE_TAG",
"Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
- my $spdx_license = $1;
- if (!is_SPDX_License_valid($spdx_license)) {
- WARN("SPDX_LICENSE_TAG",
- "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
- }
+ my $spdx_license = rtrim($1);
+ $spdx_license =~ s/\s*\Q$trailer\E$//;
+ if (!is_SPDX_License_valid($spdx_license)) {
+ WARN("SPDX_LICENSE_TAG",
+ "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
+ }
}
}
}



2019-02-06 18:55:35

by Sven Eckelmann

[permalink] [raw]
Subject: Re: [patch 2/2] scripts/spdxcheck.py: Handle special quotation mark comments

On Sunday, 20 January 2019 19.39.55 CET Joe Perches wrote:
> Well, maybe checkpatch should remove the comment trailer.
> ---
> Miscellanea:

In case you are waiting for me (haven't seen it popping up in linux-next):
yes, this patch solves the problem for me.

Tested-by: Sven Eckelmann <[email protected]>

Thanks,
Sven


Attachments:
signature.asc (849.00 B)
This is a digitally signed message part.