checkpatch: userspace improvements
v3 cover checkpatch: userspace improvements
Changes v2->v3:
* Fix unintentional disablement of CamelCase warnings on non-userspace sources (sashiko).
* 2 new commits.
Link to v2:
https://lore.kernel.org/lkml/[email protected]/
https://sashiko.dev/#/patchset/20260519162004.81665-1-pvorel%40suse.cz
Petr Vorel (3):
checkpatch: Add more user space directories to is_userspace()
checkpatch: Ignore <inttypes.h> format macros for userspace tools
checkpatch: Add new option to force userspace
scripts/checkpatch.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0
PATCH v3 1/3 checkpatch: Add more user space directories to is_userspace()
arch/*/tools/ and arch/*/boot/tools/ are directories containing user space tools. This helps not only to strscpy checks but also to CamelCase checks in the next commit to be more precise.
Follow-up: 99b70ece33d8 ("checkpatch: suppress strscpy warnings for userspace tools")
---
New in v3.
scripts/checkpatch.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +4 -1
@@ -2669,7 +2669,10 @@ sub exclude_global_initialisers { sub is_userspace { my ($realfile) = @_; - return ($realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@); + return ($realfile =~ m@^tools/@ || + $realfile =~ m@^scripts/@ || + $realfile =~ m@^arch/[^/]+/tools/@ || + $realfile =~ m@^arch/[^/]+/boot/tools/@); } sub process {
Signature · 1 line
2.54.0
Joe Perches
maintainerRe: [PATCH v3 1/3] checkpatch: Add more user space directories to is_userspace()
Quoted 3 lines · Petr Vorel
arch/*/tools/andarch/*/boot/tools/are directories containing user space tools. This helps not only to strscpy checks but also to CamelCase checks in the next commit to be more precise.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub exclude_global_initialisers { · line 2675
Quoted 9 lines
scripts/checkpatch.pl +4
-1@@ -2669,7 +2669,10 @@ sub exclude_global_initialisers { sub is_userspace { my ($realfile) = @_; - return ($realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@); + return ($realfile =~ m@^tools/@ || + $realfile =~ m@^scripts/@ || + $realfile =~ m@^arch/[^/]+/tools/@ || + $realfile =~ m@^arch/[^/]+/boot/tools/@);
Perhaps a more generic test like
m@^arch/.*\btools\b@
Re: [PATCH v3 1/3] checkpatch: Add more user space directories to is_userspace()
Quoted 19 lines · Petr Vorel
Quoted 3 lines
arch/*/tools/andarch/*/boot/tools/are directories containing user space tools. This helps not only to strscpy checks but also to CamelCase checks in the next commit to be more precise.[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
scripts/checkpatch.pl sub exclude_global_initialisers { · line 2675
Quoted 9 lines
scripts/checkpatch.pl +4
-1@@ -2669,7 +2669,10 @@ sub exclude_global_initialisers { sub is_userspace { my ($realfile) = @_; - return ($realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@); + return ($realfile =~ m@^tools/@ || + $realfile =~ m@^scripts/@ || + $realfile =~ m@^arch/[^/]+/tools/@ || + $realfile =~ m@^arch/[^/]+/boot/tools/@);Perhaps a more generic test like
Quoted 1 line
m@^arch/.*\btools\b@
Sure, I'll add it in the next version.
Kind regards,
Petr
PATCH v3 2/3 checkpatch: Ignore <inttypes.h> format macros for userspace tools
In reply to Petr VorelConstants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:
arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>
---
Changes v2->v3:
* Fix unintentional disablement of CamelCase warnings on non-userspace sources (sashiko).
Link to v2:
https://lore.kernel.org/lkml/[email protected]/
https://sashiko.dev/#/patchset/20260519162004.81665-1-pvorel%40suse.cz
scripts/checkpatch.pl | 2 ++ 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
@@ -5945,6 +5945,8 @@ sub process { #Ignore SI style variants like nS, mV and dB #(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE) $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ && +#Ignore <inttypes.h> format macros (e.g. PRIu64, SCNu64) + (is_userspace($realfile) ? $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/ : 1) && #Ignore some three character SI units explicitly, like MiB and KHz $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) { while ($var =~ m{\b($Ident)}g) {
Signature · 1 line
2.54.0
PATCH v3 3/3 checkpatch: Add new option to force userspace
In reply to Petr Vorel---
New in v3.
scripts/checkpatch.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +5 -1
@@ -63,6 +63,7 @@ my $env_config_dir = 'CHECKPATCH_CONFIG_DIR'; my $max_line_length = 100; my $ignore_perl_version = 0; my $spdx_cxx_comments = 0; +my $userspace = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; my $spelling_file = "$D/spelling.txt";
@@ -143,6 +144,7 @@ Options: (required by old toolchains), allow also C++ comments (//). NOTE: it should *not* be used for Linux mainline. + --userspace Force rules specific for userspace. --codespell Use the codespell dictionary for spelling/typos (default:$codespellfile) --codespellfile Use this codespell dictionary
@@ -358,6 +360,7 @@ GetOptions( 'codespell!' => \$codespell, 'codespellfile=s' => \$user_codespellfile, 'typedefsfile=s' => \$typedefsfile, + 'userspace' => \$userspace, 'color=s' => \$color, 'no-color' => \$color, #keep old behaviors of -nocolor 'nocolor' => \$color, #keep old behaviors of -nocolor
@@ -2669,7 +2672,8 @@ sub exclude_global_initialisers { sub is_userspace { my ($realfile) = @_; - return ($realfile =~ m@^tools/@ || + return ($userspace || + $realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@ || $realfile =~ m@^arch/[^/]+/tools/@ || $realfile =~ m@^arch/[^/]+/boot/tools/@);
Signature · 1 line
2.54.0
Re: [PATCH v3 3/3] checkpatch: Add new option to force userspace
Quoted 28 lines
Signed-off-by Petr Vorel <[email protected]>---
New in v3.scripts/checkpatch.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)scripts/checkpatch.pl +2
-0@@ -63,6 +63,7 @@ my $env_config_dir = 'CHECKPATCH_CONFIG_DIR'; my $max_line_length = 100; my $ignore_perl_version = 0; my $spdx_cxx_comments = 0; +my $userspace = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; my $spelling_file = "$D/spelling.txt";@@ -143,6 +144,7 @@ Options: (required by old toolchains), allow also C++ comments (//). NOTE: it should *not* be used for Linux mainline. + --userspace Force rules specific for userspace. --codespell Use the codespell dictionary for spelling/typos (default:$codespellfile) --codespellfile Use this codespell dictionary
scripts/checkpatch.pl GetOptions( · line 363
Quoted 4 lines
scripts/checkpatch.pl +1
-0@@ -358,6 +360,7 @@ GetOptions( 'codespell!' => \$codespell, 'codespellfile=s' => \$user_codespellfile, 'typedefsfile=s' => \$typedefsfile, + 'userspace' => \$userspace,
sashiko suggest to use "!" to allow --no-userspace. I don't see a point in having it because it's off by default, but as most of options without parameters use it, I can add it for consistency.
Kind regards,
Petr
Quoted 13 lines
scripts/checkpatch.pl +2
-1'color=s' => \$color, 'no-color' => \$color, #keep old behaviors of -nocolor 'nocolor' => \$color, #keep old behaviors of -nocolor@@ -2669,7 +2672,8 @@ sub exclude_global_initialisers { sub is_userspace { my ($realfile) = @_; - return ($realfile =~ m@^tools/@ || + return ($userspace || + $realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@ || $realfile =~ m@^arch/[^/]+/tools/@ || $realfile =~ m@^arch/[^/]+/boot/tools/@);