Fixes a few different things:
* Remove 'fw_version' NULL checks, it is allowed if the 'fw_size' is
zero, 'fw_version' being NULL but 'fw_size' not zero condition checked
in ethdev layer
* Be sure required buffer size is returned if provided one is not big
enough, instead of returning success (0)
* Document in doxygen comment the '-EINVAL' is a valid return type
* Take into account that 'snprintf' can return negative value
* Cast length to 'size_t' to compare it with 'fw_size'
Fixes:
bb42aa9ffe4e ("net/atlantic: configure device start/stop")
Fixes:
ff70acdf4299 ("net/axgbe: support reading FW version")
Fixes:
e2652b0a20a0 ("net/bnxt: support get FW version")
Fixes:
cf0fab1d2ca5 ("net/dpaa: support firmware version get API")
Fixes:
748eccb97cdc ("net/dpaa2: add support for firmware version get")
Fixes:
b883c0644a24 ("net/e1000: add firmware version get")
Fixes:
293430677e9c ("net/enic: add handler to return firmware version")
Fixes:
1f5ca0b460cd ("net/hns3: support some device operations")
Fixes:
bd5b86732bc7 ("net/hns3: modify format for firmware version")
Fixes:
ed0dfdd0e976 ("net/i40e: add firmware version get")
Fixes:
e31cb9a36298 ("net/ice: support FW version getting")
Fixes:
4f09bc55ac3d ("net/igc: implement device base operations")
Fixes:
eec10fb0ce6b ("net/ionic: support FW version")
Fixes:
8b0b56574269 ("net/ixgbe: add firmware version get")
Fixes:
4d9f5b8adc02 ("net/octeontx2: add FW version get operation")
Fixes:
f97b56f9f12e ("net/qede: support FW version query")
Fixes:
83fef46a22b2 ("net/sfc: add callback to retrieve FW version")
Fixes:
bc84ac0fadef ("net/txgbe: support getting FW version")
Fixes:
21913471202f ("ethdev: add firmware version get")
Cc: stable@dpdk.org
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Haiyue Wang <haiyue.wang@intel.com>
Acked-by: Rasesh Mody <rmody@marvell.com>
Acked-by: Jiawen Wu <jiawenwu@trustnetic.com>
Acked-by: Beilei Xing <beilei.xing@intel.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
{
struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
uint32_t fw_ver = 0;
- unsigned int ret = 0;
+ int ret = 0;
ret = hw_atl_utils_get_fw_version(hw, &fw_ver);
if (ret)
ret = snprintf(fw_version, fw_size, "%u.%u.%u", fw_ver >> 24,
(fw_ver >> 16) & 0xFFU, fw_ver & 0xFFFFU);
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add string null-terminator */
-
- if (fw_size < ret)
+ if (fw_size < (size_t)ret)
return ret;
return 0;
pdata = (struct axgbe_port *)eth_dev->data->dev_private;
hw_feat = &pdata->hw_feat;
- if (fw_version == NULL)
- return -EINVAL;
-
ret = snprintf(fw_version, fw_size, "%d.%d.%d",
AXGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
AXGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
return -EINVAL;
ret += 1; /* add the size of '\0' */
-
if (fw_size < (size_t)ret)
return ret;
else
ret = snprintf(fw_version, fw_size, "%d.%d.%d.%d",
fw_major, fw_minor, fw_updt, fw_rsvd);
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (uint32_t)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
ret = snprintf(fw_version, fw_size, "SVR:%x-fman-v%x",
svr_ver, fman_ip_rev);
- ret += 1; /* add the size of '\0' */
+ if (ret < 0)
+ return -EINVAL;
- if (fw_size < (uint32_t)ret)
+ ret += 1; /* add the size of '\0' */
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
mc_ver_info.major,
mc_ver_info.minor,
mc_ver_info.revision);
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (uint32_t)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
}
break;
}
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (u32)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
int ret;
ENICPMD_FUNC_TRACE();
- if (fw_version == NULL || fw_size <= 0)
- return -EINVAL;
+
enic = pmd_priv(eth_dev);
ret = vnic_dev_fw_info(enic->vdev, &info);
if (ret)
return ret;
- snprintf(fw_version, fw_size, "%s %s",
+ ret = snprintf(fw_version, fw_size, "%s %s",
info->fw_version, info->fw_build);
- fw_version[fw_size - 1] = '\0';
- return 0;
+ if (ret < 0)
+ return -EINVAL;
+
+ ret += 1; /* add the size of '\0' */
+ if (fw_size < (size_t)ret)
+ return ret;
+ else
+ return 0;
}
static const struct eth_dev_ops enicpmd_eth_dev_ops = {
HNS3_FW_VERSION_BYTE1_S),
hns3_get_field(version, HNS3_FW_VERSION_BYTE0_M,
HNS3_FW_VERSION_BYTE0_S));
+ if (ret < 0)
+ return -EINVAL;
+
ret += 1; /* add the size of '\0' */
- if (fw_size < (uint32_t)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
HNS3_FW_VERSION_BYTE1_S),
hns3_get_field(version, HNS3_FW_VERSION_BYTE0_M,
HNS3_FW_VERSION_BYTE0_S));
+ if (ret < 0)
+ return -EINVAL;
+
ret += 1; /* add the size of '\0' */
- if (fw_size < (uint32_t)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
((hw->nvm.version >> 4) & 0xff),
(hw->nvm.version & 0xf), hw->nvm.eetrack,
ver, build, patch);
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (u32)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
hw->flash.nvm.minor,
hw->flash.nvm.eetrack,
ver, build, patch);
+ if (ret < 0)
+ return -EINVAL;
/* add the size of '\0' */
ret += 1;
- if (fw_size < (u32)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
fw.eep_build);
}
}
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (u32)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
{
struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
struct ionic_adapter *adapter = lif->adapter;
+ int ret;
- if (fw_version == NULL || fw_size <= 0)
- return -EINVAL;
-
- snprintf(fw_version, fw_size, "%s",
+ ret = snprintf(fw_version, fw_size, "%s",
adapter->fw_version);
- fw_version[fw_size - 1] = '\0';
+ if (ret < 0)
+ return -EINVAL;
- return 0;
+ ret += 1; /* add the size of '\0' */
+ if (fw_size < (size_t)ret)
+ return ret;
+ else
+ return 0;
}
/*
etrack_id = (eeprom_verh << 16) | eeprom_verl;
ret = snprintf(fw_version, fw_size, "0x%08x", etrack_id);
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (u32)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;
rc = strlcpy(fw_version, (char *)dev->mkex_pfl_name, rc);
rc += 1; /* Add the size of '\0' */
- if (fw_size < (uint32_t)rc)
+ if (fw_size < (size_t)rc)
return rc;
return 0;
static char ver_str[QEDE_PMD_DRV_VER_STR_SIZE];
size_t size;
- if (fw_ver == NULL)
- return 0;
-
if (IS_PF(edev))
snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%s",
QEDE_PMD_FW_VERSION);
int ret;
int rc;
- /*
- * Return value of the callback is likely supposed to be
- * equal to or greater than 0, nevertheless, if an error
- * occurs, it will be desirable to pass it to the caller
- */
- if ((fw_version == NULL) || (fw_size == 0))
- return -EINVAL;
-
rc = efx_nic_get_fw_version(sa->nic, &enfi);
if (rc != 0)
return -rc;
hw->phy.get_fw_version(hw, &etrack_id);
ret = snprintf(fw_version, fw_size, "0x%08x", etrack_id);
+ if (ret < 0)
+ return -EINVAL;
ret += 1; /* add the size of '\0' */
- if (fw_size < (u32)ret)
+ if (fw_size < (size_t)ret)
return ret;
else
return 0;