[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e4b30be3891cf6e615c5079e7330c10f433520f9.camel@perches.com>
Date: Tue, 23 Sep 2025 10:57:59 -0700
From: Joe Perches <joe@...ches.com>
To: Suchit Karunakaran <suchitkarunakaran@...il.com>, apw@...onical.com,
dwaipayanray1@...il.com, lukas.bulwahn@...il.com, Andrew Morton
<akpm@...ux-foundation.org>
Cc: skhan@...uxfoundation.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 RESEND] checkpatch: suppress strscpy warnings for
userspace tools
On Tue, 2025-09-23 at 22:47 +0530, Suchit Karunakaran wrote:
> 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/.
>
> Signed-off-by: Suchit Karunakaran <suchitkarunakaran@...il.com>
Acked-by: Joe Perches <joe@...ches.com>
> ---
>
> Changes since v1:
> - Create is_userspace function to check if the file is in userspace
> directories
>
> Changes since v2:
> - Change regex pattern to match top level directories only
>
> scripts/checkpatch.pl | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e722dd6fa8ef..fe580b0810f9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2636,6 +2636,11 @@ sub exclude_global_initialisers {
> $realfile =~ m@...f/.*\.bpf\.c$@;
> }
>
> +sub is_userspace {
> + my ($realfile) = @_;
> + return ($realfile =~ m@...ols/@ || $realfile =~ m@...ripts/@);
> +}
> +
> sub process {
> my $filename = shift;
>
> @@ -7018,21 +7023,20 @@ sub process {
> # }
> # }
> # }
> -
> # strcpy uses that should likely be strscpy
> - if ($line =~ /\bstrcpy\s*\(/) {
> + if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) {
> WARN("STRCPY",
> "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
> }
>
> # strlcpy uses that should likely be strscpy
> - if ($line =~ /\bstrlcpy\s*\(/) {
> + if ($line =~ /\bstrlcpy\s*\(/ && !is_userspace($realfile)) {
> WARN("STRLCPY",
> "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
> }
>
> # strncpy uses that should likely be strscpy or strscpy_pad
> - if ($line =~ /\bstrncpy\s*\(/) {
> + if ($line =~ /\bstrncpy\s*\(/ && !is_userspace($realfile)) {
> WARN("STRNCPY",
> "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
> }
Powered by blists - more mailing lists