From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: Marcelo Moreira <marcelomoreira1905@gmail.com>,
"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
"hch@lst.de" <hch@lst.de>, "sagi@grimberg.me" <sagi@grimberg.me>,
Chaitanya Kulkarni <chaitanyak@nvidia.com>,
"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
"linux-kernel-mentees@lists.linuxfoundation.org"
<linux-kernel-mentees@lists.linuxfoundation.org>,
"~lkcamp/patches@lists.sr.ht" <~lkcamp/patches@lists.sr.ht>
Subject: Re: [PATCH v2] nvmet: replace strncpy with strscpy
Date: Tue, 8 Apr 2025 21:24:30 +0000 [thread overview]
Message-ID: <5ee4b3ef-c3cb-43f8-846e-195597f32637@nvidia.com> (raw)
In-Reply-To: <20250403232432.25255-1-marcelomoreira1905@gmail.com>
On 4/3/25 16:23, Marcelo Moreira wrote:
> The strncpy() function is deprecated for NUL-terminated strings as explained in
> the "strncpy() on NUL-terminated strings" section of
> Documentation/process/deprecated.rst. The key issues are:
> - strncpy() fails to guarantee NULL-termination when source > destination.
> - It unnecessarily zero-pads short strings, causing performance overhead.
>
> strscpy() is the proper replacement because:
> - Guarantees NULL-termination.
> - Avoids redundant zero-padding.
> - Aligns with current kernel string-copying best practice.
>
> memcpy() was rejected because:
> - NQN buffers (subsysnqn/hostnqn) are treated as NULL-terminated strings:
> - strcmp() usage in nvmet_host_allowed() (discovery.c)
> - strscpy() to copy subsysnqn in nvmet_execute_disc_identify()
>
> seq_buf wasn't used because:
> - This is a simple fixed-size buffer copy.
> - No need for progressive string construction features.
>
> Signed-off-by: Marcelo Moreira<marcelomoreira1905@gmail.com>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
next prev parent reply other threads:[~2025-04-08 21:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 23:23 [PATCH v2] nvmet: replace strncpy with strscpy Marcelo Moreira
2025-04-08 21:24 ` Chaitanya Kulkarni [this message]
2025-04-13 22:11 ` Sagi Grimberg
2025-04-22 7:58 ` Christoph Hellwig
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=5ee4b3ef-c3cb-43f8-846e-195597f32637@nvidia.com \
--to=chaitanyak@nvidia.com \
--cc=hch@lst.de \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-nvme@lists.infradead.org \
--cc=marcelomoreira1905@gmail.com \
--cc=sagi@grimberg.me \
--cc=skhan@linuxfoundation.org \
--cc=~lkcamp/patches@lists.sr.ht \
/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