checkpatch: validate MODULE_LICENSE content
PATCH 1/1 checkpatch: validate MODULE_LICENSE content
There is a well defined list of expected values for MODULE_LICENSE so warn the user upon usage of unknown values.
--- scripts/checkpatch.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
scripts/checkpatch.pl +16 -0
@@ -5354,6 +5354,22 @@ sub process { } } } + + if ($line =~ /MODULE_LICENSE\(($String)\)/) { + my $extracted_string = get_quoted_string($line, $rawline); + my $valid_licenses = qr{ + GPL| + GPL\ v2| + GPL\ and\ additional\ rights| + Dual\ BSD/GPL| + Dual\ MIT/GPL| + Dual\ MPL/GPL| + Proprietary + }x; + if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) { + WARN("MODULE_LICENSE", "unknown module license " . $extracted_string . "\n" . $herecurr); + } + } } # If we have no input at all, then there is nothing to report on
Signature · 1 line
1.8.2.2
Joe Perches
maintainerQuoted 2 lines · Bjorn Andersson
There is a well defined list of expected values for
MODULE_LICENSEso warn the user upon usage of unknown values.
Hello Bjorn
A few nits:
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub process { · line 5358
Quoted 6 lines
scripts/checkpatch.pl +2
-0@@ -5354,6 +5354,22 @@ sub process { } } } + + if ($line =~ /MODULE_LICENSE\(($String)\)/) {
As there are uses with spaces, this would be better as:
if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {scripts/checkpatch.pl sub process { · line 5367
Quoted 9 lines
scripts/checkpatch.pl +9
-0+ my $extracted_string = get_quoted_string($line, $rawline); + my $valid_licenses = qr{ + GPL| + GPL\ v2| + GPL\ and\ additional\ rights| + Dual\ BSD/GPL| + Dual\ MIT/GPL| + Dual\ MPL/GPL| + Proprietary
Why add "Proprietary" ?
This is the list I get in the current tree:
(after collapsing spaces in a few places)
5920 MODULE_LICENSE("GPL")
1211 MODULE_LICENSE("GPL v2")
187 MODULE_LICENSE("Dual BSD/GPL")
37 MODULE_LICENSE("GPL and additional rights") 26 MODULE_LICENSE("Dual MPL/GPL")
1 MODULE_LICENSE("Dual MIT/GPL")
1 MODULE_LICENSE("BSD")
scripts/checkpatch.pl sub process { · line 5370
Quoted 3 lines
scripts/checkpatch.pl +3
-0+ }x; + if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) { + WARN("MODULE_LICENSE", "unknown module license " . $extracted_string . "\n" . $herecurr);
I'd write this on 2 lines in the same fashion as
all the other warnings:
WARN("MODULE_LICENSE",
"unknown module license $extracted_string\n" . $herecurr);Other than those minor issues, it seems sensible enough.
thanks, Joe
PATCH v2 1/1 checkpatch: validate MODULE_LICENSE content
There is a well defined list of expected values for MODULE_LICENSE so warn the user upon usage of unknown values.
---
Thanks for the review Joe!
"Proprietary" is in the list because this is the full list of "valid" values mentioned in include/linux/module.h. So it's the list of licenses valid for submission, but rather the list of valid values.
Changes since v1:
- Fixed nits pointed out by Joe
- Added comment to clarify the purpose, as well as origin of the values
scripts/checkpatch.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
scripts/checkpatch.pl +18 -0
@@ -5431,6 +5431,24 @@ sub process { } } } + +# validate content of MODULE_LICENSE against list from include/linux/module.h + if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { + my $extracted_string = get_quoted_string($line, $rawline); + my $valid_licenses = qr{ + GPL| + GPL\ v2| + GPL\ and\ additional\ rights| + Dual\ BSD/GPL| + Dual\ MIT/GPL| + Dual\ MPL/GPL| + Proprietary + }x; + if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) { + WARN("MODULE_LICENSE", + "unknown module license " . $extracted_string . "\n" . $herecurr); + } + } } # If we have no input at all, then there is nothing to report on
Signature · 1 line
1.8.2.2
Joe Perches
maintainerQuoted 7 lines · Bjorn Andersson
There is a well defined list of expected values for
MODULE_LICENSEso warn the user upon usage of unknown values.Signed-off-by Bjorn Andersson <[email protected]>---
Thanks for the review Joe!
No charge.
Quoted 3 lines
"Proprietary" is in the list because this is the full list of "valid" values mentioned in
include/linux/module.h. So it's the list of licenses valid for submission, but rather the list of valid values.
So the "Proprietary" entry is only for non kernel-tree uses. I wonder if the kernel checkpatch script should account for that.
I've no strong opinion though if Andrew wants to accept this as-is.
cheers, Joe
Quoted 36 lines
Changes since v1:
- Fixed nits pointed out by Joe
- Added comment to clarify the purpose, as well as origin of the valuesscripts/checkpatch.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)scripts/checkpatch.pl +18
-0@@ -5431,6 +5431,24 @@ sub process { } } } + +# validate content of MODULE_LICENSE against list from include/linux/module.h + if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { + my $extracted_string = get_quoted_string($line, $rawline); + my $valid_licenses = qr{ + GPL| + GPL\ v2| + GPL\ and\ additional\ rights| + Dual\ BSD/GPL| + Dual\ MIT/GPL| + Dual\ MPL/GPL| + Proprietary + }x; + if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) { + WARN("MODULE_LICENSE", + "unknown module license " . $extracted_string . "\n" . $herecurr); + } + } } # If we have no input at all, then there is nothing to report on
Quoted 9 lines · Joe Perches
Quoted 7 lines · Bjorn Andersson
There is a well defined list of expected values for
MODULE_LICENSEso warn the user upon usage of unknown values.Signed-off-by Bjorn Andersson <[email protected]>---
Thanks for the review Joe!
Quoted 9 lines
No charge.
Quoted 3 lines
"Proprietary" is in the list because this is the full list of "valid" values mentioned in
include/linux/module.h. So it's the list of licenses valid for submission, but rather the list of valid values.So the "Proprietary" entry is only for non kernel-tree uses. I wonder if the kernel checkpatch script should account for that.
The way I read the comment in module.h is that if you're writing a non-free kernel module then you should mark it with "Proprietary".
If people doing so are using checkpatch that's great, but it's just included for completeness, not to argue about the concept of proprietary kernel modules.
Quoted 2 lines
I've no strong opinion though if Andrew wants to accept this as-is.
Let me know and I'll drop it from the patch.
Quoted 2 lines
cheers, Joe
Thanks,
Bjorn
Quoted 39 lines
Quoted 36 lines
Changes since v1:
- Fixed nits pointed out by Joe
- Added comment to clarify the purpose, as well as origin of the valuesscripts/checkpatch.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)scripts/checkpatch.pl +18
-0@@ -5431,6 +5431,24 @@ sub process { } } } + +# validate content of MODULE_LICENSE against list from include/linux/module.h + if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { + my $extracted_string = get_quoted_string($line, $rawline); + my $valid_licenses = qr{ + GPL| + GPL\ v2| + GPL\ and\ additional\ rights| + Dual\ BSD/GPL| + Dual\ MIT/GPL| + Dual\ MPL/GPL| + Proprietary + }x; + if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) { + WARN("MODULE_LICENSE", + "unknown module license " . $extracted_string . "\n" . $herecurr); + } + } } # If we have no input at all, then there is nothing to report on
Quoted 4 lines · On Tue, 7 Apr 2015 12:55:49 -0700 Bjorn Andersson…
Quoted 2 lines
I've no strong opinion though if Andrew wants to accept this as-is.
Let me know and I'll drop it from the patch.
I'd be inclined to keep it - if someone has used "Proprietary" then they meant to do so, and they don't want checkpatch to keep telling them they made a typo.
Hi Joe and Andrew,
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Tue, 7 Apr 2015 12:55:49 -0700 Bjorn Andersson…
Quoted 2 lines
I've no strong opinion though if Andrew wants to accept this as-is.
Let me know and I'll drop it from the patch.
I'd be inclined to keep it - if someone has used "Proprietary" then they meant to do so, and they don't want checkpatch to keep telling them they made a typo.
Any update on this patch?
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Joe Perches
maintainerQuoted 8 lines · Michal Simek
Hi Joe and Andrew,
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Tue, 7 Apr 2015 12:55:49 -0700 Bjorn Andersson…
Quoted 2 lines
I've no strong opinion though if Andrew wants to accept this as-is.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Let me know and I'll drop it from the patch.
I'd be inclined to keep it - if someone has used "Proprietary" then they meant to do so, and they don't want checkpatch to keep telling them they made a typo.
Any update on this patch?
I forgot all about it after that discussion. Please resend it so it's easier for Andrew to pick it up.
Thanks,