hns: use strscpy() to instead of strncpy()
Subsystems (3)
PATCH v2 1/1 hns: use strscpy() to instead of strncpy()
From: Xu Panda <[email protected]>
The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.
---
change for v2
- change the prefix and subject: replace ethtool with hns,
and replace linux-next with net-next.
--- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +4 -7
@@ -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 ; }
Signature · 1 line
2.15.2
Quoted 7 lines · Fri, Dec 09, 2022 at 08:33:25AM CET, [email protected] wrote:
From: Xu Panda <[email protected]>
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 <[email protected]>Signed-off-by Yang Yang <[email protected]>
Quoted 32 lines · On 2022/12/9 15:33, [email protected] wrote:
From: Xu Panda <[email protected]>
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 <[email protected]>Signed-off-by Yang Yang <[email protected]>---
change for v2
- change the prefix and subject: replace ethtool with hns,
and replace linux-next with net-next.--- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +2
-4@@ -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));
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c static void hns_nic_get_drvinfo(struct net_device *net_dev, · line 658
Quoted 10 lines
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +2
-3-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 ; }