* [PATCH v4 1/3] checkpatch: Add more userspace directories to is_userspace()
2026-08-10 16:45 [PATCH v4 0/3] checkpatch: userspace improvements Petr Vorel
@ 2026-08-10 16:45 ` Petr Vorel
2026-08-10 16:45 ` [PATCH v4 2/3] checkpatch: Ignore <inttypes.h> format macros for userspace tools Petr Vorel
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-08-10 16:45 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Vorel, Andrew Morton, Andy Whitcroft, Joe Perches,
Dwaipayan Ray, Lukas Bulwahn, Cryolitia PukNgae
arch/ directory contains subdirectories with userspace tools (at least
arch/*/tools/ and arch/*/boot/tools/). Add check to consider any
arch/.*/tools/ subdirectory as userspace tools directory.
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")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v3->v4:
* Change test for directory to be more more generic (Joe)
scripts/checkpatch.pl | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4f7325fd5825..1c6ef46bae1e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2665,7 +2665,9 @@ 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/.*\btools\b@);
}
sub process {
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v4 2/3] checkpatch: Ignore <inttypes.h> format macros for userspace tools
2026-08-10 16:45 [PATCH v4 0/3] checkpatch: userspace improvements Petr Vorel
2026-08-10 16:45 ` [PATCH v4 1/3] checkpatch: Add more userspace directories to is_userspace() Petr Vorel
@ 2026-08-10 16:45 ` Petr Vorel
2026-08-10 16:45 ` [PATCH v4 3/3] checkpatch: Add new option to force userspace Petr Vorel
2026-09-01 3:55 ` [PATCH v4 0/3] checkpatch: userspace improvements Andrew Morton
3 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-08-10 16:45 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Vorel, Andrew Morton, Andy Whitcroft, Joe Perches,
Dwaipayan Ray, Lukas Bulwahn, Cryolitia PukNgae
Constants 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>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
The same as in v3.
scripts/checkpatch.pl | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1c6ef46bae1e..ff99265056f8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5947,6 +5947,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) {
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v4 3/3] checkpatch: Add new option to force userspace
2026-08-10 16:45 [PATCH v4 0/3] checkpatch: userspace improvements Petr Vorel
2026-08-10 16:45 ` [PATCH v4 1/3] checkpatch: Add more userspace directories to is_userspace() Petr Vorel
2026-08-10 16:45 ` [PATCH v4 2/3] checkpatch: Ignore <inttypes.h> format macros for userspace tools Petr Vorel
@ 2026-08-10 16:45 ` Petr Vorel
2026-09-01 3:55 ` [PATCH v4 0/3] checkpatch: userspace improvements Andrew Morton
3 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-08-10 16:45 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Vorel, Andrew Morton, Andy Whitcroft, Joe Perches,
Dwaipayan Ray, Lukas Bulwahn, Cryolitia PukNgae
Also allow to use --no-userspace for userspace projects which vendored
checkpatch.pl and use --userspace globally to be able switch it off for
some files.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v3->v4:
* Allow to use --no-userspace (sashiko)
scripts/checkpatch.pl | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ff99265056f8..4b6250f6a614 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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
@@ -2665,7 +2668,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/.*\btools\b@);
}
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v4 0/3] checkpatch: userspace improvements
2026-08-10 16:45 [PATCH v4 0/3] checkpatch: userspace improvements Petr Vorel
` (2 preceding siblings ...)
2026-08-10 16:45 ` [PATCH v4 3/3] checkpatch: Add new option to force userspace Petr Vorel
@ 2026-09-01 3:55 ` Andrew Morton
2026-09-01 6:17 ` Petr Vorel
3 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2026-09-01 3:55 UTC (permalink / raw)
To: Petr Vorel
Cc: linux-kernel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
Lukas Bulwahn, Cryolitia PukNgae
On Mon, 10 Aug 2026 18:45:49 +0200 Petr Vorel <pvorel@suse.cz> wrote:
> Changes v3->v4:
> * Change test for directory to be more more generic (Joe)
> * Allow to use --no-userspace (sashiko)
Sashiko had a few more questions?
https://sashiko.dev/#/patchset/20260810164552.1049483-1-pvorel@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v4 0/3] checkpatch: userspace improvements
2026-09-01 3:55 ` [PATCH v4 0/3] checkpatch: userspace improvements Andrew Morton
@ 2026-09-01 6:17 ` Petr Vorel
0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-09-01 6:17 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
Lukas Bulwahn, Cryolitia PukNgae
Hi Andrew,
> On Mon, 10 Aug 2026 18:45:49 +0200 Petr Vorel <pvorel@suse.cz> wrote:
> > Changes v3->v4:
> > * Change test for directory to be more more generic (Joe)
> > * Allow to use --no-userspace (sashiko)
> Sashiko had a few more questions?
> https://sashiko.dev/#/patchset/20260810164552.1049483-1-pvorel@suse.cz
Thanks for a reminder. All are about kernel code being wrongly considered as user space.
At the beginning I was not sure if we need --no-userspace at all, but we
probably do for non-kernel projects which pass --userspace permanently via
configuration file.
1) The original regex was suggested by Joe and should mostly work, but using /
is indeed safer.
-m@^arch/.*\btools\b@
+m@^arch/.*/tools/@
2) my $userspace = 0 will indeed prevent --no-userspace from working as an
override. I did not considered this as important, but let's fix that.
3) return ($userspace || path based detection: dtto
=> v5
Kind regards,
Petr
^ permalink raw reply [flat|nested] 6+ messages in thread