cleanup use of rte_strlcpy
cover cleanup use of rte_strlcpy
In DPDK API's rte_strlcpy() is not intended to be used directly. It was introduced as a replacement for when operating system libraries were missing strlcpy(). Over time it appears several drivers and subsystems started using it directly, which is inefficient since the wrapper uses snprintf().
This series makes sure that the only usage of rte_strlcpy() is in rte_string_fns.h where it is needed.
Perhaps checkpatch should warn about other uses?
Stephen Hemminger (2):
lib: replace rte_strlcpy() with strlcpy()
drivers: don't use rte_strlcpy
drivers/common/cnxk/roc_platform.h | 2 +- drivers/mempool/cnxk/cnxk_mempool_telemetry.c | 2 +- drivers/net/cnxk/cnxk_ethdev_ops.c | 4 +- drivers/net/mlx5/mlx5_testpmd.c | 2 +- lib/eal/common/eal_common_memzone.c | 2 +- lib/fib/rte_fib.c | 2 +- lib/fib/rte_fib6.c | 2 +- lib/hash/rte_thash.c | 4 +- lib/mempool/rte_mempool.c | 2 +- lib/mldev/mldev_utils.c | 40 +++++++++---------- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- 12 files changed, 33 insertions(+), 33 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/2 lib: replace rte_strlcpy() with strlcpy()
The function rte_strlcpy is intended to be a platform specific wrapper function and only used where necessary. Prefer using the OS supplied strlcpy() if available.
--- lib/eal/common/eal_common_memzone.c | 2 +- lib/fib/rte_fib.c | 2 +- lib/fib/rte_fib6.c | 2 +- lib/hash/rte_thash.c | 4 +-- lib/mempool/rte_mempool.c | 2 +- lib/mldev/mldev_utils.c | 40 ++++++++++++++--------------- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-)
lib/eal/common/eal_common_memzone.c +1 -1
@@ -274,7 +274,7 @@ rte_memzone_free(const struct rte_memzone *mz)if (mz ==NULL )return -EINVAL ; -rte_strlcpy (name, mz->name,RTE_MEMZONE_NAMESIZE ); +strlcpy (name, mz->name,RTE_MEMZONE_NAMESIZE ); mcfg =rte_eal_get_configuration ()->mem_config; arr = &mcfg->memzones;
lib/fib/rte_fib.c +1 -1
@@ -208,7 +208,7 @@ rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf) goto free_te; } -rte_strlcpy (fib->name, name,sizeof (fib->name)); +strlcpy (fib->name, name,sizeof (fib->name)); fib->rib = rib; fib->type = conf->type; fib->def_nh = conf->default_nh;
lib/fib/rte_fib6.c +1 -1
@@ -209,7 +209,7 @@ rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf) goto free_te; } -rte_strlcpy (fib->name, name,sizeof (fib->name)); +strlcpy (fib->name, name,sizeof (fib->name)); fib->rib = rib; fib->type = conf->type; fib->def_nh = conf->default_nh;
lib/hash/rte_thash.c +2 -2
@@ -255,7 +255,7 @@ rte_thash_init_ctx(const char *name, uint32_t key_len, uint32_t reta_sz, goto free_te; } -rte_strlcpy (ctx->name, name,sizeof (ctx->name)); +strlcpy (ctx->name, name,sizeof (ctx->name)); ctx->key_len = key_len; ctx->reta_sz_log = reta_sz;LIST_INIT (&ctx->head);
@@ -574,7 +574,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,if (ent ==NULL )return -ENOMEM ; -rte_strlcpy (ent->name, name,sizeof (ent->name)); +strlcpy (ent->name, name,sizeof (ent->name)); ent->offset = start; ent->len = end - start; ent->tuple_offset = offset;
lib/mempool/rte_mempool.c +1 -1
@@ -1546,7 +1546,7 @@ mempool_handle_info(const char *cmd __rte_unused, const char *params,if (!params ||strlen (params) ==0 )return -EINVAL ; -rte_strlcpy (name, params,RTE_MEMZONE_NAMESIZE ); +strlcpy (name, params,RTE_MEMZONE_NAMESIZE );rte_tel_data_start_dict (d); mp_arg.pool_name = name;
lib/mldev/mldev_utils.c +20 -20
@@ -50,40 +50,40 @@ rte_ml_io_type_to_str(enum rte_ml_io_type type, char *str, int len) {switch (type) {case RTE_ML_IO_TYPE_UNKNOWN : -rte_strlcpy (str,"unknown" , len); +strlcpy (str,"unknown" , len);break ;case RTE_ML_IO_TYPE_INT8 : -rte_strlcpy (str,"int8" , len); +strlcpy (str,"int8" , len);break ;case RTE_ML_IO_TYPE_UINT8 : -rte_strlcpy (str,"uint8" , len); +strlcpy (str,"uint8" , len);break ;case RTE_ML_IO_TYPE_INT16 : -rte_strlcpy (str,"int16" , len); +strlcpy (str,"int16" , len);break ;case RTE_ML_IO_TYPE_UINT16 : -rte_strlcpy (str,"uint16" , len); +strlcpy (str,"uint16" , len);break ;case RTE_ML_IO_TYPE_INT32 : -rte_strlcpy (str,"int32" , len); +strlcpy (str,"int32" , len);break ;case RTE_ML_IO_TYPE_UINT32 : -rte_strlcpy (str,"uint32" , len); +strlcpy (str,"uint32" , len);break ;case RTE_ML_IO_TYPE_FP8 : -rte_strlcpy (str,"float8" , len); +strlcpy (str,"float8" , len);break ;case RTE_ML_IO_TYPE_FP16 : -rte_strlcpy (str,"float16" , len); +strlcpy (str,"float16" , len);break ;case RTE_ML_IO_TYPE_FP32 : -rte_strlcpy (str,"float32" , len); +strlcpy (str,"float32" , len);break ;case RTE_ML_IO_TYPE_BFLOAT16 : -rte_strlcpy (str,"bfloat16" , len); +strlcpy (str,"bfloat16" , len);break ;default : -rte_strlcpy (str,"invalid" , len); +strlcpy (str,"invalid" , len); } }
@@ -92,27 +92,27 @@ rte_ml_io_format_to_str(enum rte_ml_io_format format, char *str, int len) {switch (format) {case RTE_ML_IO_FORMAT_NCHW : -rte_strlcpy (str,"NCHW" , len); +strlcpy (str,"NCHW" , len);break ;case RTE_ML_IO_FORMAT_NHWC : -rte_strlcpy (str,"NHWC" , len); +strlcpy (str,"NHWC" , len);break ;case RTE_ML_IO_FORMAT_CHWN : -rte_strlcpy (str,"CHWN" , len); +strlcpy (str,"CHWN" , len);break ;case RTE_ML_IO_FORMAT_3D : -rte_strlcpy (str,"3D" , len); +strlcpy (str,"3D" , len);break ;case RTE_ML_IO_FORMAT_2D : -rte_strlcpy (str,"Matrix" , len); +strlcpy (str,"Matrix" , len);break ;case RTE_ML_IO_FORMAT_1D : -rte_strlcpy (str,"Vector" , len); +strlcpy (str,"Vector" , len);break ;case RTE_ML_IO_FORMAT_SCALAR : -rte_strlcpy (str,"Scalar" , len); +strlcpy (str,"Scalar" , len);break ;default : -rte_strlcpy (str,"invalid" , len); +strlcpy (str,"invalid" , len); } }
lib/rib/rte_rib.c +1 -1
@@ -453,7 +453,7 @@ rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf) goto free_te; } -rte_strlcpy (rib->name, name,sizeof (rib->name)); +strlcpy (rib->name, name,sizeof (rib->name)); rib->tree =NULL ; rib->max_nodes = conf->max_nodes; rib->node_pool = node_pool;
lib/rib/rte_rib6.c +1 -1
@@ -522,7 +522,7 @@ rte_rib6_create(const char *name, int socket_id, goto free_te; } -rte_strlcpy (rib->name, name,sizeof (rib->name)); +strlcpy (rib->name, name,sizeof (rib->name)); rib->tree =NULL ; rib->max_nodes = conf->max_nodes; rib->node_pool = node_pool;
Signature · 1 line
2.39.2
PATCH 2/2 drivers: don't use rte_strlcpy
In reply to Stephen HemmingerPrefer using strlcpy over rte_strlcpy.
--- drivers/common/cnxk/roc_platform.h | 2 +- drivers/mempool/cnxk/cnxk_mempool_telemetry.c | 2 +- drivers/net/cnxk/cnxk_ethdev_ops.c | 4 ++-- drivers/net/mlx5/mlx5_testpmd.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/common/cnxk/roc_platform.h +1 -1
@@ -215,7 +215,7 @@#define plt_lcore_id rte_lcore_id -#define plt_strlcpy rte_strlcpy +#define plt_strlcpy strlcpy#define PLT_TEL_INT_VAL RTE_TEL_INT_VAL#define PLT_TEL_STRING_VAL RTE_TEL_STRING_VAL
drivers/mempool/cnxk/cnxk_mempool_telemetry.c +1 -1
@@ -39,7 +39,7 @@ mempool_tel_handle_info(const char *cmd __rte_unused, const char *params,if (params ==NULL ||strlen (params) ==0 )return -EINVAL ; -rte_strlcpy (name, params,RTE_MEMZONE_NAMESIZE ); +strlcpy (name, params,RTE_MEMZONE_NAMESIZE );rte_tel_data_start_dict (d); mp_arg.pool_name = name;
drivers/net/cnxk/cnxk_ethdev_ops.c +2 -2
@@ -753,12 +753,12 @@ cnxk_nix_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version, {struct cnxk_eth_dev *dev =cnxk_eth_pmd_priv (eth_dev);const char *str =roc_npc_profile_name_get (&dev->npc); -uint32_t size =strlen (str) +1 ; +size_t size =strlen (str) +1 ;if (fw_size > size) fw_size = size; -rte_strlcpy (fw_version, str, fw_size); +strlcpy (fw_version, str, fw_size);if (fw_size < size)return size;
drivers/net/mlx5/mlx5_testpmd.c +1 -1
@@ -179,7 +179,7 @@ mlx5_test_extend_devargs(char *identifier, char *extend) strerror(errno));return -1 ; } -rte_strlcpy (un.sun_path, path,sizeof (un.sun_path)); +strlcpy (un.sun_path, path,sizeof (un.sun_path));if (connect (socket_fd, (struct sockaddr *)&un,sizeof (un)) <0 ) {TESTPMD_LOG (ERR ,"Failed to connect %s: %s\n" , un.sun_path,strerror (errno));
Signature · 1 line
2.39.2
Quoted 6 lines · Stephen Hemminger
In DPDK API's
rte_strlcpy()is not intended to be used directly. It was introduced as a replacement for when operating system libraries were missingstrlcpy(). Over time it appears several drivers and subsystems started using it directly, which is inefficient since the wrapper usessnprintf().
Quoted 9 lines
This series makes sure that the only usage of
rte_strlcpy()is inrte_string_fns.hwhere it is needed.Perhaps checkpatch should warn about other uses?
Stephen Hemminger (2):
lib: replacerte_strlcpy()withstrlcpy()
drivers: don't userte_strlcpy
Tyler Retzlaff
Acked-byQuoted 10 lines · Bruce Richardson
Quoted 9 lines · Stephen Hemminger
In DPDK API's
rte_strlcpy()is not intended to be used directly. It was introduced as a replacement for when operating system libraries were missingstrlcpy(). Over time it appears several drivers and subsystems started using it directly, which is inefficient since the wrapper usessnprintf().This series makes sure that the only usage of
rte_strlcpy()is inrte_string_fns.hwhere it is needed.
Quoted 7 lines
Quoted 6 lines
Perhaps checkpatch should warn about other uses?
Stephen Hemminger (2):
lib: replacerte_strlcpy()withstrlcpy()
drivers: don't userte_strlcpyAcked-by Bruce Richardson <[email protected]>