public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch: suppress strscpy warnings for userspace tools
@ 2025-07-27 12:50 Suchit Karunakaran
  2025-07-29 10:24 ` Joe Perches
  2025-07-29 14:42 ` Markus Elfring
  0 siblings, 2 replies; 10+ messages in thread
From: Suchit Karunakaran @ 2025-07-27 12:50 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 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-07-29 16:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-27 12:50 [PATCH v2] checkpatch: suppress strscpy warnings for userspace tools Suchit Karunakaran
2025-07-29 10:24 ` Joe Perches
2025-07-29 11:45   ` Suchit Karunakaran
2025-07-29 13:44     ` Joe Perches
2025-07-29 14:44       ` Suchit Karunakaran
2025-07-29 14:59       ` Suchit Karunakaran
2025-07-29 16:08         ` Joe Perches
2025-07-29 14:42 ` Markus Elfring
2025-07-29 14:45   ` Suchit Karunakaran
2025-07-29 14:55     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox