Messages in this thread Patch in this message | | | From | Dominique Martinet <> | Subject | [PATCH 07/18] hisilicon: change strncpy+truncation to strlcpy | Date | Fri, 13 Jul 2018 03:25:39 +0200 |
| |
Generated by scripts/coccinelle/misc/strncpy_truncation.cocci
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org> ---
Please see https://marc.info/?l=linux-kernel&m=153144450722324&w=2 (the first patch of the serie) for the motivation behind this patch
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 7 ++----- drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index 2e14a3ae1d8b..35b4d72d1997 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -638,12 +638,9 @@ 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, + strlcpy(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'; + strlcpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver)); strncpy(drvinfo->bus_info, priv->dev->bus->name, sizeof(drvinfo->bus_info)); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c index 40c0425b4023..630c8d186707 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -493,13 +493,10 @@ static void hns3_get_drvinfo(struct net_device *netdev, struct hns3_nic_priv *priv = netdev_priv(netdev); struct hnae3_handle *h = priv->ae_handle; - strncpy(drvinfo->version, hns3_driver_version, + strlcpy(drvinfo->version, hns3_driver_version, sizeof(drvinfo->version)); - drvinfo->version[sizeof(drvinfo->version) - 1] = '\0'; - - strncpy(drvinfo->driver, h->pdev->driver->name, + strlcpy(drvinfo->driver, h->pdev->driver->name, sizeof(drvinfo->driver)); - drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0'; strncpy(drvinfo->bus_info, pci_name(h->pdev), sizeof(drvinfo->bus_info)); -- 2.17.1
| |