checkpatch: suppress strscpy warnings for userspace tools
Subsystems (2)
PATCH v2 1/1 checkpatch: suppress strscpy warnings for userspace tools
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/.
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(-)
scripts/checkpatch.pl +7 -3
@@ -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); }
Signature · 1 line
2.50.1
Joe Perches
maintainerQuoted 11 lines · 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/andscripts/, which are userspace utilities where strscpy is not available. This patch suppresses these warnings for files intools/andscripts/.Signed-off-by Suchit Karunakaran <[email protected]>Changes since v1:
- Createis_userspacefunction to check if the file is in userspace directories
the changelog bit should go below the --- line
Quoted 1 line
---
This
scripts/checkpatch.pl
Quoted 4 lines
scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub process { · line 7024
Quoted 7 lines
scripts/checkpatch.pl +3
-0@@ -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.
Quoted 7 lines
scripts/checkpatch.pl +2
-1+ } # 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); }
Quoted 14 lines · Joe Perches
Quoted 11 lines · 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/andscripts/, which are userspace utilities where strscpy is not available. This patch suppresses these warnings for files intools/andscripts/.Signed-off-by Suchit Karunakaran <[email protected]>Changes since v1:
- Createis_userspacefunction to check if the file is in userspace directories
Quoted 5 lines
the changelog bit should go below the --- line
Quoted 1 line
---
This
Sorry I will change it in the next version.
Quoted 9 lines
scripts/checkpatch.pl
Quoted 4 lines
scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)scripts/checkpatch.pl +0
-0[]
Quoted 4 lines
scripts/checkpatch.pl +0
-0@@ -7019,20 +7019,24 @@ sub process { # } # }
Quoted 7 lines
scripts/checkpatch.pl sub process { · line 7024
Quoted 3 lines
scripts/checkpatch.pl +3
-0+ 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.
Quoted 3 lines
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?
Joe Perches
maintainerQuoted 40 lines · Suchit Karunakaran
Quoted 14 lines · Joe Perches
Quoted 11 lines · 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/andscripts/, which are userspace utilities where strscpy is not available. This patch suppresses these warnings for files intools/andscripts/.Signed-off-by Suchit Karunakaran <[email protected]>Changes since v1:
- Createis_userspacefunction to check if the file is in userspace directoriesQuoted 5 lines
the changelog bit should go below the --- line
Quoted 1 line
---
This
Sorry I will change it in the next version.
Quoted 9 lines
scripts/checkpatch.pl
Quoted 4 lines
scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)scripts/checkpatch.pl +0
-0[]
Quoted 4 lines
scripts/checkpatch.pl +0
-0@@ -7019,20 +7019,24 @@ sub process { # } # }Quoted 7 lines
scripts/checkpatch.pl sub process { · line 7024
Quoted 3 lines
scripts/checkpatch.pl +3
-0+ 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.
Quoted 7 lines
Yup will do it.
Quoted 3 lines
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.
Quoted 50 lines · Joe Perches
Quoted 40 lines · Suchit Karunakaran
Quoted 14 lines · Joe Perches
Quoted 11 lines · 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/andscripts/, which are userspace utilities where strscpy is not available. This patch suppresses these warnings for files intools/andscripts/.Signed-off-by Suchit Karunakaran <[email protected]>Changes since v1:
- Createis_userspacefunction to check if the file is in userspace directoriesQuoted 5 lines
the changelog bit should go below the --- line
Quoted 1 line
---
This
Sorry I will change it in the next version.
Quoted 9 lines
scripts/checkpatch.pl
Quoted 4 lines
scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)scripts/checkpatch.pl +0
-0[]
Quoted 4 lines
scripts/checkpatch.pl +0
-0@@ -7019,20 +7019,24 @@ sub process { # } # }Quoted 7 lines
scripts/checkpatch.pl sub process { · line 7024
Quoted 3 lines
scripts/checkpatch.pl +3
-0+ 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.Quoted 7 lines
Yup will do it.
Quoted 3 lines
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?
Quoted 9 lines
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!
Quoted 50 lines · Joe Perches
Quoted 40 lines · Suchit Karunakaran
Quoted 14 lines · Joe Perches
Quoted 11 lines · 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/andscripts/, which are userspace utilities where strscpy is not available. This patch suppresses these warnings for files intools/andscripts/.Signed-off-by Suchit Karunakaran <[email protected]>Changes since v1:
- Createis_userspacefunction to check if the file is in userspace directoriesQuoted 5 lines
the changelog bit should go below the --- line
Quoted 1 line
---
This
Sorry I will change it in the next version.
Quoted 9 lines
scripts/checkpatch.pl
Quoted 4 lines
scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)scripts/checkpatch.pl +0
-0[]
Quoted 4 lines
scripts/checkpatch.pl +0
-0@@ -7019,20 +7019,24 @@ sub process { # } # }Quoted 7 lines
scripts/checkpatch.pl sub process { · line 7024
Quoted 3 lines
scripts/checkpatch.pl +3
-0+ 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.Quoted 7 lines
Yup will do it.
Quoted 3 lines
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?
Quoted 9 lines
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?
Joe Perches
maintainerQuoted 2 lines · Suchit Karunakaran
On a related note, should we also suppress warnings for the Documentation folder?
No
…
Quoted 1 line
This patch suppresses …
Regards,
Markus
Quoted 7 lines · Markus Elfring
…
Quoted 1 line
This patch suppresses …
Thanks for the suggestion. Will keep this in mind next time.
Quoted 11 lines · Suchit Karunakaran
Quoted 7 lines · Markus Elfring
…
Quoted 1 line
This patch suppresses …
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