checkpatch.pl: Warn on duplicate sysctl local variable
PATCH v2 1/1 checkpatch.pl: Warn on duplicate sysctl local variable
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
--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
@@ -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
Signature · 1 line
2.21.0
Quoted 10 lines · Matteo Croce
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 actl_tablestruct:$ 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,
Quoted 7 lines
WARNING: duplicated sysctl range checking value '
int_max', consider using the shared one ininclude/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 <[email protected]>
-Kees
Quoted 24 lines
--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)scripts/checkpatch.pl +6
-0@@ -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 onSignature · 1 line
2.21.0
Signature · 1 line
Kees Cook
Joe Perches
maintainerQuoted 26 lines · Matteo Croce
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 actl_tablestruct:$ 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 ininclude/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 <[email protected]>--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl sub process { · line 6644
Quoted 6 lines
scripts/checkpatch.pl +3
-0@@ -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 ?
Quoted 34 lines · Joe Perches
Quoted 1 line · Matteo Croce
Commit
6a33853c5773("proc/sysctl: add shared variables for rangecheck")
Quoted 1 line
adds some shared const variables to be used instead of a local copy
in
Quoted 2 lines
each source file.
Warn when a chunk duplicates one of these values in actl_tablestruct:
Quoted 3 lines
$ scripts/checkpatch.pl 0001-test-commit.patch WARNING: duplicated sysctl range checking value 'zero', considerusing the shared one in
include/linux/sysctl.hQuoted 4 lines
#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.hQuoted 15 lines
#28: FILE:
arch/arm/kernel/isa.c:49:
+ .extra2 =&int_max,total: 0 errors, 2 warnings, 14 lines checked
Signed-off-by Matteo Croce <[email protected]>--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)scripts/checkpatch.pl +0
-0scripts/checkpatch.pl sub process { · line 6639
Quoted 1 line
scripts/checkpatch.pl +0
-0@@ -6639,6 +6639,12 @@ sub process { "unknown module license " . $extracted_string . "\n" .$herecurr);
Quoted 7 lines
scripts/checkpatch.pl sub process { · line 6644
Quoted 5 lines
scripts/checkpatch.pl +3
-0} } + +# 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,
Signature · 2 lines
Matteo Croce per aspera ad upstream
Joe Perches
maintainerQuoted 10 lines · Matteo Croce
Quoted 6 lines · Joe Perches
scripts/checkpatch.pl sub process { · line 6644
Quoted 3 lines · Matteo Croce
scripts/checkpatch.pl +3
-0+ +# 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.