parse_u32() open codes the errno, end pointer and range checks that the helper does.
parse_tx_sched_levels() assigns before validating and uses base 0, so a leading zero silently selects octal. handle_field_offs_arg() converts with atoi(), which reports no error. Convert with rte_kvargs_to_int() instead. The range starts at zero, which keeps the old isdigit() rejection of a negative value: -1 is used internally to mean that no extraction field is configured. hw_debug_mask is a bare hexadecimal mask, so use rte_kvargs_handle_hex64() for it rather than a decimal handler. The five boolean arguments each went through parse_bool(), which the typed handler replaces. A bare key such as "safe-mode-support" now enables the option, and the usual spellings are accepted. Signed-off-by: Stephen Hemminger <[email protected]> --- drivers/net/intel/ice/ice_ethdev.c | 112 +++++++---------------------- 1 file changed, 26 insertions(+), 86 deletions(-) diff --git a/drivers/net/intel/ice/ice_ethdev.c b/drivers/net/intel/ice/ice_ethdev.c index 3de9840e7c..8dc1483883 100644 --- a/drivers/net/intel/ice/ice_ethdev.c +++ b/drivers/net/intel/ice/ice_ethdev.c @@ -8,6 +8,7 @@ #include <ctype.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> @@ -15,6 +16,7 @@ #include <math.h> #include <rte_tailq.h> +#include <rte_kvargs.h> #include <rte_os_shim.h> #include "eal_firmware.h" @@ -759,18 +761,20 @@ handle_proto_xtr_arg(__rte_unused const char *key, const char *value, } static int -handle_field_offs_arg(__rte_unused const char *key, const char *value, - void *offs_args) +handle_field_offs_arg(const char *key, const char *value, void *offs_args) { - int *offset = offs_args; + int64_t offset; - if (value == NULL || offs_args == NULL) + if (offs_args == NULL) return -EINVAL; - if (!isdigit(*value)) - return -1; + /* A negative offset is reserved: -1 means no field is configured. */ + if (rte_kvargs_to_int(value, 0, INT_MAX, &offset) < 0) { + PMD_DRV_LOG(ERR, "Invalid %s, must be a non-negative offset", key); + return -EINVAL; + } - *offset = atoi(value); + *(int *)offs_args = offset; return 0; } @@ -2169,83 +2173,19 @@ ice_base_queue_get(struct ice_pf *pf) } } -static int -parse_bool(const char *key, const char *value, void *args) -{ - bool *i = args; - - if (value == NULL || value[0] == '\0') { - PMD_DRV_LOG(WARNING, "key:\"%s\", requires a value, which must be 0 or 1", key); - return -1; - } - if (value[1] != '\0' || (value[0] != '0' && value[0] != '1')) { - PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", value must be 0 or 1", - value, key); - return -1; - } - - *i = (value[0] == '1'); - return 0; -} - -static int -parse_u64(const char *key, const char *value, void *args) -{ - u64 *num = (u64 *)args; - u64 tmp; - - errno = 0; - tmp = strtoull(value, NULL, 16); - if (errno) { - PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u64", - key, value); - return -1; - } - - *num = tmp; - - return 0; -} - -static int -parse_u32(const char *key, const char *value, void *args) -{ - uint32_t *num = args; - unsigned long tmp; - char *endptr; - - errno = 0; - tmp = strtoul(value, &endptr, 0); - if (errno != 0 || endptr == value || *endptr != '\0') { - PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u32", key, value); - return -1; - } - if (tmp > UINT32_MAX) { - PMD_DRV_LOG(WARNING, "%s: value \"%s\" is out of range", key, value); - return -1; - } - - *num = (uint32_t)tmp; - - return 0; -} - static int parse_tx_sched_levels(const char *key, const char *value, void *args) { uint8_t *num = args; - long tmp; - char *endptr; + uint64_t tmp; - errno = 0; - tmp = strtol(value, &endptr, 0); /* the value needs two stage validation, since the actual number of available * levels is not known at this point. Initially just validate that it is in * the correct range, between 3 and 8. Later validation will check that the * available layers on a particular port is higher than the value specified here. */ - if (errno || *endptr != '\0' || - tmp < (ICE_VSI_LAYER_OFFSET - 1) || tmp >= ICE_TM_MAX_LAYERS) { + if (rte_kvargs_to_uint(value, ICE_VSI_LAYER_OFFSET - 1, + ICE_TM_MAX_LAYERS - 1, &tmp) < 0) { PMD_DRV_LOG(WARNING, "%s: Invalid value \"%s\", should be in range [%d, %d]", key, value, ICE_VSI_LAYER_OFFSET - 1, ICE_TM_MAX_LAYERS - 1); return -1; @@ -2486,18 +2426,18 @@ static int ice_parse_devargs(struct rte_eth_dev *dev) if (ret) goto bail; - ret = rte_kvargs_process(kvlist, ICE_SAFE_MODE_SUPPORT_ARG, - &parse_bool, &ad->devargs.safe_mode_support); + ret = rte_kvargs_process_opt(kvlist, ICE_SAFE_MODE_SUPPORT_ARG, + rte_kvargs_handle_bool, &ad->devargs.safe_mode_support); if (ret) goto bail; - ret = rte_kvargs_process(kvlist, ICE_DEFAULT_MAC_DISABLE, - &parse_bool, &ad->devargs.default_mac_disable); + ret = rte_kvargs_process_opt(kvlist, ICE_DEFAULT_MAC_DISABLE, + rte_kvargs_handle_bool, &ad->devargs.default_mac_disable); if (ret) goto bail; ret = rte_kvargs_process(kvlist, ICE_HW_DEBUG_MASK_ARG, - &parse_u64, &ad->hw.debug_mask); + rte_kvargs_handle_hex64, &ad->hw.debug_mask); if (ret) goto bail; @@ -2511,8 +2451,8 @@ static int ice_parse_devargs(struct rte_eth_dev *dev) if (ret) goto bail; - ret = rte_kvargs_process(kvlist, ICE_RX_LOW_LATENCY_ARG, - &parse_bool, &ad->devargs.rx_low_latency); + ret = rte_kvargs_process_opt(kvlist, ICE_RX_LOW_LATENCY_ARG, + rte_kvargs_handle_bool, &ad->devargs.rx_low_latency); if (ret) goto bail; @@ -2521,8 +2461,8 @@ static int ice_parse_devargs(struct rte_eth_dev *dev) if (ret) goto bail; - ret = rte_kvargs_process(kvlist, ICE_DDP_LOAD_SCHED_ARG, - &parse_bool, &ad->devargs.ddp_load_sched); + ret = rte_kvargs_process_opt(kvlist, ICE_DDP_LOAD_SCHED_ARG, + rte_kvargs_handle_bool, &ad->devargs.ddp_load_sched); if (ret) goto bail; @@ -2532,12 +2472,12 @@ static int ice_parse_devargs(struct rte_eth_dev *dev) goto bail; ret = rte_kvargs_process(kvlist, ICE_RL_BURST_SIZE_ARG, - &parse_u32, &ad->devargs.rl_burst_size); + rte_kvargs_handle_u32, &ad->devargs.rl_burst_size); if (ret) goto bail; - ret = rte_kvargs_process(kvlist, ICE_SOURCE_PRUNE_ARG, - &parse_bool, &ad->devargs.source_prune); + ret = rte_kvargs_process_opt(kvlist, ICE_SOURCE_PRUNE_ARG, + rte_kvargs_handle_bool, &ad->devargs.source_prune); if (ret) goto bail; -- 2.53.0

