* [PATCH v6 1/4] checkpatch: Add more userspace directories to is_userspace()
2026-09-04 11:02 [PATCH v6 0/4] checkpatch: userspace improvements Petr Vorel
@ 2026-09-04 11:02 ` Petr Vorel
2026-09-04 11:02 ` [PATCH v6 2/4] checkpatch: Ignore <inttypes.h> format macros for userspace tools Petr Vorel
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-09-04 11:02 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>
---
The same as in v5.
scripts/checkpatch.pl | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f424dafce5bc..b8702f6bc9b5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2667,7 +2667,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/.*/tools/@);
}
sub process {
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v6 2/4] checkpatch: Ignore <inttypes.h> format macros for userspace tools
2026-09-04 11:02 [PATCH v6 0/4] checkpatch: userspace improvements Petr Vorel
2026-09-04 11:02 ` [PATCH v6 1/4] checkpatch: Add more userspace directories to is_userspace() Petr Vorel
@ 2026-09-04 11:02 ` Petr Vorel
2026-09-04 11:02 ` [PATCH v6 3/4] checkpatch: Add --userspace to force userspace rules Petr Vorel
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-09-04 11:02 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 v5 and earlier versions.
scripts/checkpatch.pl | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b8702f6bc9b5..b458c7f22684 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5950,6 +5950,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 v6 3/4] checkpatch: Add --userspace to force userspace rules
2026-09-04 11:02 [PATCH v6 0/4] checkpatch: userspace improvements Petr Vorel
2026-09-04 11:02 ` [PATCH v6 1/4] checkpatch: Add more userspace directories to is_userspace() Petr Vorel
2026-09-04 11:02 ` [PATCH v6 2/4] checkpatch: Ignore <inttypes.h> format macros for userspace tools Petr Vorel
@ 2026-09-04 11:02 ` Petr Vorel
2026-09-04 11:02 ` [PATCH v6 4/4] checkpatch: Skip kernel specific checks for userspace Petr Vorel
2026-09-06 1:22 ` [PATCH v6 0/4] checkpatch: userspace improvements Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-09-04 11:02 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
files with kernel code.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
The same as in v5.
scripts/checkpatch.pl | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b458c7f22684..ead35e6abba7 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;
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
@@ -2667,6 +2670,9 @@ sub exclude_global_initialisers {
sub is_userspace {
my ($realfile) = @_;
+
+ return $userspace if (defined $userspace);
+
return ($realfile =~ m@^tools/@ ||
$realfile =~ m@^scripts/@ ||
$realfile =~ m@^arch/.*/tools/@);
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v6 4/4] checkpatch: Skip kernel specific checks for userspace
2026-09-04 11:02 [PATCH v6 0/4] checkpatch: userspace improvements Petr Vorel
` (2 preceding siblings ...)
2026-09-04 11:02 ` [PATCH v6 3/4] checkpatch: Add --userspace to force userspace rules Petr Vorel
@ 2026-09-04 11:02 ` Petr Vorel
2026-09-06 1:22 ` [PATCH v6 0/4] checkpatch: userspace improvements Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-09-04 11:02 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Vorel, Andrew Morton, Andy Whitcroft, Joe Perches,
Dwaipayan Ray, Lukas Bulwahn, Cryolitia PukNgae
These check are kernel specific, do not warn about it when testing
userspace code:
* BIT_MACRO
* LONG_UDELAY
* MSLEEP
* PREFER_KERNEL_TYPES
* USLEEP_RANGE
Follow-up: 99b70ece33d8 ("checkpatch: suppress strscpy warnings for userspace tools")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
v6: Fix: use is_userspace instead of is_uapi().
scripts/checkpatch.pl | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ead35e6abba7..3614cfe4dcbb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6696,7 +6696,8 @@ sub process {
}
# prefer usleep_range over udelay
- if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
+ if (!is_userspace($realfile) &&
+ $line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
my $delay = $1;
# ignore udelay's < 10, however
if (! ($delay < 10) ) {
@@ -6710,7 +6711,8 @@ sub process {
}
# warn about unexpectedly long msleep's
- if ($line =~ /\bmsleep\s*\((\d+)\);/) {
+ if (!is_userspace($realfile) &&
+ $line =~ /\bmsleep\s*\((\d+)\);/) {
if ($1 < 20) {
WARN("MSLEEP",
"msleep < 20ms can sleep for up to 20ms; see function description of msleep().\n" . $herecurr);
@@ -6932,7 +6934,7 @@ sub process {
# check for c99 types like uint8_t used outside of uapi/ and tools/
if ($realfile !~ m@\binclude/uapi/@ &&
- $realfile !~ m@\btools/@ &&
+ !is_userspace($realfile) &&
$line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
my $type = $1;
if ($type =~ /\b($typeC99Typedefs)\b/) {
@@ -7182,6 +7184,7 @@ sub process {
# check usleep_range arguments
if ($perl_version_ok &&
defined $stat &&
+ !is_userspace($realfile) &&
$stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
my $min = $1;
my $max = $7;
@@ -7425,6 +7428,7 @@ sub process {
# check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
if ($realfile !~ m@^include/uapi/@ &&
+ !is_userspace($realfile) &&
$line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
my $ull = "";
$ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v6 0/4] checkpatch: userspace improvements
2026-09-04 11:02 [PATCH v6 0/4] checkpatch: userspace improvements Petr Vorel
` (3 preceding siblings ...)
2026-09-04 11:02 ` [PATCH v6 4/4] checkpatch: Skip kernel specific checks for userspace Petr Vorel
@ 2026-09-06 1:22 ` Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2026-09-06 1:22 UTC (permalink / raw)
To: Petr Vorel
Cc: linux-kernel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
Lukas Bulwahn, Cryolitia PukNgae
On Fri, 4 Sep 2026 13:02:26 +0200 Petr Vorel <pvorel@suse.cz> wrote:
> Few improvements for user space code + --userspace option for projects
> which vendored checkpatch.pl.
>
> There could be probably more checks which are kernel space only.
Thanks. Let me put this into mm.git's mm-nonmm-unstable branch (and
hence into linux-next) for testing and additional review.
> Follow-up: 99b70ece33d8 ("checkpatch: suppress strscpy warnings for userspace tools")
Sorry, I'm not a fan of inventing new tags. This isn't a documented
tag and nobody has ever used it before. I altered these to
: This is a follow-up to 99b70ece33d8 ("checkpatch: suppress strscpy
: warnings for userspace tools").
^ permalink raw reply [flat|nested] 6+ messages in thread