replace snprintf with strlcpy
Subsystems (3)
cover replace snprintf with strlcpy
This patch series was generated by using the existing Coccinelle script to find where snprintf() is used but strlcpy() could be used instead.
Manually replaced fixed some trigraphs and paren's where needed. Also one instance the whole temporary string copy was not needed at all.
Stephen Hemminger (25):
app: use strlcpy in tests
examples: use strlcpy instead of snprintf
lib: use strlcpy instead of snprintf raw/ifpga: replace snprintf with strlcpy common/cnxk: replace snprint with strlcpy common/mlx5: replace snprintf with strlcpy drivers/gpu: replace snprintf with strlcpy crypto/ipsec_mb: remove unnecessary snprintf crypto/dpaa_sec: replace snprintf with strlcpy event/cnxk: replace snprintf with strlcpy net/atlantic: replace snprintf with strlcpy net/axgbe: replace snprintf with strlcpy net/bnxt: replace snprintf with strlcpy net/cpfl: replace snprintf with strlcpy net/cxgbe: replace snprintf with strlcpy net/dpaa*: replace snprintf with strlcpy net/hinic: replace snptintf with strlcpy net/hns3: replace snprint with strlcpy net/intel: replace snprintf with strlcpy net/ionic: replace snprintf with strlcpy net/mlx5: replace snprintf with strlcpy net/nfp: replace snprintf with strlcpy net/ngbe: replace snprintf with strlcpy net/qede: replace snprintf with strlcpy net/txgbe: replace snprintf with strlcpy
app/test-bbdev/main.c | 5 ++-- app/test-pmd/cmdline_flow.c | 6 ++-- app/test/process.h | 2 +- app/test/test_graph_perf.c | 29 ++++++++++--------- drivers/common/cnxk/roc_nix_stats.c | 4 +-- drivers/common/mlx5/linux/mlx5_common_os.c | 2 +- drivers/common/mlx5/mlx5_common_utils.c | 5 ++-- drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- drivers/crypto/ipsec_mb/ipsec_mb_ops.c | 7 +---- drivers/event/cnxk/cnxk_eventdev_stats.c | 11 ++++--- drivers/gpu/cuda/cuda.c | 2 +- drivers/gpu/cuda/gdrcopy.c | 2 +- drivers/net/atlantic/atl_ethdev.c | 5 ++-- drivers/net/axgbe/axgbe_ethdev.c | 6 ++-- drivers/net/bnxt/bnxt_ethdev.c | 8 ++--- drivers/net/cpfl/cpfl_ethdev.c | 6 ++-- drivers/net/cxgbe/cxgbe_ethdev.c | 9 +++--- drivers/net/dpaa/dpaa_ethdev.c | 8 ++--- drivers/net/dpaa2/dpaa2_ethdev.c | 8 ++--- drivers/net/fm10k/fm10k_ethdev.c | 6 ++-- 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 ++++----- drivers/net/hns3/hns3_fdir.c | 2 +- drivers/net/hns3/hns3_rxtx.c | 8 ++--- drivers/net/hns3/hns3_stats.c | 22 +++++++------- drivers/net/i40e/i40e_rxtx.c | 8 ++--- drivers/net/iavf/iavf_ethdev.c | 6 ++-- drivers/net/ice/ice_dcf_ethdev.c | 6 ++-- drivers/net/ice/ice_rxtx.c | 8 ++--- drivers/net/idpf/idpf_ethdev.c | 6 ++-- drivers/net/ionic/ionic_ethdev.c | 15 +++++----- drivers/net/ipn3ke/ipn3ke_representor.c | 17 +++++------ drivers/net/mlx5/mlx5_rx.c | 16 +++++----- .../net/nfp/flower/nfp_flower_representor.c | 4 +-- drivers/net/ngbe/ngbe_rxtx.c | 8 ++--- drivers/net/qede/qede_ethdev.c | 10 +++---- drivers/net/txgbe/txgbe_ethdev_vf.c | 6 ++-- drivers/raw/ifpga/afu_pmd_core.c | 3 +- examples/fips_validation/fips_validation.c | 8 ++--- examples/l3fwd-graph/main.c | 2 +- examples/pipeline/cli.c | 2 +- examples/vhost_blk/vhost_blk.c | 5 ++-- lib/bbdev/rte_bbdev.c | 2 +- lib/ethdev/sff_8636.c | 11 ++++--- 45 files changed, 157 insertions(+), 170 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/25 app: use strlcpy in tests
Prefer using strlcpy over snprintf().
--- app/test-bbdev/main.c | 5 ++--- app/test-pmd/cmdline_flow.c | 6 +++--- app/test/process.h | 2 +- app/test/test_graph_perf.c | 29 ++++++++++++++++------------- 4 files changed, 22 insertions(+), 20 deletions(-)
app/test-bbdev/main.c +2 -3
@@ -251,9 +251,8 @@ parse_args(int argc, char **argv, struct test_params *tp)TEST_ASSERT (strlen (optarg) >0 ,"Config file name is null" ); -snprintf (tp->test_vector_filename, -sizeof (tp->test_vector_filename), -"%s" , optarg); +strlcpy (tp->test_vector_filename, optarg, +sizeof (tp->test_vector_filename));break ;case 's' : TEST_ASSERT(strlen(optarg) > 0,
app/test-pmd/cmdline_flow.c +3 -3
@@ -10028,7 +10028,7 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)char tmp[3 ], *end = tmp;uint32_t read_lim = left &1 ?1 :2 ; -snprintf (tmp, read_lim +1 ,"%s" , src); +strlcpy (tmp, src, read_lim +1 ); *dst =strtoul (tmp, &end,16 );if (*end) { *dst =0 ;
@@ -11404,7 +11404,7 @@ cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)if (!size)return -1 ;/* Set token type and update global help with details. */ -strlcpy (dst, (token->type ? token->type :"TOKEN" ), size); +strlcpy (dst, token->type ? :"TOKEN" , size);if (token->help) cmd_flow.help_str = token->help;else
@@ -12220,7 +12220,7 @@ cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,if (!size)return -1 ;/* Set token type and update global help with details. */ -snprintf (dst, size,"%s" , (token->type ? token->type :"TOKEN" )); +strlcpy (dst, token->type ? :"TOKEN" , size);if (token->help) cmd_set_raw.help_str = token->help;else
app/test/process.h +1 -1
@@ -176,7 +176,7 @@ get_current_prefix(char *prefix, int size)return NULL ;/* get the prefix */ -snprintf (prefix, size,"%s" ,basename (dirname (buf))); +strlcpy (prefix,basename (dirname (buf)), size);return prefix; }
app/test/test_graph_perf.c +16 -13
@@ -294,8 +294,9 @@ graph_node_count_edges(uint32_t stage, uint16_t node, uint16_t nodes_per_stage,for (i =0 ; i < nodes_per_stage && edges <MAX_EDGES_PER_NODE ; i++) {if (edge_map[stage +1 ][i][node]) { ename[edges] =malloc (sizeof (char ) *RTE_NODE_NAMESIZE ); -snprintf (ename[edges],RTE_NODE_NAMESIZE ,"%s" , -rte_node_id_to_name (node_map[stage +1 ][i])); +strlcpy (ename[edges], +rte_node_id_to_name (node_map[stage +1 ][i]), +RTE_NODE_NAMESIZE ); node_data->next_nodes[edges] = node_map[stage +1 ][i]; node_data->next_percentage[edges] = edge_map[stage +1 ][i][node];
@@ -405,9 +406,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, graph_data->nb_nodes++; goto pattern_name_free; } -snprintf (node_patterns[graph_data->nb_nodes], -RTE_NODE_NAMESIZE ,"%s" , -rte_node_id_to_name (node_map[i][j])); +strlcpy (node_patterns[graph_data->nb_nodes], +rte_node_id_to_name (node_map[i][j]), +RTE_NODE_NAMESIZE ); node_data = &graph_data->node_data[graph_data->nb_nodes]; node_data->node_id = node_map[i][j];
@@ -467,8 +468,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, graph_data->nb_nodes++; goto pattern_name_free; } -snprintf (node_patterns[graph_data->nb_nodes],RTE_NODE_NAMESIZE , -"%s" ,rte_node_id_to_name (src_nodes[i])); +strlcpy (node_patterns[graph_data->nb_nodes], +rte_node_id_to_name (src_nodes[i]),RTE_NODE_NAMESIZE ); node_data = &graph_data->node_data[graph_data->nb_nodes]; node_data->node_id = src_nodes[i]; node_data->is_sink = false;
@@ -479,8 +480,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,if (!src_map[i][j])continue ; ename[edges] =malloc (sizeof (char ) *RTE_NODE_NAMESIZE ); -snprintf (ename[edges],RTE_NODE_NAMESIZE ,"%s" , -rte_node_id_to_name (node_map[0 ][j])); +strlcpy (ename[edges], +rte_node_id_to_name (node_map[0 ][j]), +RTE_NODE_NAMESIZE ); node_data->next_nodes[edges] = node_map[0 ][j]; node_data->next_percentage[edges] = src_map[i][j]; edges++;
@@ -524,8 +526,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks, graph_data->nb_nodes++; goto pattern_name_free; } -snprintf (node_patterns[graph_data->nb_nodes],RTE_NODE_NAMESIZE , -"%s" ,rte_node_id_to_name (snk_nodes[i])); +strlcpy (node_patterns[graph_data->nb_nodes], +rte_node_id_to_name (snk_nodes[i]),RTE_NODE_NAMESIZE ); node_data = &graph_data->node_data[graph_data->nb_nodes]; node_data->node_id = snk_nodes[i]; node_data->is_sink = true;
@@ -543,8 +545,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,if (!snk_map[i][j])continue ; ename[edges] =malloc (sizeof (char ) *RTE_NODE_NAMESIZE ); -snprintf (ename[edges],RTE_NODE_NAMESIZE ,"%s" , -rte_node_id_to_name (snk_nodes[j])); +strlcpy (ename[edges], +rte_node_id_to_name (snk_nodes[j]), +RTE_NODE_NAMESIZE ); node_data->next_nodes[edges] = snk_nodes[j]; node_data->next_percentage[edges] = snk_map[i][j]; edges++;
Signature · 1 line
2.39.2
PATCH 2/25 examples: use strlcpy instead of snprintf
In reply to Stephen HemmingerReplace snprintf() with strlcpy() where possible.
--- examples/fips_validation/fips_validation.c | 8 ++++---- examples/l3fwd-graph/main.c | 2 +- examples/pipeline/cli.c | 2 +- examples/vhost_blk/vhost_blk.c | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-)
examples/fips_validation/fips_validation.c +4 -4
@@ -505,8 +505,8 @@ fips_test_parse_one_json_group(void)switch (json_typeof (param)) {case JSON_STRING : -snprintf (json_value,sizeof (json_value),"%s" , -json_string_value (param)); +strlcpy (json_value,json_string_value (param), +sizeof (json_value));break ;case JSON_INTEGER :
@@ -550,8 +550,8 @@ fips_test_parse_one_json_case(void)switch (json_typeof (param)) {case JSON_STRING : -snprintf (info.one_line_text,MAX_LINE_CHAR ,"%s" , -json_string_value (param)); +strlcpy (info.one_line_text,json_string_value (param), +MAX_LINE_CHAR );break ;case JSON_INTEGER :
examples/l3fwd-graph/main.c +1 -1
@@ -546,7 +546,7 @@ parse_args(int argc, char **argv)break ;case CMD_LINE_OPT_PCAP_FILENAME_CAP : -rte_strlcpy (pcap_filename, optarg, +strlcpy (pcap_filename, optarg,sizeof (pcap_filename));printf ("Pcap file name: %s\n" , pcap_filename);break ;
examples/pipeline/cli.c +1 -1
@@ -3164,7 +3164,7 @@ cmd_ipsec_sa_add(char **tokens, goto free; } -snprintf (out, out_size,"%s" , line); +strlcpy (out, line, out_size); out_size -=strlen (out); out +=strlen (out);
examples/vhost_blk/vhost_blk.c +2 -3
@@ -771,9 +771,8 @@ vhost_blk_bdev_construct(const char *bdev_name,if (!bdev)return NULL ; -snprintf (bdev->name,sizeof (bdev->name),"%s" , bdev_name); -snprintf (bdev->product_name,sizeof (bdev->product_name),"%s" , - bdev_serial); +strlcpy (bdev->name, bdev_name,sizeof (bdev->name)); +strlcpy (bdev->product_name, bdev_serial,sizeof (bdev->product_name)); bdev->blocklen = blk_size; bdev->blockcnt = blk_cnt; bdev->write_cache = wce_enable;
Signature · 1 line
2.39.2
PATCH 3/25 lib: use strlcpy instead of snprintf
In reply to Stephen HemmingerReplace snprintf with strlcpy where possible.
--- lib/bbdev/rte_bbdev.c | 2 +- lib/ethdev/sff_8636.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
lib/bbdev/rte_bbdev.c +1 -1
@@ -212,7 +212,7 @@ rte_bbdev_allocate(const char *name) bbdev->data->dev_id = dev_id; bbdev->state =RTE_BBDEV_INITIALIZED ; - ret =snprintf (bbdev->data->name,RTE_BBDEV_NAME_MAX_LEN ,"%s" , name); + ret =strlcpy (bbdev->data->name, name,RTE_BBDEV_NAME_MAX_LEN );if ((ret <0 ) || (ret >=RTE_BBDEV_NAME_MAX_LEN )) {rte_bbdev_log (ERR ,"Copying device name \"%s\" failed" , name);return NULL ;
lib/ethdev/sff_8636.c +7 -4
@@ -203,16 +203,19 @@ static void sff_8636_show_ext_identifier(const uint8_t *data, struct rte_tel_datswitch (data[SFF_8636_EXT_ID_OFFSET ] &SFF_8636_EXT_ID_EPWR_CLASS_MASK ) {case SFF_8636_EXT_ID_PWR_CLASS_LEGACY : -snprintf (val_string,sizeof (val_string),"%s" ,"" ); +strlcpy (val_string,"" ,sizeof (val_string));break ;case SFF_8636_EXT_ID_PWR_CLASS_5 : -snprintf (val_string,sizeof (val_string),"%s" ,"4.0W max. Power consumption, " ); +strlcpy (val_string,"4.0W max. Power consumption, " , +sizeof (val_string));break ;case SFF_8636_EXT_ID_PWR_CLASS_6 : -snprintf (val_string,sizeof (val_string),"%s" ,"4.5W max. Power consumption, " ); +strlcpy (val_string,"4.5W max. Power consumption, " , +sizeof (val_string));break ;case SFF_8636_EXT_ID_PWR_CLASS_7 : -snprintf (val_string,sizeof (val_string),"%s" ,"5.0W max. Power consumption, " ); +strlcpy (val_string,"5.0W max. Power consumption, " , +sizeof (val_string));break ; }
Signature · 1 line
2.39.2
PATCH 4/25 raw/ifpga: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/raw/ifpga/afu_pmd_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/raw/ifpga/afu_pmd_core.c +2 -1
@@ -16,6 +16,7 @@#include <rte_malloc.h> #include <rte_memzone.h> #include <rte_rawdev_pmd.h> +#include <rte_string_fns.h> #include "afu_pmd_core.h"
@@ -225,7 +226,7 @@ static int afu_shared_data_alloc(const char *name,return -EINVAL ;/* name format is afu_?|??:??.? which is unique */ -snprintf (mz_name,sizeof (mz_name),"%s" , name); +strlcpy (mz_name, name,sizeof (mz_name)); mz =rte_memzone_lookup (mz_name);if (!mz) {
Signature · 1 line
2.39.2
PATCH 5/25 common/cnxk: replace snprint with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/common/cnxk/roc_nix_stats.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/common/cnxk/roc_nix_stats.c +1 -3
@@ -16,9 +16,7 @@#define NIX_XSTATS_NAME_PRINT (xstats_names, count, xstats, index) \ do { \ if (xstats_names) \ - snprintf(xstats_names[count].name, \ - sizeof(xstats_names[count].name), "%s", \ - xstats[index].name); \ + strlcpy(xstats_names[count].name, xstats[index].name, sizeof(xstats_names[count].name)); \ } while (0)int
Signature · 1 line
2.39.2
PATCH 6/25 common/mlx5: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/common/mlx5/linux/mlx5_common_os.c | 2 +- drivers/common/mlx5/mlx5_common_utils.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.c +1 -1
@@ -897,7 +897,7 @@ mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len) } }while (strchr (ptr->d_name,'.' ) ||strchr (ptr->d_name,'_' ) ||strchr (ptr->d_name,'v' )); -snprintf (cur_ifname,sizeof (cur_ifname),"%s" , ptr->d_name); +strlcpy (cur_ifname, ptr->d_name,sizeof (cur_ifname));closedir (dir);snprintf (tmp +strlen (tmp),sizeof (tmp) -strlen (tmp),"/%s/phys_switch_id" , cur_ifname);
drivers/common/mlx5/mlx5_common_utils.c +2 -3
@@ -49,8 +49,7 @@ mlx5_list_create(const char *name, void *ctx, bool lcores_share,if (!list)return NULL ;if (name) -snprintf (list->l_const.name, -sizeof (list->l_const.name),"%s" , name); +strlcpy (list->l_const.name, name,sizeof (list->l_const.name)); list->l_const.ctx = ctx; list->l_const.lcores_share = lcores_share; list->l_const.cb_create = cb_create;
@@ -422,7 +421,7 @@ mlx5_hlist_create(const char *name, uint32_t size, bool direct_key,return NULL ; }if (name) -snprintf (h->l_const.name,sizeof (h->l_const.name),"%s" , name); +strlcpy (h->l_const.name, name,sizeof (h->l_const.name)); h->l_const.ctx = ctx; h->l_const.lcores_share = lcores_share; h->l_const.cb_create = cb_create;
Signature · 1 line
2.39.2
PATCH 7/25 drivers/gpu: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/gpu/cuda/cuda.c | 2 +- drivers/gpu/cuda/gdrcopy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/cuda/cuda.c +1 -1
@@ -291,7 +291,7 @@ cuda_loader(void)char cuda_path[1024 ];if (getenv ("CUDA_PATH_L" ) ==NULL ) -snprintf (cuda_path,1024 ,"%s" ,"libcuda.so" ); +strlcpy (cuda_path,"libcuda.so" ,1024 );else snprintf (cuda_path,1024 ,"%s/%s" ,getenv ("CUDA_PATH_L" ),"libcuda.so" );
drivers/gpu/cuda/gdrcopy.c +1 -1
@@ -20,7 +20,7 @@ gdrcopy_loader(void)char gdrcopy_path[1024 ];if (getenv ("GDRCOPY_PATH_L" ) ==NULL ) -snprintf (gdrcopy_path,1024 ,"%s" ,"libgdrapi.so" ); +strlcpy (gdrcopy_path,"libgdrapi.so" ,1024 );else snprintf (gdrcopy_path,1024 ,"%s/%s" ,getenv ("GDRCOPY_PATH_L" ),"libgdrapi.so" );
Signature · 1 line
2.39.2
PATCH 8/25 crypto/ipsec_mb: remove unnecessary snprintf
In reply to Stephen HemmingerCan just use the ring name directly.
--- drivers/crypto/ipsec_mb/ipsec_mb_ops.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/crypto/ipsec_mb/ipsec_mb_ops.c +1 -6
@@ -185,12 +185,7 @@ static struct rte_ring struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id) { struct rte_ring *r; -char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN ]; - -unsigned int n =rte_strlcpy (ring_name, qp->name,sizeof (ring_name)); - -if (n >=sizeof (ring_name)) -return NULL ; +const char *ring_name = qp->name; r =rte_ring_lookup (ring_name);if (r) {
Signature · 1 line
2.39.2
PATCH 9/25 crypto/dpaa_sec: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/dpaa_sec/dpaa_sec.c +1 -1
@@ -3740,7 +3740,7 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ; -snprintf (cryptodev_name,sizeof (cryptodev_name),"%s" , dpaa_dev->name); +strlcpy (cryptodev_name, dpaa_dev->name,sizeof (cryptodev_name)); cryptodev =rte_cryptodev_pmd_allocate (cryptodev_name,rte_socket_id ());if (cryptodev ==NULL )
Signature · 1 line
2.39.2
PATCH 10/25 event/cnxk: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/event/cnxk/cnxk_eventdev_stats.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/event/cnxk/cnxk_eventdev_stats.c +5 -6
@@ -246,15 +246,14 @@ cnxk_sso_xstats_get_names(const struct rte_eventdev *event_dev,unsigned int i;for (i =0 ; i <CNXK_SSO_NUM_HWS_XSTATS ; i++) { -snprintf (xstats_names_copy[i].name, -sizeof (xstats_names_copy[i].name),"%s" , - sso_hws_xstats[i].name); +strlcpy (xstats_names_copy[i].name, sso_hws_xstats[i].name, +sizeof (xstats_names_copy[i].name)); }for (; i <CNXK_SSO_NUM_XSTATS ; i++) { -snprintf (xstats_names_copy[i].name, -sizeof (xstats_names_copy[i].name),"%s" , - sso_hwgrp_xstats[i -CNXK_SSO_NUM_HWS_XSTATS ].name); +strlcpy (xstats_names_copy[i].name, + sso_hwgrp_xstats[i -CNXK_SSO_NUM_HWS_XSTATS ].name, +sizeof (xstats_names_copy[i].name)); }switch (mode) {
Signature · 1 line
2.39.2
PATCH 11/25 net/atlantic: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/atlantic/atl_ethdev.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/atlantic/atl_ethdev.c +2 -3
@@ -1006,9 +1006,8 @@ atl_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,if (xstats_names) {for (i =0 ; i < size && i < count; i++) { -snprintf (xstats_names[i].name, -RTE_ETH_XSTATS_NAME_SIZE ,"%s" , - atl_xstats_tbl[i].name); +strlcpy (xstats_names[i].name, atl_xstats_tbl[i].name, +RTE_ETH_XSTATS_NAME_SIZE ); } }
Signature · 1 line
2.39.2
PATCH 12/25 net/axgbe: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/axgbe/axgbe_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/axgbe/axgbe_ethdev.c +3 -3
@@ -1025,9 +1025,9 @@ axgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,if (n >=AXGBE_XSTATS_COUNT && xstats_names) {for (i =0 ; i <AXGBE_XSTATS_COUNT ; ++i) { -snprintf (xstats_names[i].name, -RTE_ETH_XSTATS_NAME_SIZE ,"%s" , - axgbe_xstats_strings[i].name); +strlcpy (xstats_names[i].name, + axgbe_xstats_strings[i].name, +RTE_ETH_XSTATS_NAME_SIZE ); } }
Signature · 1 line
2.39.2
PATCH 13/25 net/bnxt: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/bnxt/bnxt_ethdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/bnxt/bnxt_ethdev.c +4 -4
@@ -2983,8 +2983,8 @@ bnxt_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (bnxt_rx_burst_info); i++) {if (pkt_burst == bnxt_rx_burst_info[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - bnxt_rx_burst_info[i].info); +strlcpy (mode->info, bnxt_rx_burst_info[i].info, +sizeof (mode->info));return 0 ; } }
@@ -3017,8 +3017,8 @@ bnxt_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (bnxt_tx_burst_info); i++) {if (pkt_burst == bnxt_tx_burst_info[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - bnxt_tx_burst_info[i].info); +strlcpy (mode->info, bnxt_tx_burst_info[i].info, +sizeof (mode->info));return 0 ; } }
Signature · 1 line
2.39.2
PATCH 14/25 net/cpfl: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/cpfl/cpfl_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/cpfl/cpfl_ethdev.c +3 -3
@@ -380,9 +380,9 @@ static int cpfl_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,if (xstats_names) {for (i =0 ; i <CPFL_NB_XSTATS ; i++) { -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_cpfl_stats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_cpfl_stats_strings[i].name, +sizeof (xstats_names[i].name)); } }return CPFL_NB_XSTATS ;
Signature · 1 line
2.39.2
PATCH 15/25 net/cxgbe: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/cxgbe/cxgbe_ethdev.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/cxgbe/cxgbe_ethdev.c +4 -5
@@ -928,9 +928,8 @@ static int cxgbe_dev_xstats(struct rte_eth_dev *dev, count =0 ;for (i =0 ; i < nstats; i++, count++) {if (xstats_names !=NULL ) -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , xstats_str[i].name); +strlcpy (xstats_names[count].name, xstats_str[i].name, +sizeof (xstats_names[count].name));if (xstats !=NULL ) { stats_ptr =RTE_PTR_ADD (&ps, xstats_str[i].offset);
@@ -1043,8 +1042,8 @@ int cxgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, ret = -EINVAL ; goto out_err; } -rte_strlcpy (xnames[i].name, xnames_copy[ids[i]].name, -sizeof (xnames[i].name)); +strlcpy (xnames[i].name, xnames_copy[ids[i]].name, +sizeof (xnames[i].name)); } ret = n;
Signature · 1 line
2.39.2
PATCH 16/25 net/dpaa*: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/dpaa/dpaa_ethdev.c | 8 ++++---- drivers/net/dpaa2/dpaa2_ethdev.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/net/dpaa/dpaa_ethdev.c +4 -4
@@ -620,8 +620,8 @@ dpaa_dev_rx_burst_mode_get(struct rte_eth_dev *dev,/* Update Rx offload info */ for (i =0 ; i <RTE_DIM (rx_offload_map); i++) {if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) { -snprintf (mode->info,sizeof (mode->info),"%s" , - rx_offload_map[i].output); +strlcpy (mode->info, rx_offload_map[i].output, +sizeof (mode->info)); ret =0 ;break ; }
@@ -654,8 +654,8 @@ dpaa_dev_tx_burst_mode_get(struct rte_eth_dev *dev,/* Update Tx offload info */ for (i =0 ; i <RTE_DIM (tx_offload_map); i++) {if (eth_conf->txmode.offloads & tx_offload_map[i].flags) { -snprintf (mode->info,sizeof (mode->info),"%s" , - tx_offload_map[i].output); +strlcpy (mode->info, tx_offload_map[i].output, +sizeof (mode->info)); ret =0 ;break ; }
drivers/net/dpaa2/dpaa2_ethdev.c +4 -4
@@ -313,8 +313,8 @@ dpaa2_dev_rx_burst_mode_get(struct rte_eth_dev *dev,/* Update Rx offload info */ for (i =0 ; i <RTE_DIM (rx_offload_map); i++) {if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) { -snprintf (mode->info,sizeof (mode->info),"%s" , - rx_offload_map[i].output); +strlcpy (mode->info, rx_offload_map[i].output, +sizeof (mode->info)); ret =0 ;break ; }
@@ -348,8 +348,8 @@ dpaa2_dev_tx_burst_mode_get(struct rte_eth_dev *dev,/* Update Tx offload info */ for (i =0 ; i <RTE_DIM (tx_offload_map); i++) {if (eth_conf->txmode.offloads & tx_offload_map[i].flags) { -snprintf (mode->info,sizeof (mode->info),"%s" , - tx_offload_map[i].output); +strlcpy (mode->info, tx_offload_map[i].output, +sizeof (mode->info)); ret =0 ;break ; }
Signature · 1 line
2.39.2
PATCH 17/25 net/hinic: replace snptintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- 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(-)
drivers/net/hinic/base/hinic_compat.h +1 -0
@@ -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 ;
drivers/net/hinic/base/hinic_pmd_niccfg.c +1 -3
@@ -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; } - -
drivers/net/hinic/hinic_pmd_ethdev.c +7 -7
@@ -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++; }
Signature · 1 line
2.39.2
PATCH 18/25 net/hns3: replace snprint with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/hns3/hns3_fdir.c | 2 +- drivers/net/hns3/hns3_rxtx.c | 8 ++++---- drivers/net/hns3/hns3_stats.c | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-)
drivers/net/hns3/hns3_fdir.c +1 -1
@@ -843,7 +843,7 @@ int hns3_fdir_filter_init(struct hns3_adapter *hns) fdir_hash_params.socket_id =rte_socket_id ();TAILQ_INIT (&fdir_info->fdir_list); -snprintf (fdir_hash_name,RTE_HASH_NAMESIZE ,"%s" , hns->hw.data->name); +strlcpy (fdir_hash_name, hns->hw.data->name,RTE_HASH_NAMESIZE ); fdir_info->hash_handle =rte_hash_create (&fdir_hash_params);if (fdir_info->hash_handle ==NULL ) {PMD_INIT_LOG (ERR ,"Create FDIR hash handle fail!" );
drivers/net/hns3/hns3_rxtx.c +4 -4
@@ -2795,8 +2795,8 @@ hns3_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (burst_infos); i++) {if (pkt_burst == burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - burst_infos[i].info); +strlcpy (mode->info, burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
@@ -4290,8 +4290,8 @@ hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (burst_infos); i++) {if (pkt_burst == burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - burst_infos[i].info); +strlcpy (mode->info, burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
drivers/net/hns3/hns3_stats.c +11 -11
@@ -1176,9 +1176,9 @@ hns3_imissed_stats_name_get(struct rte_eth_dev *dev, imissed_stats_num =hns3_get_imissed_stats_num (hns);for (i =0 ; i < imissed_stats_num; i++) { -snprintf (xstats_names[cnt].name, -sizeof (xstats_names[cnt].name), -"%s" , hns3_imissed_stats_strings[i].name); +strlcpy (xstats_names[cnt].name, + hns3_imissed_stats_strings[i].name, +sizeof (xstats_names[cnt].name)); cnt++; }
@@ -1228,9 +1228,9 @@ hns3_dev_xstats_get_names(struct rte_eth_dev *dev,if (!hns->is_vf) {/* Get MAC name from hw->hw_xstats.mac_stats struct */ for (i =0 ; i <HNS3_NUM_MAC_STATS ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , hns3_mac_strings[i].name); +strlcpy (xstats_names[count].name, + hns3_mac_strings[i].name, +sizeof (xstats_names[count].name)); count++; } }
@@ -1238,9 +1238,9 @@ hns3_dev_xstats_get_names(struct rte_eth_dev *dev,hns3_imissed_stats_name_get (dev, xstats_names, &count);for (i =0 ; i <HNS3_NUM_RESET_XSTATS ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , hns3_reset_stats_strings[i].name); +strlcpy (xstats_names[count].name, + hns3_reset_stats_strings[i].name, +sizeof (xstats_names[count].name)); count++; }
@@ -1418,8 +1418,8 @@ hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,rte_free (names_copy);return -EINVAL ; } -snprintf (xstats_names[i].name,sizeof (xstats_names[i].name), -"%s" , names_copy[ids[i]].name); +strlcpy (xstats_names[i].name, names_copy[ids[i]].name, +sizeof (xstats_names[i].name)); }rte_free (names_copy);
Signature · 1 line
2.39.2
PATCH 19/25 net/intel: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/fm10k/fm10k_ethdev.c | 6 +++--- drivers/net/i40e/i40e_rxtx.c | 8 ++++---- drivers/net/iavf/iavf_ethdev.c | 6 +++--- drivers/net/ice/ice_dcf_ethdev.c | 6 +++--- drivers/net/ice/ice_rxtx.c | 8 ++++---- drivers/net/idpf/idpf_ethdev.c | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-)
drivers/net/fm10k/fm10k_ethdev.c +3 -3
@@ -1244,9 +1244,9 @@ static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,/* Global stats */ for (i =0 ; i <FM10K_NB_HW_XSTATS ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , fm10k_hw_stats_strings[count].name); +strlcpy (xstats_names[count].name, + fm10k_hw_stats_strings[count].name, +sizeof (xstats_names[count].name)); count++; }
drivers/net/i40e/i40e_rxtx.c +4 -4
@@ -3395,8 +3395,8 @@ i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (i40e_rx_burst_infos); ++i) {if (pkt_burst == i40e_rx_burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - i40e_rx_burst_infos[i].info); +strlcpy (mode->info, i40e_rx_burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
@@ -3526,8 +3526,8 @@ i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (i40e_tx_burst_infos); ++i) {if (pkt_burst == i40e_tx_burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - i40e_tx_burst_infos[i].info); +strlcpy (mode->info, i40e_tx_burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
drivers/net/iavf/iavf_ethdev.c +3 -3
@@ -1802,9 +1802,9 @@ static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,if (xstats_names !=NULL )for (i =0 ; i <IAVF_NB_XSTATS ; i++) { -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_iavf_stats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_iavf_stats_strings[i].name, +sizeof (xstats_names[i].name)); }return IAVF_NB_XSTATS ; }
drivers/net/ice/ice_dcf_ethdev.c +3 -3
@@ -1549,9 +1549,9 @@ static int ice_dcf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,if (xstats_names !=NULL )for (i =0 ; i <ICE_DCF_NB_XSTATS ; i++) { -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_ice_dcf_stats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_ice_dcf_stats_strings[i].name, +sizeof (xstats_names[i].name)); }return ICE_DCF_NB_XSTATS ; }
drivers/net/ice/ice_rxtx.c +4 -4
@@ -3605,8 +3605,8 @@ ice_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (ice_rx_burst_infos); ++i) {if (pkt_burst == ice_rx_burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - ice_rx_burst_infos[i].info); +strlcpy (mode->info, ice_rx_burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
@@ -3846,8 +3846,8 @@ ice_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (ice_tx_burst_infos); ++i) {if (pkt_burst == ice_tx_burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - ice_tx_burst_infos[i].info); +strlcpy (mode->info, ice_tx_burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
drivers/net/idpf/idpf_ethdev.c +3 -3
@@ -384,9 +384,9 @@ static int idpf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,if (xstats_names)for (i =0 ; i <IDPF_NB_XSTATS ; i++) { -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_idpf_stats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_idpf_stats_strings[i].name, +sizeof (xstats_names[i].name)); }return IDPF_NB_XSTATS ; }
Signature · 1 line
2.39.2
PATCH 20/25 net/ionic: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/ionic/ionic_ethdev.c | 15 +++++++-------- drivers/net/ipn3ke/ipn3ke_representor.c | 17 +++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-)
drivers/net/ionic/ionic_ethdev.c +7 -8
@@ -208,8 +208,7 @@ ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,struct ionic_adapter *adapter = lif->adapter;int ret; - ret =snprintf (fw_version, fw_size,"%s" , - adapter->fw_version); + ret =strlcpy (fw_version, adapter->fw_version, fw_size);if (ret <0 )return -EINVAL ;
@@ -705,9 +704,9 @@ ionic_dev_xstats_get_names(__rte_unused struct rte_eth_dev *eth_dev,if (xstats_names !=NULL ) {for (i =0 ; i <IONIC_NB_HW_STATS ; i++) { -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_ionic_xstats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_ionic_xstats_strings[i].name, +sizeof (xstats_names[i].name)); } }
@@ -725,9 +724,9 @@ ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,if (!ids) {if (xstats_names !=NULL ) {for (i =0 ; i <IONIC_NB_HW_STATS ; i++) { -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_ionic_xstats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_ionic_xstats_strings[i].name, +sizeof (xstats_names[i].name)); } }
drivers/net/ipn3ke/ipn3ke_representor.c +7 -10
@@ -124,8 +124,7 @@ ipn3ke_rpst_dev_start(struct rte_eth_dev *dev) rawdev = hw->rawdev;memset (attr_name,0 ,sizeof (attr_name)); -snprintf (attr_name,IPN3KE_RAWDEV_ATTR_LEN_MAX ,"%s" , -"LineSideBaseMAC" ); +strlcpy (attr_name,"LineSideBaseMAC" ,IPN3KE_RAWDEV_ATTR_LEN_MAX ); rawdev->dev_ops->attr_get (rawdev, attr_name, &base_mac);rte_ether_addr_copy ((struct rte_ether_addr *)&base_mac, &rpst->mac_addr);
@@ -2330,19 +2329,17 @@ __rte_unused unsigned int limit)/* Get stats from ipn3ke_rpst_stats */ for (i =0 ; i <IPN3KE_RPST_ETH_XSTATS_CNT ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , - ipn3ke_rpst_stats_strings[i].name); +strlcpy (xstats_names[count].name, + ipn3ke_rpst_stats_strings[i].name, +sizeof (xstats_names[count].name)); count++; }/* Get individual stats from ipn3ke_rpst_hw_port */ for (i =0 ; i <IPN3KE_RPST_HW_PORT_XSTATS_CNT ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , - ipn3ke_rpst_hw_port_strings[i].name); +strlcpy (xstats_names[count].name, + ipn3ke_rpst_hw_port_strings[i].name, +sizeof (xstats_names[count].name)); count++; }
Signature · 1 line
2.39.2
PATCH 21/25 net/mlx5: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/mlx5/mlx5_rx.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/mlx5/mlx5_rx.c +8 -8
@@ -219,26 +219,26 @@ mlx5_rx_burst_mode_get(struct rte_eth_dev *dev,return -rte_errno; }if (pkt_burst == mlx5_rx_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" ,"Scalar" ); +strlcpy (mode->info,"Scalar" ,sizeof (mode->info)); }else if (pkt_burst == mlx5_rx_burst_mprq) { -snprintf (mode->info,sizeof (mode->info),"%s" ,"Multi-Packet RQ" ); +strlcpy (mode->info,"Multi-Packet RQ" ,sizeof (mode->info)); }else if (pkt_burst == mlx5_rx_burst_vec) {#if definedRTE_ARCH_X86_64 -snprintf (mode->info,sizeof (mode->info),"%s" ,"Vector SSE" ); +strlcpy (mode->info,"Vector SSE" ,sizeof (mode->info));#elif definedRTE_ARCH_ARM64 -snprintf (mode->info,sizeof (mode->info),"%s" ,"Vector Neon" ); +strlcpy (mode->info,"Vector Neon" ,sizeof (mode->info));#elif definedRTE_ARCH_PPC_64 -snprintf (mode->info,sizeof (mode->info),"%s" ,"Vector AltiVec" ); +strlcpy (mode->info,"Vector AltiVec" ,sizeof (mode->info));#else return -EINVAL ;#endif }else if (pkt_burst == mlx5_rx_burst_mprq_vec) {#if definedRTE_ARCH_X86_64 -snprintf (mode->info,sizeof (mode->info),"%s" ,"MPRQ Vector SSE" ); +strlcpy (mode->info,"MPRQ Vector SSE" ,sizeof (mode->info));#elif definedRTE_ARCH_ARM64 -snprintf (mode->info,sizeof (mode->info),"%s" ,"MPRQ Vector Neon" ); +strlcpy (mode->info,"MPRQ Vector Neon" ,sizeof (mode->info));#elif definedRTE_ARCH_PPC_64 -snprintf (mode->info,sizeof (mode->info),"%s" ,"MPRQ Vector AltiVec" ); +strlcpy (mode->info,"MPRQ Vector AltiVec" ,sizeof (mode->info));#else return -EINVAL ;#endif
Signature · 1 line
2.39.2
PATCH 22/25 net/nfp: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/nfp/flower/nfp_flower_representor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/nfp/flower/nfp_flower_representor.c +2 -2
@@ -600,7 +600,7 @@ nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev, repr->repr_type = init_repr_data->repr_type; repr->app_fw_flower = init_repr_data->app_fw_flower; -snprintf (repr->name,sizeof (repr->name),"%s" , init_repr_data->name); +strlcpy (repr->name, init_repr_data->name,sizeof (repr->name)); eth_dev->dev_ops = &nfp_flower_pf_repr_dev_ops; eth_dev->rx_pkt_burst = nfp_flower_pf_recv_pkts;
@@ -671,7 +671,7 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev, repr->repr_type = init_repr_data->repr_type; repr->app_fw_flower = init_repr_data->app_fw_flower; -snprintf (repr->name,sizeof (repr->name),"%s" , init_repr_data->name); +strlcpy (repr->name, init_repr_data->name,sizeof (repr->name)); eth_dev->dev_ops = &nfp_flower_repr_dev_ops; eth_dev->rx_pkt_burst = nfp_flower_repr_rx_burst;
Signature · 1 line
2.39.2
PATCH 23/25 net/ngbe: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/ngbe/ngbe_rxtx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ngbe/ngbe_rxtx.c +4 -4
@@ -1875,8 +1875,8 @@ ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (ngbe_tx_burst_infos); ++i) {if (pkt_burst == ngbe_tx_burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - ngbe_tx_burst_infos[i].info); +strlcpy (mode->info, ngbe_tx_burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
@@ -2785,8 +2785,8 @@ ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,for (i =0 ; i <RTE_DIM (ngbe_rx_burst_infos); ++i) {if (pkt_burst == ngbe_rx_burst_infos[i].pkt_burst) { -snprintf (mode->info,sizeof (mode->info),"%s" , - ngbe_rx_burst_infos[i].info); +strlcpy (mode->info, ngbe_rx_burst_infos[i].info, +sizeof (mode->info)); ret =0 ;break ; }
Signature · 1 line
2.39.2
PATCH 24/25 net/qede: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/qede/qede_ethdev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/qede/qede_ethdev.c +4 -6
@@ -238,8 +238,8 @@ qede_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)size_t size;if (IS_PF (edev)) -snprintf (ver_str,QEDE_PMD_DRV_VER_STR_SIZE ,"%s" , -QEDE_PMD_FW_VERSION ); +strlcpy (ver_str,QEDE_PMD_FW_VERSION , +QEDE_PMD_DRV_VER_STR_SIZE );else snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%d.%d.%d.%d", info->fw_major, info->fw_minor,
@@ -374,11 +374,9 @@ static void qede_print_adapter_info(struct rte_eth_dev *dev)ECORE_IS_BB (edev) ?"BB" :"AH" ,'A' + edev->chip_rev, (int)edev->chip_metal); -snprintf (ver_str,QEDE_PMD_DRV_VER_STR_SIZE ,"%s" , -QEDE_PMD_DRV_VERSION ); +strlcpy (ver_str,QEDE_PMD_DRV_VERSION ,QEDE_PMD_DRV_VER_STR_SIZE );DP_INFO (edev," %-20s: %s\n" ,"Driver version" , ver_str); -snprintf (ver_str,QEDE_PMD_DRV_VER_STR_SIZE ,"%s" , -QEDE_PMD_BASE_VERSION ); +strlcpy (ver_str,QEDE_PMD_BASE_VERSION ,QEDE_PMD_DRV_VER_STR_SIZE );DP_INFO (edev," %-20s: %s\n" ,"Base version" , ver_str);qede_fw_version_get (dev, ver_str,sizeof (ver_str));DP_INFO (edev," %-20s: %s\n" ,"Firmware version" , ver_str);
Signature · 1 line
2.39.2
PATCH 25/25 net/txgbe: replace snprintf with strlcpy
In reply to Stephen HemmingerSuggested by devtools/cocci/strlcpy-with-header.cocci
--- drivers/net/txgbe/txgbe_ethdev_vf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/txgbe/txgbe_ethdev_vf.c +3 -3
@@ -357,9 +357,9 @@ static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,if (xstats_names !=NULL )for (i =0 ; i <TXGBEVF_NB_XSTATS ; i++) -snprintf (xstats_names[i].name, -sizeof (xstats_names[i].name), -"%s" , rte_txgbevf_stats_strings[i].name); +strlcpy (xstats_names[i].name, + rte_txgbevf_stats_strings[i].name, +sizeof (xstats_names[i].name));return TXGBEVF_NB_XSTATS ; }
Signature · 1 line
2.39.2
RE: [PATCH 16/25] net/dpaa*: replace snprintf with strlcpy
In reply to Stephen HemmingerRE: [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy
In reply to Stephen HemmingerRE: [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy
In reply to Stephen HemmingerHi,
Quoted 38 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, June 1, 2023 11:01 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>
Subject: [PATCH 04/25] raw/ifpga: replace snprintf with strlcpySuggested by
devtools/cocci/strlcpy-with-header.cocciSigned-off-by Stephen Hemminger <[email protected]>--- drivers/raw/ifpga/afu_pmd_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/raw/ifpga/afu_pmd_core.c +2
-2@@ -16,6 +16,7 @@#include <rte_malloc.h> #include <rte_memzone.h> #include <rte_rawdev_pmd.h> +#include <rte_string_fns.h> #include "afu_pmd_core.h" @@ -225,7 +226,7 @@ static int afu_shared_data_alloc(const char *name,return -EINVAL ;/* name format is afu_?|??:??.? which is unique */ -snprintf (mz_name,sizeof (mz_name),"%s" , name); +strlcpy (mz_name, name,sizeof (mz_name)); mz =rte_memzone_lookup (mz_name);if (!mz) { --
Quoted 1 line
2.39.2
RE: [PATCH 20/25] net/ionic: replace snprintf with strlcpy
In reply to Stephen HemmingerHi,
Quoted 58 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, June 1, 2023 11:01 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Andrew Boyer <[email protected]>; Xu, Rosen <[email protected]>
Subject: [PATCH 20/25] net/ionic: replace snprintf with strlcpySuggested by
devtools/cocci/strlcpy-with-header.cocciSigned-off-by Stephen Hemminger <[email protected]>--- drivers/net/ipn3ke/ipn3ke_representor.c | 17 +++++++----------drivers/net/ipn3ke/ipn3ke_representor.c +1
-2@@ -124,8 +124,7 @@ ipn3ke_rpst_dev_start(struct rte_eth_dev *dev) rawdev = hw->rawdev;memset (attr_name,0 ,sizeof (attr_name)); -snprintf (attr_name,IPN3KE_RAWDEV_ATTR_LEN_MAX ,"%s" , -"LineSideBaseMAC" ); +strlcpy (attr_name,"LineSideBaseMAC" ,IPN3KE_RAWDEV_ATTR_LEN_MAX ); rawdev->dev_ops->attr_get (rawdev, attr_name, &base_mac); rte_ether_addr_copy((struct rte_ether_addr *)&base_mac,drivers/net/ipn3ke/ipn3ke_representor.c +6
-9&rpst->mac_addr);@@ -2330,19 +2329,17 @@ __rte_unused unsigned int limit)/* Get stats from ipn3ke_rpst_stats */ for (i =0 ; i <IPN3KE_RPST_ETH_XSTATS_CNT ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , - ipn3ke_rpst_stats_strings[i].name); +strlcpy (xstats_names[count].name, + ipn3ke_rpst_stats_strings[i].name, +sizeof (xstats_names[count].name)); count++; }/* Get individual stats from ipn3ke_rpst_hw_port */ for (i =0 ; i <IPN3KE_RPST_HW_PORT_XSTATS_CNT ; i++) { -snprintf (xstats_names[count].name, -sizeof (xstats_names[count].name), -"%s" , - ipn3ke_rpst_hw_port_strings[i].name); +strlcpy (xstats_names[count].name, + ipn3ke_rpst_hw_port_strings[i].name, +sizeof (xstats_names[count].name)); count++; } --
Quoted 1 line
2.39.2
Quoted 3 lines · Stephen Hemminger
This patch series was generated by using the existing Coccinelle script to find where
snprintf()is used butstrlcpy()could be used instead.
i guess the motivation here is strlcpy is safer to use than the portable snprintf? not objecting, just confirming.
Quoted 81 lines
Manually replaced fixed some trigraphs and paren's where needed. Also one instance the whole temporary string copy was not needed at all.
Stephen Hemminger (25):
app: use strlcpy in tests
examples: use strlcpy instead of snprintf
lib: use strlcpy instead of snprintf raw/ifpga: replace snprintf with strlcpy common/cnxk: replace snprint with strlcpy common/mlx5: replace snprintf with strlcpydrivers/gpu: replace snprintf with strlcpycrypto/ipsec_mb: remove unnecessary snprintfcrypto/dpaa_sec: replace snprintf with strlcpy event/cnxk: replace snprintf with strlcpy net/atlantic: replace snprintf with strlcpy net/axgbe: replace snprintf with strlcpy net/bnxt: replace snprintf with strlcpy net/cpfl: replace snprintf with strlcpy net/cxgbe: replace snprintf with strlcpynet/dpaa*: replace snprintf with strlcpy net/hinic: replace snptintf with strlcpy net/hns3: replace snprint with strlcpy net/intel: replace snprintf with strlcpy net/ionic: replace snprintf with strlcpy net/mlx5: replace snprintf with strlcpy net/nfp: replace snprintf with strlcpy net/ngbe: replace snprintf with strlcpy net/qede: replace snprintf with strlcpy net/txgbe: replace snprintf with strlcpyapp/test-bbdev/main.c | 5 ++-- app/test-pmd/cmdline_flow.c | 6 ++-- app/test/process.h | 2 +- app/test/test_graph_perf.c | 29 ++++++++++--------- drivers/common/cnxk/roc_nix_stats.c | 4 +-- drivers/common/mlx5/linux/mlx5_common_os.c | 2 +- drivers/common/mlx5/mlx5_common_utils.c | 5 ++-- drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- drivers/crypto/ipsec_mb/ipsec_mb_ops.c | 7 +---- drivers/event/cnxk/cnxk_eventdev_stats.c | 11 ++++--- drivers/gpu/cuda/cuda.c | 2 +- drivers/gpu/cuda/gdrcopy.c | 2 +- drivers/net/atlantic/atl_ethdev.c | 5 ++-- drivers/net/axgbe/axgbe_ethdev.c | 6 ++-- drivers/net/bnxt/bnxt_ethdev.c | 8 ++--- drivers/net/cpfl/cpfl_ethdev.c | 6 ++-- drivers/net/cxgbe/cxgbe_ethdev.c | 9 +++--- drivers/net/dpaa/dpaa_ethdev.c | 8 ++--- drivers/net/dpaa2/dpaa2_ethdev.c | 8 ++--- drivers/net/fm10k/fm10k_ethdev.c | 6 ++-- 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 ++++----- drivers/net/hns3/hns3_fdir.c | 2 +- drivers/net/hns3/hns3_rxtx.c | 8 ++--- drivers/net/hns3/hns3_stats.c | 22 +++++++------- drivers/net/i40e/i40e_rxtx.c | 8 ++--- drivers/net/iavf/iavf_ethdev.c | 6 ++-- drivers/net/ice/ice_dcf_ethdev.c | 6 ++-- drivers/net/ice/ice_rxtx.c | 8 ++--- drivers/net/idpf/idpf_ethdev.c | 6 ++-- drivers/net/ionic/ionic_ethdev.c | 15 +++++----- drivers/net/ipn3ke/ipn3ke_representor.c | 17 +++++------ drivers/net/mlx5/mlx5_rx.c | 16 +++++----- .../net/nfp/flower/nfp_flower_representor.c | 4 +-- drivers/net/ngbe/ngbe_rxtx.c | 8 ++--- drivers/net/qede/qede_ethdev.c | 10 +++---- drivers/net/txgbe/txgbe_ethdev_vf.c | 6 ++-- drivers/raw/ifpga/afu_pmd_core.c | 3 +- examples/fips_validation/fips_validation.c | 8 ++--- examples/l3fwd-graph/main.c | 2 +- examples/pipeline/cli.c | 2 +- examples/vhost_blk/vhost_blk.c | 5 ++-- lib/bbdev/rte_bbdev.c | 2 +- lib/ethdev/sff_8636.c | 11 ++++--- 45 files changed, 157 insertions(+), 170 deletions(-)Signature · 1 line
2.39.2
Re: [PATCH 22/25] net/nfp: replace snprintf with strlcpy
In reply to Stephen HemmingerHi Stephen,
Thanks for your work.
Quoted 3 lines · Stephen Hemminger
Suggested by
devtools/cocci/strlcpy-with-header.cocciSigned-off-by Stephen Hemminger <[email protected]>
Quoted 29 lines
--- drivers/net/nfp/flower/nfp_flower_representor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/nfp/flower/nfp_flower_representor.c +2
-2@@ -600,7 +600,7 @@ nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev, repr->repr_type = init_repr_data->repr_type; repr->app_fw_flower = init_repr_data->app_fw_flower; -snprintf (repr->name,sizeof (repr->name),"%s" , init_repr_data->name); +strlcpy (repr->name, init_repr_data->name,sizeof (repr->name)); eth_dev->dev_ops = &nfp_flower_pf_repr_dev_ops; eth_dev->rx_pkt_burst = nfp_flower_pf_recv_pkts;@@ -671,7 +671,7 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev, repr->repr_type = init_repr_data->repr_type; repr->app_fw_flower = init_repr_data->app_fw_flower; -snprintf (repr->name,sizeof (repr->name),"%s" , init_repr_data->name); +strlcpy (repr->name, init_repr_data->name,sizeof (repr->name)); eth_dev->dev_ops = &nfp_flower_repr_dev_ops; eth_dev->rx_pkt_burst = nfp_flower_repr_rx_burst;Signature · 1 line
2.39.2
Signature · 2 lines
Kind Regards, Niklas Söderlund