Replace the open coded errno and end pointer checks in the multi driver and VF queue number handlers.
The VF queue number handler also used base 0, so a leading zero silently selected octal. It is now parsed as a uint16_t, which is the width of the field it feeds, so a value above 65535 is rejected outright rather than warned about; anything in range still warns and returns success, so that a later valid instance of the same argument takes effect. support-multi-driver is a boolean and the field behind it is already a bool, so drop i40e_parse_multi_drv_handler() and point rte_kvargs_handle_bool() at the field. Note that a value other than 0 or 1 used to log a warning and carry on with the default. It now fails the probe, like every other malformed devarg in this series. Signed-off-by: Stephen Hemminger <[email protected]> --- drivers/net/intel/i40e/i40e_ethdev.c | 45 ++++++---------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/drivers/net/intel/i40e/i40e_ethdev.c b/drivers/net/intel/i40e/i40e_ethdev.c index b6b2d291ee..3b17281952 100644 --- a/drivers/net/intel/i40e/i40e_ethdev.c +++ b/drivers/net/intel/i40e/i40e_ethdev.c @@ -14,6 +14,7 @@ #include <assert.h> #include <rte_common.h> +#include <rte_kvargs.h> #include <rte_eal.h> #include <rte_string_fns.h> #include <rte_pci.h> @@ -1267,33 +1268,6 @@ i40e_init_queue_region_conf(struct rte_eth_dev *dev) memset(info, 0, sizeof(struct i40e_queue_regions)); } -static int -i40e_parse_multi_drv_handler(__rte_unused const char *key, - const char *value, - void *opaque) -{ - struct i40e_pf *pf; - unsigned long support_multi_driver; - char *end; - - pf = (struct i40e_pf *)opaque; - - errno = 0; - support_multi_driver = strtoul(value, &end, 10); - if (errno != 0 || end == value || *end != 0) { - PMD_DRV_LOG(WARNING, "Wrong global configuration"); - return -(EINVAL); - } - - if (support_multi_driver == 1 || support_multi_driver == 0) - pf->support_multi_driver = (bool)support_multi_driver; - else - PMD_DRV_LOG(WARNING, "%s must be 1 or 0,", - "enable global configuration by default." - ETH_I40E_SUPPORT_MULTI_DRIVER); - return 0; -} - static int i40e_support_multi_driver(struct rte_eth_dev *dev) { @@ -1322,8 +1296,9 @@ i40e_support_multi_driver(struct rte_eth_dev *dev) "the first invalid or last valid one is used !", ETH_I40E_SUPPORT_MULTI_DRIVER); - if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER, - i40e_parse_multi_drv_handler, pf) < 0) { + if (rte_kvargs_process_opt(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER, + rte_kvargs_handle_bool, + &pf->support_multi_driver) < 0) { rte_kvargs_free(kvlist); return -EINVAL; } @@ -4831,15 +4806,12 @@ static int i40e_pf_parse_vf_queue_number_handler(const char *key, void *opaque) { struct i40e_pf *pf; - unsigned long num; - char *end; + uint64_t num; pf = (struct i40e_pf *)opaque; RTE_SET_USED(key); - errno = 0; - num = strtoul(value, &end, 0); - if (errno != 0 || end == value || *end != 0) { + if (rte_kvargs_to_uint(value, 0, UINT16_MAX, &num) < 0) { PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is " "kept the value = %hu", value, pf->vf_nb_qp_max); return -(EINVAL); @@ -4849,9 +4821,10 @@ static int i40e_pf_parse_vf_queue_number_handler(const char *key, pf->vf_nb_qp_max = (uint16_t)num; else /* here return 0 to make next valid same argument work */ - PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be " + PMD_DRV_LOG(WARNING, "Wrong VF queue number = %hu, it must be " "power of 2 and equal or less than 16 !, Now it is " - "kept the value = %hu", num, pf->vf_nb_qp_max); + "kept the value = %hu", (uint16_t)num, + pf->vf_nb_qp_max); return 0; } -- 2.53.0

