Commit 97776caf authored by David Arinzon's avatar David Arinzon Committed by Jakub Kicinski
Browse files

net: ena: Changes around strscpy calls



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: default avatarDavid Arinzon <darinzon@amazon.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240512134637.25299-5-darinzon@amazon.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent b37b98a3
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -460,10 +460,18 @@ static void ena_get_drvinfo(struct net_device *dev,
			    struct ethtool_drvinfo *info)
{
	struct ena_adapter *adapter = netdev_priv(dev);
	ssize_t ret = 0;

	strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
	strscpy(info->bus_info, pci_name(adapter->pdev),
	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,
+13 −4
Original line number Diff line number Diff line
@@ -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,
	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) |