Suggested by devtools/cocci/strlcpy-with-header.cocci

Signed-off-by: Stephen Hemminger <step...@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(-)

diff --git a/drivers/net/hinic/base/hinic_compat.h 
b/drivers/net/hinic/base/hinic_compat.h
index aea332046ede..e8d0badb792a 100644
--- a/drivers/net/hinic/base/hinic_compat.h
+++ b/drivers/net/hinic/base/hinic_compat.h
@@ -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;
diff --git a/drivers/net/hinic/base/hinic_pmd_niccfg.c 
b/drivers/net/hinic/base/hinic_pmd_niccfg.c
index 8c08d63286df..eb127a308a0b 100644
--- a/drivers/net/hinic/base/hinic_pmd_niccfg.c
+++ b/drivers/net/hinic/base/hinic_pmd_niccfg.c
@@ -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;
 }
-
-
diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c 
b/drivers/net/hinic/hinic_pmd_ethdev.c
index 7aa5e7d8e929..bb4d5a3f0f85 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.c
+++ b/drivers/net/hinic/hinic_pmd_ethdev.c
@@ -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++;
        }
 
-- 
2.39.2

Reply via email to