Suggested by devtools/cocci/strlcpy-with-header.cocci
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/hinic/base/hinic_compat.h | 1 +
drivers/net/hinic/base/hinic_pmd_niccfg.c | 4 +---
drivers/net/hinic/hinic_pmd_ethdev.c | 14 +++++++-------
3 files changed, 9 insertions(+), 10 deletions(-)
@@ -19,6 +19,7 @@
#include <rte_spinlock.h>
#include <rte_cycles.h>
#include <rte_log.h>
+#include <rte_string_fns.h>
typedef uint8_t u8;
typedef int8_t s8;
@@ -1337,7 +1337,7 @@ int hinic_get_mgmt_version(void *hwdev, char *fw)
return -EIO;
}
- snprintf(fw, HINIC_MGMT_VERSION_MAX_LEN, "%s", fw_ver.ver);
+ strlcpy(fw, (const char *)fw_ver.ver, HINIC_MGMT_VERSION_MAX_LEN);
return 0;
}
@@ -2115,5 +2115,3 @@ int hinic_set_fdir_tcam_rule_filter(void *hwdev, bool enable)
return err;
}
-
-
@@ -786,7 +786,7 @@ static int hinic_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
if (fw_size < strlen(fw_ver) + 1)
return (strlen(fw_ver) + 1);
- snprintf(fw_version, fw_size, "%s", fw_ver);
+ strlcpy(fw_version, fw_ver, fw_size);
return 0;
}
@@ -2302,9 +2302,9 @@ static int hinic_dev_xstats_get_names(struct rte_eth_dev *dev,
/* get vport stats */
for (i = 0; i < HINIC_VPORT_XSTATS_NUM; i++) {
- snprintf(xstats_names[count].name,
- sizeof(xstats_names[count].name),
- "%s", hinic_vport_stats_strings[i].name);
+ strlcpy(xstats_names[count].name,
+ hinic_vport_stats_strings[i].name,
+ sizeof(xstats_names[count].name));
count++;
}
@@ -2313,9 +2313,9 @@ static int hinic_dev_xstats_get_names(struct rte_eth_dev *dev,
/* get phy port stats */
for (i = 0; i < HINIC_PHYPORT_XSTATS_NUM; i++) {
- snprintf(xstats_names[count].name,
- sizeof(xstats_names[count].name),
- "%s", hinic_phyport_stats_strings[i].name);
+ strlcpy(xstats_names[count].name,
+ hinic_phyport_stats_strings[i].name,
+ sizeof(xstats_names[count].name));
count++;
}