scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
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 utilities where strscpy is not available.
This patch suppresses these warnings for files in tools/ and scripts/.
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
Changes since v1:
- Create is_userspace function to check if the file is in userspace
directories
---
scripts/checkpatch.pl | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e722dd6fa8ef..472cd8aac9c3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7019,20 +7019,24 @@ sub process {
# }
# }
+ sub is_userspace {
+ my ($file) = @_;
+ return ($file =~ m@\btools/@ || $file =~ m@\bscripts/@);
+ }
# strcpy uses that should likely be strscpy
- if ($line =~ /\bstrcpy\s*\(/) {
+ if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) {
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*\(/ && !is_userspace($realfile)) {
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*\(/ && !is_userspace($realfile)) {
WARN("STRNCPY",
"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
}
--
2.50.1
… > This patch suppresses … See also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n94 Regards, Markus
On Tue, 29 Jul 2025 at 20:12, Markus Elfring <Markus.Elfring@web.de> wrote: > > … > > This patch suppresses … > > See also: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n94 > Thanks for the suggestion. Will keep this in mind next time.
On Tue, Jul 29, 2025 at 08:15:03PM +0530, Suchit Karunakaran wrote: > On Tue, 29 Jul 2025 at 20:12, Markus Elfring <Markus.Elfring@web.de> wrote: > > > > … > > > This patch suppresses … > > > > See also: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n94 > > > > Thanks for the suggestion. Will keep this in mind next time. > Hi, This is the semi-friendly patch-bot of Greg Kroah-Hartman. Markus, you seem to have sent a nonsensical or otherwise pointless review comment to a patch submission on a Linux kernel developer mailing list. I strongly suggest that you not do this anymore. Please do not bother developers who are actively working to produce patches and features with comments that, in the end, are a waste of time. Patch submitter, please ignore Markus's suggestion; you do not need to follow it at all. The person/bot/AI that sent it is being ignored by almost all Linux kernel maintainers for having a persistent pattern of behavior of producing distracting and pointless commentary, and inability to adapt to feedback. Please feel free to also ignore emails from them. thanks, greg k-h's patch email bot
On Sun, 2025-07-27 at 18:20 +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 utilities where strscpy is not available. > This patch suppresses these warnings for files in tools/ and scripts/. > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > Changes since v1: > - Create is_userspace function to check if the file is in userspace > directories the changelog bit should go below the --- line > --- This > scripts/checkpatch.pl | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -7019,20 +7019,24 @@ sub process { > # } > # } > > + sub is_userspace { > + my ($file) = @_; > + return ($file =~ m@\btools/@ || $file =~ m@\bscripts/@); All other sub uses start in without indentation. Please move this next to other sub blocks. Please do a git ls-files -- '*tools/' and see if too many other files are matched, especially the Documentation/ ones. > + } > # strcpy uses that should likely be strscpy > - if ($line =~ /\bstrcpy\s*\(/) { > + if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) { > WARN("STRCPY", > "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr); > }
On Tue, 29 Jul 2025 at 15:54, Joe Perches <joe@perches.com> wrote: > > On Sun, 2025-07-27 at 18:20 +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 utilities where strscpy is not available. > > This patch suppresses these warnings for files in tools/ and scripts/. > > > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > > > Changes since v1: > > - Create is_userspace function to check if the file is in userspace > > directories > > the changelog bit should go below the --- line > > > --- > > This Sorry I will change it in the next version. > > scripts/checkpatch.pl | 10 +++++++--- > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > [] > > @@ -7019,20 +7019,24 @@ sub process { > > # } > > # } > > > > + sub is_userspace { > > + my ($file) = @_; > > + return ($file =~ m@\btools/@ || $file =~ m@\bscripts/@); > > All other sub uses start in without indentation. > Please move this next to other sub blocks. > Yup will do it. > Please do a git ls-files -- '*tools/' and see if too many other > files are matched, especially the Documentation/ ones. > I didn't quite understand this. Could you please elaborate?
On Tue, 2025-07-29 at 17:15 +0530, Suchit Karunakaran wrote: > On Tue, 29 Jul 2025 at 15:54, Joe Perches <joe@perches.com> wrote: > > > > On Sun, 2025-07-27 at 18:20 +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 utilities where strscpy is not available. > > > This patch suppresses these warnings for files in tools/ and scripts/. > > > > > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > > > > > Changes since v1: > > > - Create is_userspace function to check if the file is in userspace > > > directories > > > > the changelog bit should go below the --- line > > > > > --- > > > > This > > Sorry I will change it in the next version. > > > > scripts/checkpatch.pl | 10 +++++++--- > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > [] > > > @@ -7019,20 +7019,24 @@ sub process { > > > # } > > > # } > > > > > > + sub is_userspace { > > > + my ($file) = @_; > > > + return ($file =~ m@\btools/@ || $file =~ m@\bscripts/@); > > > > All other sub uses start in without indentation. > > Please move this next to other sub blocks. > > > > Yup will do it. > > > Please do a git ls-files -- '*tools/' and see if too many other > > files are matched, especially the Documentation/ ones. > > > > I didn't quite understand this. Could you please elaborate? The search pattern m@\btools/@ matches files other than the first level tools/ directory. It also matches Documentation/tools/ Perhaps using m@^tools/@ to match only the first level tools and change $file to $realfile to make it clear it's not a/tools or b/tools like the diff filenames.
On Tue, 29 Jul 2025 at 19:14, Joe Perches <joe@perches.com> wrote: > > On Tue, 2025-07-29 at 17:15 +0530, Suchit Karunakaran wrote: > > On Tue, 29 Jul 2025 at 15:54, Joe Perches <joe@perches.com> wrote: > > > > > > On Sun, 2025-07-27 at 18:20 +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 utilities where strscpy is not available. > > > > This patch suppresses these warnings for files in tools/ and scripts/. > > > > > > > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > > > > > > > Changes since v1: > > > > - Create is_userspace function to check if the file is in userspace > > > > directories > > > > > > the changelog bit should go below the --- line > > > > > > > --- > > > > > > This > > > > Sorry I will change it in the next version. > > > > > > scripts/checkpatch.pl | 10 +++++++--- > > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > > [] > > > > @@ -7019,20 +7019,24 @@ sub process { > > > > # } > > > > # } > > > > > > > > + sub is_userspace { > > > > + my ($file) = @_; > > > > + return ($file =~ m@\btools/@ || $file =~ m@\bscripts/@); > > > > > > All other sub uses start in without indentation. > > > Please move this next to other sub blocks. > > > > > > > Yup will do it. > > > > > Please do a git ls-files -- '*tools/' and see if too many other > > > files are matched, especially the Documentation/ ones. > > > > > > > I didn't quite understand this. Could you please elaborate? > > The search pattern m@\btools/@ matches files other than the > first level tools/ directory. > > It also matches Documentation/tools/ > > Perhaps using m@^tools/@ to match only the first level tools > and change $file to $realfile to make it clear it's not > a/tools or b/tools like the diff filenames. > On a related note, should we also suppress warnings for the Documentation folder?
On 2025-07-29 07:59, Suchit Karunakaran wrote: > On a related note, should we also suppress warnings for the > Documentation folder? No
On Tue, 29 Jul 2025 at 19:14, Joe Perches <joe@perches.com> wrote: > > On Tue, 2025-07-29 at 17:15 +0530, Suchit Karunakaran wrote: > > On Tue, 29 Jul 2025 at 15:54, Joe Perches <joe@perches.com> wrote: > > > > > > On Sun, 2025-07-27 at 18:20 +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 utilities where strscpy is not available. > > > > This patch suppresses these warnings for files in tools/ and scripts/. > > > > > > > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > > > > > > > Changes since v1: > > > > - Create is_userspace function to check if the file is in userspace > > > > directories > > > > > > the changelog bit should go below the --- line > > > > > > > --- > > > > > > This > > > > Sorry I will change it in the next version. > > > > > > scripts/checkpatch.pl | 10 +++++++--- > > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > > [] > > > > @@ -7019,20 +7019,24 @@ sub process { > > > > # } > > > > # } > > > > > > > > + sub is_userspace { > > > > + my ($file) = @_; > > > > + return ($file =~ m@\btools/@ || $file =~ m@\bscripts/@); > > > > > > All other sub uses start in without indentation. > > > Please move this next to other sub blocks. > > > > > > > Yup will do it. > > > > > Please do a git ls-files -- '*tools/' and see if too many other > > > files are matched, especially the Documentation/ ones. > > > > > > > I didn't quite understand this. Could you please elaborate? > > The search pattern m@\btools/@ matches files other than the > first level tools/ directory. > > It also matches Documentation/tools/ > > Perhaps using m@^tools/@ to match only the first level tools > and change $file to $realfile to make it clear it's not > a/tools or b/tools like the diff filenames. > Apologies, I missed that part. Will fix it in the next version. Thanks!
© 2016 - 2025 Red Hat, Inc.