[PATCH v2] nvmet: replace strncpy with strscpy

Chaitanya Kulkarni chaitanyak at nvidia.com
Tue Apr 8 14:24:30 PDT 2025


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

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch at nvidia.com>

-ck




More information about the Linux-nvme mailing list