2012-11-01 07:10:54

by Joe Perches

[permalink] [raw]
Subject: [PATCH V2 0/3] 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(-)

--
1.7.8.112.g3fd21


2012-11-01 07:12:37

by Joe Perches

[permalink] [raw]
Subject: [PATCH 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.

Signed-off-by: Joe Perches <[email protected]>
---
scripts/checkpatch.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f18750e..099a0ad 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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{
--
1.7.8.112.g3fd21

2012-11-01 07:12:50

by Joe Perches

[permalink] [raw]
Subject: [PATCH V2 2/3] checkpatch: Add support for floating point constants

Even 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

Signed-off-by: Joe Perches <[email protected]>
---
scripts/checkpatch.pl | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 099a0ad..c3a2162 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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{
--
1.7.8.112.g3fd21

2012-11-01 07:13:03

by Joe Perches

[permalink] [raw]
Subject: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used

Linux kernel doesn't like floating point, say so.

Signed-off-by: Joe Perches <[email protected]>
---
scripts/checkpatch.pl | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c3a2162..96685c6 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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) {
--
1.7.8.112.g3fd21

2012-11-06 23:36:28

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used

On Thu, 1 Nov 2012 00:12:18 -0700
Joe Perches <[email protected]> wrote:

> Linux kernel doesn't like floating point, say so.
>
> ...
>
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -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) {

The earlier review comments were not addressed.

In particular, I don't see a problem with people doing

int foo = 1.1 * 2.2;

2012-11-07 09:40:19

by Andy Whitcroft

[permalink] [raw]
Subject: Re: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used

On Tue, Nov 06, 2012 at 03:36:25PM -0800, Andrew Morton wrote:
> On Thu, 1 Nov 2012 00:12:18 -0700
> Joe Perches <[email protected]> wrote:
>
> > Linux kernel doesn't like floating point, say so.
> >
> > ...
> >
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -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) {
>
> The earlier review comments were not addressed.
>
> 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

2012-11-07 11:09:47

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used

On Tue, 2012-11-06 at 15:36 -0800, Andrew Morton wrote:
> On Thu, 1 Nov 2012 00:12:18 -0700
> Joe Perches <[email protected]> wrote:
> > Linux kernel doesn't like floating point, say so.
[]
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -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) {
>
> 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.

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

2012-11-07 16:53:03

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH V2 3/3] checkpatch: Emit an warning when floating point values are used

On Wed, 07 Nov 2012 03:09:35 -0800 Joe Perches <[email protected]> wrote:

> On Tue, 2012-11-06 at 15:36 -0800, Andrew Morton wrote:
> > On Thu, 1 Nov 2012 00:12:18 -0700
> > Joe Perches <[email protected]> wrote:
> > > Linux kernel doesn't like floating point, say so.
> []
> > > --- a/scripts/checkpatch.pl
> > > +++ b/scripts/checkpatch.pl
> > > @@ -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) {
> >
> > The earlier review comments were not addressed.
>
> You didn't read my response in the thread then.

There was no response afaict. Not here, not on lkml.org?