[PATCH] net/smc: replace strncpy with strscpy for ib_name

Kriish Sharma posted 1 patch 1 day, 3 hours ago
net/smc/smc_pnet.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] net/smc: replace strncpy with strscpy for ib_name
Posted by Kriish Sharma 1 day, 3 hours ago
Replace the deprecated strncpy() with strscpy() for ib_name in
smc_pnet_add_ib(). The destination buffer should be NUL-terminated and
does not require any trailing NUL-padding. Since ib_name is a fixed-size
array, the two-argument form of strscpy() is sufficient and preferred.

Signed-off-by: Kriish Sharma <kriish.sharma2006@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 76ad29e31d60..b90337f86e83 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
 		return -ENOMEM;
 	new_pe->type = SMC_PNET_IB;
 	memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
-	strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
+	strscpy(new_pe->ib_name, ib_name);
 	new_pe->ib_port = ib_port;
 
 	new_ibdev = true;
-- 
2.34.1
Re: [PATCH] net/smc: replace strncpy with strscpy for ib_name
Posted by Dust Li 18 hours ago
On 2025-09-08 18:09:13, Kriish Sharma wrote:
>Replace the deprecated strncpy() with strscpy() for ib_name in
>smc_pnet_add_ib(). The destination buffer should be NUL-terminated and
>does not require any trailing NUL-padding. Since ib_name is a fixed-size
>array, the two-argument form of strscpy() is sufficient and preferred.
>
>Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>

I think d250f14f5f0754ce2d05d9c0ce778e4a51f488b0 has already done the
same thing.

Best regards,
Dust


>---
> 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 76ad29e31d60..b90337f86e83 100644
>--- a/net/smc/smc_pnet.c
>+++ b/net/smc/smc_pnet.c
>@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> 		return -ENOMEM;
> 	new_pe->type = SMC_PNET_IB;
> 	memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
>-	strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
>+	strscpy(new_pe->ib_name, ib_name);
> 	new_pe->ib_port = ib_port;
> 
> 	new_ibdev = true;
>-- 
>2.34.1