Skip to content

Commit 99b70ec

Browse files
suchit07-gitakpm00
authored andcommitted
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/[email protected] Signed-off-by: Suchit Karunakaran <[email protected]> Acked-by: Joe Perches <[email protected]> Cc: Andy Whitcroft <[email protected]> Cc: Dwaipayan Ray <[email protected]> Cc: Lukas Bulwahn <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 20a8e04 commit 99b70ec

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/checkpatch.pl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,11 @@ sub exclude_global_initialisers {
26362636
$realfile =~ m@/bpf/.*\.bpf\.c$@;
26372637
}
26382638

2639+
sub is_userspace {
2640+
my ($realfile) = @_;
2641+
return ($realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@);
2642+
}
2643+
26392644
sub process {
26402645
my $filename = shift;
26412646

@@ -7018,21 +7023,20 @@ sub process {
70187023
# }
70197024
# }
70207025
# }
7021-
70227026
# strcpy uses that should likely be strscpy
7023-
if ($line =~ /\bstrcpy\s*\(/) {
7027+
if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) {
70247028
WARN("STRCPY",
70257029
"Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
70267030
}
70277031

70287032
# strlcpy uses that should likely be strscpy
7029-
if ($line =~ /\bstrlcpy\s*\(/) {
7033+
if ($line =~ /\bstrlcpy\s*\(/ && !is_userspace($realfile)) {
70307034
WARN("STRLCPY",
70317035
"Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
70327036
}
70337037

70347038
# strncpy uses that should likely be strscpy or strscpy_pad
7035-
if ($line =~ /\bstrncpy\s*\(/) {
7039+
if ($line =~ /\bstrncpy\s*\(/ && !is_userspace($realfile)) {
70367040
WARN("STRNCPY",
70377041
"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
70387042
}

0 commit comments

Comments
 (0)