Skip to contentSkip to conversation

checkpatch.pl: Warn on duplicate sysctl local variable

PATCH Superseded Matteo Croce 3 participants 5 messages May 31, 2019 Checkpatch

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index 342c7c781ba5..629c31435487 100755
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
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 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,
Quoted 7 lines

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

-Kees

Quoted 24 lines
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
index 342c7c781ba5..629c31435487 100755
@@ -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
Signature · 1 line
Kees Cook
maintainer
#2 lore raw
In reply to Matteo Croce
Quoted 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 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 +0 -0
index 342c7c781ba5..629c31435487 100755

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 ?

#3 lore raw
Quoted 34 lines · Joe Perches
Quoted 1 line · Matteo Croce

Commit 6a33853c5773 ("proc/sysctl: add shared variables for range

check")

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 a ctl_table

struct:

Quoted 3 lines
    $ scripts/checkpatch.pl 0001-test-commit.patch
    WARNING: duplicated sysctl range checking value 'zero', consider

using the shared one in include/linux/sysctl.h

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

Quoted 15 lines

#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 +0 -0
index 342c7c781ba5..629c31435487 100755

scripts/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
maintainer
#4 lore raw
Quoted 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.