checkpatch: Add support for floating point constants
Joe Perches
maintainerv2 cover checkpatch: Add support for floating point constants
The kernel doesn't support them though.
v2: Make it clearer that checkpatch understands floating point constants
Support floating point hex constants too
Joe Perches (3):
checkpatch: Find hex constants as a single IDENT
checkpatch: Add support for floating point constants
checkpatch: Emit an warning when floating point values are used
scripts/checkpatch.pl | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
Signature · 1 line
1.7.8.112.g3fd21
Joe Perches
maintainerPATCH v2 1/3 checkpatch: Find hex constants as a single IDENT
Hexadecimal values are current found in 2 parts.
A hex constant like 0x123456abcdef is found as
0 and then x123456abcdef and later coalesced.
Instead, reverse the order of the 2 searches in
$Constant to find 0x first, then 0 so that the
entire hex constant is found all at once.
--- scripts/checkpatch.pl | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
@@ -227,7 +227,7 @@ our $Inline = qr{inline|__always_inline|noinline}; our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; our $Lval = qr{$Ident(?:$Member)*}; -our $Constant = qr{(?i:(?:[0-9]+|0x[0-9a-f]+)[ul]*)}; +our $Constant = qr{(?i:(?:0x[0-9a-f]+|[0-9]+)[ul]*)}; our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; our $Compare = qr{<=|>=|==|!=|<|>}; our $Operators = qr{
Signature · 1 line
1.7.8.112.g3fd21
Joe Perches
maintainerPATCH v2 2/3 checkpatch: Add support for floating point constants
In reply to Joe PerchesEven though the kernel doesn't support using floating point constants, add a regex for them.
Support forms like: 0x123p1, 123e-1, 1.23, 1.5e23f
--- scripts/checkpatch.pl | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +5 -1
@@ -227,7 +227,11 @@ our $Inline = qr{inline|__always_inline|noinline}; our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; our $Lval = qr{$Ident(?:$Member)*}; -our $Constant = qr{(?i:(?:0x[0-9a-f]+|[0-9]+)[ul]*)}; +our $Float_hex = qr{(?i:0x[0-9a-f]+p-?[0-9]+[fl]?)}; +our $Float_dec = qr{(?i:((?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?))}; +our $Float_int = qr{(?i:[0-9]+e-?[0-9]+[fl]?)}; +our $Float = qr{$Float_hex|$Float_dec|$Float_int}; +our $Constant = qr{(?:$Float|(?i:(?:0x[0-9a-f]+|[0-9]+)[ul]*))}; our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; our $Compare = qr{<=|>=|==|!=|<|>}; our $Operators = qr{
Signature · 1 line
1.7.8.112.g3fd21
Joe Perches
maintainerPATCH v2 3/3 checkpatch: Emit an warning when floating point values are used
In reply to Joe PerchesLinux kernel doesn't like floating point, say so.
--- scripts/checkpatch.pl | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +7 -0
@@ -2332,6 +2332,13 @@ sub process { "do not add new typedefs\n" . $herecurr); } +# check for floating point constants + + if ($line =~ /\b$Float\b/) { + WARN("KERNEL_FLOAT", + "Floating point is not supported in linux kernel source\n" . $herecurr); + } + # * goes on variable not on type # (char*[ const]) while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
Signature · 1 line
1.7.8.112.g3fd21
Re: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used
Quoted 10 lines · On Thu, 1 Nov 2012 00:12:18 -0700 Joe Perches <[email protected]> wrote:
Linux kernel doesn't like floating point, say so.
...
scripts/checkpatch.pl +0
-0@@ -2332,6 +2332,13 @@ sub process { "do not add new typedefs\n" . $herecurr); }
scripts/checkpatch.pl sub process { · line 2344
Quoted 10 lines
scripts/checkpatch.pl +7
-0+# check for floating point constants + + if ($line =~ /\b$Float\b/) { + WARN("KERNEL_FLOAT", + "Floating point is not supported in linux kernel source\n" . $herecurr); + } + # * goes on variable not on type # (char*[ const]) while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
The earlier review comments were not addressed.
In particular, I don't see a problem with people doing
int foo = 1.1 * 2.2;
Andy Whitcroft
maintainerRe: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used
Quoted 26 lines · Andrew Morton
Quoted 10 lines · On Thu, 1 Nov 2012 00:12:18 -0700 Joe Perches <[email protected]> wrote:
Linux kernel doesn't like floating point, say so.
...
scripts/checkpatch.pl +0
-0@@ -2332,6 +2332,13 @@ sub process { "do not add new typedefs\n" . $herecurr); }scripts/checkpatch.pl sub process { · line 2344
Quoted 10 lines
scripts/checkpatch.pl +7
-0+# check for floating point constants + + if ($line =~ /\b$Float\b/) { + WARN("KERNEL_FLOAT", + "Floating point is not supported in linux kernel source\n" . $herecurr); + } + # * goes on variable not on type # (char*[ const]) while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {The earlier review comments were not addressed.
Quoted 3 lines
In particular, I don't see a problem with people doing
int foo = 1.1 * 2.2;
I thought there was also now a way to enable floats in kernel space and some use thereof.
-apw
Joe Perches
maintainerRe: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used
In reply to Andrew MortonQuoted 3 lines · Andrew Morton
Quoted 1 line · On Thu, 1 Nov 2012 00:12:18 -0700 Joe Perches <[email protected]> wrote:
Linux kernel doesn't like floating point, say so.
[]
Quoted 6 lines
Quoted 6 lines
scripts/checkpatch.pl +0
-0@@ -2332,6 +2332,13 @@ sub process { "do not add new typedefs\n" . $herecurr); }
Quoted 12 lines
scripts/checkpatch.pl sub process { · line 2344
Quoted 10 lines
scripts/checkpatch.pl +7
-0+# check for floating point constants + + if ($line =~ /\b$Float\b/) { + WARN("KERNEL_FLOAT", + "Floating point is not supported in linux kernel source\n" . $herecurr); + } + # * goes on variable not on type # (char*[ const]) while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {The earlier review comments were not addressed.
You didn't read my response in the thread then. I "addressed" it by saying that the problem exists without solution.
Quoted 3 lines
In particular, I don't see a problem with people doing
int foo = 1.1 * 2.2;
Neither do I but I know of no way to determine that any calc is a constant.
Re: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used
Quoted 24 lines · On Wed, 07 Nov 2012 03:09:35 -0800 Joe Perches <[email protected]> wrote:
Quoted 3 lines · Andrew Morton
Quoted 1 line · On Thu, 1 Nov 2012 00:12:18 -0700 Joe Perches <[email protected]> wrote:
Linux kernel doesn't like floating point, say so.
[]
Quoted 6 lines
Quoted 6 lines
scripts/checkpatch.pl +0
-0@@ -2332,6 +2332,13 @@ sub process { "do not add new typedefs\n" . $herecurr); }Quoted 12 lines
scripts/checkpatch.pl sub process { · line 2344
Quoted 10 lines
scripts/checkpatch.pl +7
-0+# check for floating point constants + + if ($line =~ /\b$Float\b/) { + WARN("KERNEL_FLOAT", + "Floating point is not supported in linux kernel source\n" . $herecurr); + } + # * goes on variable not on type # (char*[ const]) while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {The earlier review comments were not addressed.
Quoted 1 line
You didn't read my response in the thread then.
There was no response afaict. Not here, not on lkml.org?