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
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 { · 4376 unmodified lines
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 }