From: Simon Horman <horms@kernel.org>
To: Pranav Tyagi <pranav.tyagi03@gmail.com>
Cc: wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
alibuda@linux.alibaba.com, tonylu@linux.alibaba.com,
guwen@linux.alibaba.com, skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] net/smc: replace strncpy with strscpy
Date: Wed, 18 Jun 2025 11:50:39 +0100 [thread overview]
Message-ID: <20250618105039.GE1699@horms.kernel.org> (raw)
In-Reply-To: <20250617122512.21979-1-pranav.tyagi03@gmail.com>
On Tue, Jun 17, 2025 at 05:55:12PM +0530, Pranav Tyagi wrote:
> Replace the deprecated strncpy() with strscpy() as the destination
> buffer should be NUL-terminated and does not require any trailing
> NUL-padding.
>
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> ---
> net/smc/smc_pnet.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
> index b391c2ef463f..b70e1f3179c5 100644
> --- a/net/smc/smc_pnet.c
> +++ b/net/smc/smc_pnet.c
> @@ -370,7 +370,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
> goto out_put;
> new_pe->type = SMC_PNET_ETH;
> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
> - strncpy(new_pe->eth_name, eth_name, IFNAMSIZ);
> + strscpy(new_pe->eth_name, eth_name, IFNAMSIZ);
Hi Pranav,
I think that because strscpy always results in a NULL terminated string
the length argument can be increased by one to IFNAMSIZ + 1, matching
the size of the destination.
But I also think that we can handle this automatically by switching
to the two-argument version of strscpy() because the destination is an
array.
strscpy(new_pe->eth_name, eth_name);
> rc = -EEXIST;
> new_netdev = true;
> mutex_lock(&pnettable->lock);
> --
> 2.49.0
>
--
pw-bot: changes-requested
next prev parent reply other threads:[~2025-06-18 10:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 12:25 [PATCH] net/smc: replace strncpy with strscpy Pranav Tyagi
2025-06-18 10:50 ` Simon Horman [this message]
2025-06-18 14:32 ` Pranav Tyagi
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=20250618105039.GE1699@horms.kernel.org \
--to=horms@kernel.org \
--cc=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=guwen@linux.alibaba.com \
--cc=jaka@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pranav.tyagi03@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=tonylu@linux.alibaba.com \
--cc=wenjia@linux.ibm.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