Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/.

Link: https://lkml.kernel.org/r/20250923171722.7798-1-suchitkarunakaran@gmail.com
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
Acked-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Suchit Karunakaran and committed by
Andrew Morton
99b70ece 20a8e045

+8 -4
+8 -4
scripts/checkpatch.pl
··· 2636 2636 $realfile =~ m@/bpf/.*\.bpf\.c$@; 2637 2637 } 2638 2638 2639 + sub is_userspace { 2640 + my ($realfile) = @_; 2641 + return ($realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@); 2642 + } 2643 + 2639 2644 sub process { 2640 2645 my $filename = shift; 2641 2646 ··· 7023 7018 # } 7024 7019 # } 7025 7020 # } 7026 - 7027 7021 # strcpy uses that should likely be strscpy 7028 - if ($line =~ /\bstrcpy\s*\(/) { 7022 + if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) { 7029 7023 WARN("STRCPY", 7030 7024 "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr); 7031 7025 } 7032 7026 7033 7027 # strlcpy uses that should likely be strscpy 7034 - if ($line =~ /\bstrlcpy\s*\(/) { 7028 + if ($line =~ /\bstrlcpy\s*\(/ && !is_userspace($realfile)) { 7035 7029 WARN("STRLCPY", 7036 7030 "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr); 7037 7031 } 7038 7032 7039 7033 # strncpy uses that should likely be strscpy or strscpy_pad 7040 - if ($line =~ /\bstrncpy\s*\(/) { 7034 + if ($line =~ /\bstrncpy\s*\(/ && !is_userspace($realfile)) { 7041 7035 WARN("STRNCPY", 7042 7036 "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr); 7043 7037 }