mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Suchit Karunakaran <suchitkarunakaran@gmail.com>,
	apw@canonical.com,  dwaipayanray1@gmail.com,
	lukas.bulwahn@gmail.com,
	Andrew Morton <akpm@linux-foundation.org>
Cc: skhan@linuxfoundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 RESEND] checkpatch: suppress strscpy warnings for userspace tools
Date: Tue, 23 Sep 2025 10:57:59 -0700	[thread overview]
Message-ID: <e4b30be3891cf6e615c5079e7330c10f433520f9.camel@perches.com> (raw)
In-Reply-To: <20250923171722.7798-1-suchitkarunakaran@gmail.com>

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@gmail.com>

Acked-by: Joe Perches <joe@perches.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@/bpf/.*\.bpf\.c$@;
>  }
>  
> +sub is_userspace {
> +    my ($realfile) = @_;
> +    return ($realfile =~ m@^tools/@ || $realfile =~ m@^scripts/@);
> +}
> +
>  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);
>  		}

  reply	other threads:[~2025-09-23 17:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 17:17 Suchit Karunakaran
2025-09-23 17:57 ` Joe Perches [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-09-09 16:56 Suchit Karunakaran
2025-08-25 14:10 Suchit Karunakaran
2025-08-15 18:04 Suchit Karunakaran
2025-08-04 18:08 Suchit Karunakaran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e4b30be3891cf6e615c5079e7330c10f433520f9.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=suchitkarunakaran@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®