netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] ethtool: use strscpy() to instead of strncpy()
@ 2022-12-08 11:47 yang.yang29
  2022-12-08 13:18 ` Michal Kubecek
  2022-12-09  2:23 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: yang.yang29 @ 2022-12-08 11:47 UTC (permalink / raw)
  To: salil.mehta
  Cc: yisen.zhuang, davem, edumazet, kuba, pabeni, brianvv, netdev,
	linux-kernel, xu.panda, yang.yang29

From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 54faf0f2d1d8..b54f3706fb97 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -644,18 +644,15 @@ static void hns_nic_get_drvinfo(struct net_device *net_dev,
 {
 	struct hns_nic_priv *priv = netdev_priv(net_dev);

-	strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
+	strscpy(drvinfo->version, HNAE_DRIVER_VERSION,
 		sizeof(drvinfo->version));
-	drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';

-	strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
-	drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
+	strscpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));

-	strncpy(drvinfo->bus_info, priv->dev->bus->name,
+	strscpy(drvinfo->bus_info, priv->dev->bus->name,
 		sizeof(drvinfo->bus_info));
-	drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';

-	strncpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
+	strscpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
 	drvinfo->eedump_len = 0;
 }

-- 
2.15.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH linux-next] ethtool: use strscpy() to instead of strncpy()
  2022-12-08 11:47 [PATCH linux-next] ethtool: use strscpy() to instead of strncpy() yang.yang29
@ 2022-12-08 13:18 ` Michal Kubecek
  2022-12-09  2:23 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Kubecek @ 2022-12-08 13:18 UTC (permalink / raw)
  To: yang.yang29
  Cc: salil.mehta, yisen.zhuang, davem, edumazet, kuba, pabeni, brianvv,
	netdev, linux-kernel, xu.panda

[-- Attachment #1: Type: text/plain, Size: 1817 bytes --]

On Thu, Dec 08, 2022 at 07:47:41PM +0800, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
> 
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>

The patch looks good to me but the subject prefix should rather be
"hns:" to reflect its target code.

Michal

> ---
>  drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> index 54faf0f2d1d8..b54f3706fb97 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> @@ -644,18 +644,15 @@ static void hns_nic_get_drvinfo(struct net_device *net_dev,
>  {
>  	struct hns_nic_priv *priv = netdev_priv(net_dev);
> 
> -	strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
> +	strscpy(drvinfo->version, HNAE_DRIVER_VERSION,
>  		sizeof(drvinfo->version));
> -	drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
> 
> -	strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
> -	drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
> +	strscpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
> 
> -	strncpy(drvinfo->bus_info, priv->dev->bus->name,
> +	strscpy(drvinfo->bus_info, priv->dev->bus->name,
>  		sizeof(drvinfo->bus_info));
> -	drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
> 
> -	strncpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
> +	strscpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
>  	drvinfo->eedump_len = 0;
>  }
> 
> -- 
> 2.15.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH linux-next] ethtool: use strscpy() to instead of strncpy()
  2022-12-08 11:47 [PATCH linux-next] ethtool: use strscpy() to instead of strncpy() yang.yang29
  2022-12-08 13:18 ` Michal Kubecek
@ 2022-12-09  2:23 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2022-12-09  2:23 UTC (permalink / raw)
  To: yang.yang29
  Cc: salil.mehta, yisen.zhuang, davem, edumazet, pabeni, brianvv,
	netdev, linux-kernel, xu.panda

On Thu, 8 Dec 2022 19:47:41 +0800 (CST) yang.yang29@zte.com.cn wrote:
> Subject: [PATCH linux-next] ethtool: use strscpy() to instead of strncpy()

Also net-next, linux-next is an integration tree, not a development
tree. It does not accept patches.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-09  2:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 11:47 [PATCH linux-next] ethtool: use strscpy() to instead of strncpy() yang.yang29
2022-12-08 13:18 ` Michal Kubecek
2022-12-09  2:23 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).