* [PATCH] checkpatch: suppress strscpy warnings for userspace tools
@ 2025-07-26 18:54 Suchit Karunakaran
2025-07-27 11:55 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Suchit Karunakaran @ 2025-07-26 18:54 UTC (permalink / raw)
To: apw, joe, dwaipayanray1, lukas.bulwahn
Cc: skhan, linux-kernel-mentees, linux-kernel, Suchit Karunakaran
The checkpatch.pl script currently warns against the use of strcpy,
strlcpy, and strncpy, recommending strscpy as a safer alternative.
However, these warnings are also triggered for code under tools/ and
scripts/, which are userspace code where strscpy is not available.
This patch suppresses these warnings for files in tools/ and scripts/.
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
---
scripts/checkpatch.pl | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e722dd6fa8ef..1533cfbc8305 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7020,19 +7020,19 @@ sub process {
# }
# strcpy uses that should likely be strscpy
- if ($line =~ /\bstrcpy\s*\(/) {
+ if ($line =~ /\bstrcpy\s*\(/ && $realfile !~ m@\btools/@ && $realfile !~ m@\bscripts/@) {
WARN("STRCPY",
"Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
}
# strlcpy uses that should likely be strscpy
- if ($line =~ /\bstrlcpy\s*\(/) {
+ if ($line =~ /\bstrlcpy\s*\(/ && $realfile !~ m@\btools/@ && $realfile !~ m@\bscripts/@) {
WARN("STRLCPY",
"Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
}
# strncpy uses that should likely be strscpy or strscpy_pad
- if ($line =~ /\bstrncpy\s*\(/) {
+ if ($line =~ /\bstrncpy\s*\(/ && $realfile !~ m@\btools/@ && $realfile !~ m@\bscripts/@) {
WARN("STRNCPY",
"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] checkpatch: suppress strscpy warnings for userspace tools
2025-07-26 18:54 [PATCH] checkpatch: suppress strscpy warnings for userspace tools Suchit Karunakaran
@ 2025-07-27 11:55 ` Joe Perches
2025-07-27 12:31 ` Suchit K
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2025-07-27 11:55 UTC (permalink / raw)
To: Suchit Karunakaran, apw, dwaipayanray1, lukas.bulwahn
Cc: skhan, linux-kernel-mentees, linux-kernel
On Sun, 2025-07-27 at 00:24 +0530, Suchit Karunakaran wrote:
> The checkpatch.pl script currently warns against the use of strcpy,
> strlcpy, and strncpy, recommending strscpy as a safer alternative.
> However, these warnings are also triggered for code under tools/ and
> scripts/, which are userspace code where strscpy is not available.
> This patch suppresses these warnings for files in tools/ and scripts/.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7020,19 +7020,19 @@ sub process {
> # }
>
> # strcpy uses that should likely be strscpy
> - if ($line =~ /\bstrcpy\s*\(/) {
> + if ($line =~ /\bstrcpy\s*\(/ && $realfile !~ m@\btools/@ && $realfile !~ m@\bscripts/@) {
Maybe instead create a is_kernel or is_userspace function
and use that instead of the test
if (!is_userspace($realfile) &&
$line =~ etc...
and
are all <any_subdirectory>tools/ always userspace ?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] checkpatch: suppress strscpy warnings for userspace tools
2025-07-27 11:55 ` Joe Perches
@ 2025-07-27 12:31 ` Suchit K
0 siblings, 0 replies; 3+ messages in thread
From: Suchit K @ 2025-07-27 12:31 UTC (permalink / raw)
To: Joe Perches
Cc: apw, dwaipayanray1, lukas.bulwahn, skhan, linux-kernel-mentees,
linux-kernel
On Sun, 27 Jul 2025 at 17:25, Joe Perches <joe@perches.com> wrote:
>
> On Sun, 2025-07-27 at 00:24 +0530, Suchit Karunakaran wrote:
> > The checkpatch.pl script currently warns against the use of strcpy,
> > strlcpy, and strncpy, recommending strscpy as a safer alternative.
> > However, these warnings are also triggered for code under tools/ and
> > scripts/, which are userspace code where strscpy is not available.
> > This patch suppresses these warnings for files in tools/ and scripts/.
> []
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -7020,19 +7020,19 @@ sub process {
> > # }
> >
> > # strcpy uses that should likely be strscpy
> > - if ($line =~ /\bstrcpy\s*\(/) {
> > + if ($line =~ /\bstrcpy\s*\(/ && $realfile !~ m@\btools/@ && $realfile !~ m@\bscripts/@) {
>
> Maybe instead create a is_kernel or is_userspace function
> and use that instead of the test
Sure, I will do it.
>
> if (!is_userspace($realfile) &&
> $line =~ etc...
>
> and
>
> are all <any_subdirectory>tools/ always userspace ?
>
Yes, as far as I know, almost all of the code in the tools directory
is userspace. Atleast, strscpy isn't available for the code inside
tools and scripts.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-27 12:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-26 18:54 [PATCH] checkpatch: suppress strscpy warnings for userspace tools Suchit Karunakaran
2025-07-27 11:55 ` Joe Perches
2025-07-27 12:31 ` Suchit K
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).