Skip to content

Commit

Permalink
net: ena: Changes around strscpy calls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Arinzon authored and Jakub Kicinski committed May 13, 2024
1 parent b37b98a commit 97776ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
16 changes: 12 additions & 4 deletions drivers/net/ethernet/amazon/ena/ena_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions drivers/net/ethernet/amazon/ena/ena_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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) |
Expand Down

0 comments on commit 97776ca

Please sign in to comment.