All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable
@ 2019-05-31  1:12 Matteo Croce
  2019-05-31  2:04 ` Kees Cook
  2019-05-31  3:06 ` Joe Perches
  0 siblings, 2 replies; 5+ messages in thread
From: Matteo Croce @ 2019-05-31  1:12 UTC (permalink / raw)
  To: linux-kernel, Andy Whitcroft, Joe Perches
  Cc: Kees Cook, Aaron Tomlin, Matthew Wilcox, Andrew Morton

Commit 6a33853c5773 ("proc/sysctl: add shared variables for range check")
adds some shared const variables to be used instead of a local copy in
each source file.
Warn when a chunk duplicates one of these values in a ctl_table struct:

    $ scripts/checkpatch.pl 0001-test-commit.patch
    WARNING: duplicated sysctl range checking value 'zero', consider using the shared one in include/linux/sysctl.h
    #27: FILE: arch/arm/kernel/isa.c:48:
    +               .extra1         = &zero,

    WARNING: duplicated sysctl range checking value 'int_max', consider using the shared one in include/linux/sysctl.h
    #28: FILE: arch/arm/kernel/isa.c:49:
    +               .extra2         = &int_max,

    total: 0 errors, 2 warnings, 14 lines checked

Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 342c7c781ba5..629c31435487 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6639,6 +6639,12 @@ sub process {
 				     "unknown module license " . $extracted_string . "\n" . $herecurr);
 			}
 		}
+
+# check for sysctl duplicate constants
+		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max|max_int)\b/) {
+			WARN("DUPLICATED_SYSCTL_CONST",
+				"duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr);
+		}
 	}
 
 	# If we have no input at all, then there is nothing to report on
-- 
2.21.0


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

* Re: [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable
  2019-05-31  1:12 [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable Matteo Croce
@ 2019-05-31  2:04 ` Kees Cook
  2019-05-31  3:06 ` Joe Perches
  1 sibling, 0 replies; 5+ messages in thread
From: Kees Cook @ 2019-05-31  2:04 UTC (permalink / raw)
  To: Matteo Croce
  Cc: linux-kernel, Andy Whitcroft, Joe Perches, Aaron Tomlin,
	Matthew Wilcox, Andrew Morton

On Fri, May 31, 2019 at 03:12:27AM +0200, Matteo Croce wrote:
> Commit 6a33853c5773 ("proc/sysctl: add shared variables for range check")
> adds some shared const variables to be used instead of a local copy in
> each source file.
> Warn when a chunk duplicates one of these values in a ctl_table struct:
> 
>     $ scripts/checkpatch.pl 0001-test-commit.patch
>     WARNING: duplicated sysctl range checking value 'zero', consider using the shared one in include/linux/sysctl.h
>     #27: FILE: arch/arm/kernel/isa.c:48:
>     +               .extra1         = &zero,
> 
>     WARNING: duplicated sysctl range checking value 'int_max', consider using the shared one in include/linux/sysctl.h
>     #28: FILE: arch/arm/kernel/isa.c:49:
>     +               .extra2         = &int_max,
> 
>     total: 0 errors, 2 warnings, 14 lines checked
> 
> Signed-off-by: Matteo Croce <mcroce@redhat.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 342c7c781ba5..629c31435487 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6639,6 +6639,12 @@ sub process {
>  				     "unknown module license " . $extracted_string . "\n" . $herecurr);
>  			}
>  		}
> +
> +# check for sysctl duplicate constants
> +		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max|max_int)\b/) {
> +			WARN("DUPLICATED_SYSCTL_CONST",
> +				"duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr);
> +		}
>  	}
>  
>  	# If we have no input at all, then there is nothing to report on
> -- 
> 2.21.0
> 

-- 
Kees Cook

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

* Re: [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable
  2019-05-31  1:12 [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable Matteo Croce
  2019-05-31  2:04 ` Kees Cook
@ 2019-05-31  3:06 ` Joe Perches
  2019-05-31  8:44   ` Matteo Croce
  1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2019-05-31  3:06 UTC (permalink / raw)
  To: Matteo Croce, linux-kernel, Andy Whitcroft
  Cc: Kees Cook, Aaron Tomlin, Matthew Wilcox, Andrew Morton

On Fri, 2019-05-31 at 03:12 +0200, Matteo Croce wrote:
> Commit 6a33853c5773 ("proc/sysctl: add shared variables for range check")
> adds some shared const variables to be used instead of a local copy in
> each source file.
> Warn when a chunk duplicates one of these values in a ctl_table struct:
> 
>     $ scripts/checkpatch.pl 0001-test-commit.patch
>     WARNING: duplicated sysctl range checking value 'zero', consider using the shared one in include/linux/sysctl.h
>     #27: FILE: arch/arm/kernel/isa.c:48:
>     +               .extra1         = &zero,
> 
>     WARNING: duplicated sysctl range checking value 'int_max', consider using the shared one in include/linux/sysctl.h
>     #28: FILE: arch/arm/kernel/isa.c:49:
>     +               .extra2         = &int_max,
> 
>     total: 0 errors, 2 warnings, 14 lines checked
> 
> Signed-off-by: Matteo Croce <mcroce@redhat.com>
> ---
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 342c7c781ba5..629c31435487 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6639,6 +6639,12 @@ sub process {
>  				     "unknown module license " . $extracted_string . "\n" . $herecurr);
>  			}
>  		}
> +
> +# check for sysctl duplicate constants
> +		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max|max_int)\b/) {

why max_int, there isn't a single use of it in the kernel ?



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

* Re: [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable
  2019-05-31  3:06 ` Joe Perches
@ 2019-05-31  8:44   ` Matteo Croce
  2019-05-31 10:26     ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Matteo Croce @ 2019-05-31  8:44 UTC (permalink / raw)
  To: Joe Perches, linux-kernel, Andy Whitcroft
  Cc: Kees Cook, Aaron Tomlin, Matthew Wilcox, Andrew Morton

On May 31, 2019 5:06:58 AM GMT+02:00, Joe Perches <joe@perches.com> wrote:
> On Fri, 2019-05-31 at 03:12 +0200, Matteo Croce wrote:
> > Commit 6a33853c5773 ("proc/sysctl: add shared variables for range
> check")
> > adds some shared const variables to be used instead of a local copy
> in
> > each source file.
> > Warn when a chunk duplicates one of these values in a ctl_table
> struct:
> > 
> >     $ scripts/checkpatch.pl 0001-test-commit.patch
> >     WARNING: duplicated sysctl range checking value 'zero', consider
> using the shared one in include/linux/sysctl.h
> >     #27: FILE: arch/arm/kernel/isa.c:48:
> >     +               .extra1         = &zero,
> > 
> >     WARNING: duplicated sysctl range checking value 'int_max',
> consider using the shared one in include/linux/sysctl.h
> >     #28: FILE: arch/arm/kernel/isa.c:49:
> >     +               .extra2         = &int_max,
> > 
> >     total: 0 errors, 2 warnings, 14 lines checked
> > 
> > Signed-off-by: Matteo Croce <mcroce@redhat.com>
> > ---
> >  scripts/checkpatch.pl | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 342c7c781ba5..629c31435487 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -6639,6 +6639,12 @@ sub process {
> >  				     "unknown module license " . $extracted_string . "\n" .
> $herecurr);
> >  			}
> >  		}
> > +
> > +# check for sysctl duplicate constants
> > +		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max|max_int)\b/) {
> 
> why max_int, there isn't a single use of it in the kernel ?

Because you can never know how a local variabile will be called.
I wanted to add intmax and maxint too, bit it seemed too much.

Bye,
-- 
Matteo Croce
per aspera ad upstream

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

* Re: [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable
  2019-05-31  8:44   ` Matteo Croce
@ 2019-05-31 10:26     ` Joe Perches
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2019-05-31 10:26 UTC (permalink / raw)
  To: Matteo Croce, linux-kernel, Andy Whitcroft
  Cc: Kees Cook, Aaron Tomlin, Matthew Wilcox, Andrew Morton

On Fri, 2019-05-31 at 10:44 +0200, Matteo Croce wrote:
> On May 31, 2019 5:06:58 AM GMT+02:00, Joe Perches <joe@perches.com> wrote:
> > On Fri, 2019-05-31 at 03:12 +0200, Matteo Croce wrote:
> > > +
> > > +# check for sysctl duplicate constants
> > > +		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max|max_int)\b/) {
> > 
> > why max_int, there isn't a single use of it in the kernel ?
> 
> Because you can never know how a local variabile will be called.
> I wanted to add intmax and maxint too, bit it seemed too much.

I think that checkpatch should not speculate about things like this.



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

end of thread, other threads:[~2019-05-31 10:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-31  1:12 [PATCH v2] checkpatch.pl: Warn on duplicate sysctl local variable Matteo Croce
2019-05-31  2:04 ` Kees Cook
2019-05-31  3:06 ` Joe Perches
2019-05-31  8:44   ` Matteo Croce
2019-05-31 10:26     ` Joe Perches

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.