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/.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -2636,6 +2636,11 @@ sub exclude_global_initialisers { · 2635 unmodified lines | ||
| 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 | |
| @@ -7018,21 +7023,20 @@ sub process { · 4376 unmodified lines | ||
| 7018 | 7023 | # } |
| 7019 | 7024 | # } |
| 7020 | 7025 | # } |
| 7021 | − | |
| 7022 | 7026 | # strcpy uses that should likely be strscpy |
| 7023 | − if ($line =~ /\bstrcpy\s*\(/) { | |
| 7027 | + if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) { | |
| 7024 | 7028 | WARN("STRCPY", |
| 7025 | 7029 | "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr); |
| 7026 | 7030 | } |
| 7027 | 7031 | |
| 7028 | 7032 | # strlcpy uses that should likely be strscpy |
| 7029 | − if ($line =~ /\bstrlcpy\s*\(/) { | |
| 7033 | + if ($line =~ /\bstrlcpy\s*\(/ && !is_userspace($realfile)) { | |
| 7030 | 7034 | WARN("STRLCPY", |
| 7031 | 7035 | "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr); |
| 7032 | 7036 | } |
| 7033 | 7037 | |
| 7034 | 7038 | # strncpy uses that should likely be strscpy or strscpy_pad |
| 7035 | − if ($line =~ /\bstrncpy\s*\(/) { | |
| 7039 | + if ($line =~ /\bstrncpy\s*\(/ && !is_userspace($realfile)) { | |
| 7036 | 7040 | WARN("STRNCPY", |
| 7037 | 7041 | "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr); |
| 7038 | 7042 | } |