drivers/nvme/target/discovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
---
drivers/nvme/target/discovery.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/target/discovery.c b/drivers/nvme/target/discovery.c
index df7207640506..c06f3e04296c 100644
--- a/drivers/nvme/target/discovery.c
+++ b/drivers/nvme/target/discovery.c
@@ -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);
}
/*
--
2.39.5
On Mon, Apr 14, 2025 at 5:37 PM Kevin Paul Reddy Janagari <kevinpaul468@gmail.com> wrote: > > 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. This patch was posted to the mailing list earlier: https://lists.infradead.org/pipermail/linux-nvme/2025-April/055004.html Best, Caleb
© 2016 - 2025 Red Hat, Inc.