nvme: Removing deprecated strncpy()
Subsystems (2)
PATCH 1/1 nvme: Removing deprecated strncpy()
This patch suggests the replacement of strncpy with strscpy
as per Documentation/process/deprecated.
The strncpy() fails to guarantee NULL termination,
The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy() is a preferred replacement because
it overcomes the limitations of strncpy mentioned above.
Compile Tested
--- drivers/nvme/target/discovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/discovery.c +1 -1
@@ -119,7 +119,7 @@ static void nvmet_format_discovery_entry(struct nvmf_disc_rsp_page_hdr *hdr,memcpy (e->trsvcid, port->disc_addr.trsvcid,NVMF_TRSVCID_SIZE );memcpy (e->traddr, traddr,NVMF_TRADDR_SIZE );memcpy (e->tsas.common, port->disc_addr.tsas.common,NVMF_TSAS_SIZE ); -strncpy (e->subnqn, subsys_nqn,NVMF_NQN_SIZE ); +strscpy (e->subnqn, subsys_nqn,NVMF_NQN_SIZE ); }/*
Signature · 1 line
2.39.5
Quoted 9 lines · Kevin Paul Reddy Janagari
This patch suggests the replacement of strncpy with strscpy
as perDocumentation/process/deprecated.
Thestrncpy()fails to guarantee NULL termination,
The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy()is a preferred replacement because
it overcomes the limitations of strncpy mentioned above.
This patch was posted to the mailing list earlier:
https://lists.infradead.org/pipermail/linux-nvme/2025-April/055004.html
Best,
Caleb