net: hns3: use strscpy() to instead of strncpy()
authorXu Panda <xu.panda@zte.com.cn>
Fri, 9 Dec 2022 07:38:59 +0000 (15:38 +0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 12 Dec 2022 21:00:00 +0000 (13:00 -0800)
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>
Link: https://lore.kernel.org/r/202212091538591375035@zte.com.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

index cdf76fb58d45ed8364a79cd786a96e24bbc06783..55306fe8a5402d6227a85b9019275a5402ca90f1 100644 (file)
@@ -639,13 +639,11 @@ static void hns3_get_drvinfo(struct net_device *netdev,
                return;
        }
 
-       strncpy(drvinfo->driver, dev_driver_string(&h->pdev->dev),
+       strscpy(drvinfo->driver, dev_driver_string(&h->pdev->dev),
                sizeof(drvinfo->driver));
-       drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
 
-       strncpy(drvinfo->bus_info, pci_name(h->pdev),
+       strscpy(drvinfo->bus_info, pci_name(h->pdev),
                sizeof(drvinfo->bus_info));
-       drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
 
        fw_version = priv->ae_handle->ae_algo->ops->get_fw_version(h);