History

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

Suchit Karunakaran committed 1 year ago

Commit 99b70ec1 parent 20a8e041 file · +8 −4Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

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