net: ena: Changes around strscpy calls
authorDavid Arinzon <darinzon@amazon.com>
Sun, 12 May 2024 13:46:36 +0000 (13:46 +0000)
committerJakub Kicinski <kuba@kernel.org>
Mon, 13 May 2024 21:42:04 +0000 (14:42 -0700)
strscpy copies as much of the string as possible,
meaning that the destination string will be truncated
in case of no space. As this is a non-critical error in
our case, adding a debug level print for indication.

This patch also removes a -1 which was added to ensure
enough space for NUL, but strscpy destination string is
guaranteed to be NUL-terminted, therefore, the -1 is
not needed.

Signed-off-by: David Arinzon <darinzon@amazon.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240512134637.25299-5-darinzon@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/amazon/ena/ena_ethtool.c
drivers/net/ethernet/amazon/ena/ena_netdev.c

index 28583db848e2239d041e21c386a97829c7427f2e..b24cc3f0524850b4efd5bc5075cbc8bf60318d76 100644 (file)
@@ -460,10 +460,18 @@ static void ena_get_drvinfo(struct net_device *dev,
                            struct ethtool_drvinfo *info)
 {
        struct ena_adapter *adapter = netdev_priv(dev);
-
-       strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
-       strscpy(info->bus_info, pci_name(adapter->pdev),
-               sizeof(info->bus_info));
+       ssize_t ret = 0;
+
+       ret = strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
+       if (ret < 0)
+               netif_dbg(adapter, drv, dev,
+                         "module name will be truncated, status = %zd\n", ret);
+
+       ret = strscpy(info->bus_info, pci_name(adapter->pdev),
+                     sizeof(info->bus_info));
+       if (ret < 0)
+               netif_dbg(adapter, drv, dev,
+                         "bus info will be truncated, status = %zd\n", ret);
 }
 
 static void ena_get_ringparam(struct net_device *netdev,
index 7398bc615866c4c601bf102b7b47e5358ccea2f7..184b6e6cbed457f79afc0216cc87cc3de0bb2644 100644 (file)
@@ -2703,6 +2703,7 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pd
 {
        struct device *dev = &pdev->dev;
        struct ena_admin_host_info *host_info;
+       ssize_t ret;
        int rc;
 
        /* Allocate only the host info */
@@ -2717,11 +2718,19 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pd
        host_info->bdf = pci_dev_id(pdev);
        host_info->os_type = ENA_ADMIN_OS_LINUX;
        host_info->kernel_ver = LINUX_VERSION_CODE;
-       strscpy(host_info->kernel_ver_str, utsname()->version,
-               sizeof(host_info->kernel_ver_str) - 1);
+       ret = strscpy(host_info->kernel_ver_str, utsname()->version,
+                     sizeof(host_info->kernel_ver_str));
+       if (ret < 0)
+               dev_dbg(dev,
+                       "kernel version string will be truncated, status = %zd\n", ret);
+
        host_info->os_dist = 0;
-       strscpy(host_info->os_dist_str, utsname()->release,
-               sizeof(host_info->os_dist_str));
+       ret = strscpy(host_info->os_dist_str, utsname()->release,
+                     sizeof(host_info->os_dist_str));
+       if (ret < 0)
+               dev_dbg(dev,
+                       "OS distribution string will be truncated, status = %zd\n", ret);
+
        host_info->driver_version =
                (DRV_MODULE_GEN_MAJOR) |
                (DRV_MODULE_GEN_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |