Skip to content

Commit

Permalink
hns: use strscpy() to instead of strncpy()
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Xu Panda authored and David S. Miller committed Dec 12, 2022
1 parent 6d534ee commit 94d30e8
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 94d30e8

Please sign in to comment.