parse_flag() uses atoi(), which cannot report an error, so a malformed value is silently taken as zero. The result was only ever used as a boolean, so use rte_kvargs_handle_bool() and drop the local handler.
This also accepts the usual spellings such as "on" and "true" in addition to 0 and 1. The boolean uses rte_kvargs_process_opt(), so that a bare key with no value enables the option. Add missing error checking for bad devargs strings. Signed-off-by: Stephen Hemminger <[email protected]> --- drivers/net/octeon_ep/otx_ep_ethdev.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/net/octeon_ep/otx_ep_ethdev.c b/drivers/net/octeon_ep/otx_ep_ethdev.c index ddd3d092c3..959f872b24 100644 --- a/drivers/net/octeon_ep/otx_ep_ethdev.c +++ b/drivers/net/octeon_ep/otx_ep_ethdev.c @@ -32,42 +32,33 @@ static const struct rte_eth_desc_lim otx_ep_tx_desc_lim = { .nb_align = OTX_EP_TXD_ALIGN, }; -static int -parse_flag(const char *key, const char *value, void *extra_args) -{ - RTE_SET_USED(key); - - *(uint8_t *)extra_args = atoi(value); - - return 0; -} - static int otx_ethdev_parse_devargs(struct rte_devargs *devargs, struct otx_ep_device *otx_epvf) { uint8_t max_rings = CN20K_MAX_RINGS_PER_VF; struct rte_kvargs *kvlist; - uint8_t ism_enable = 0; + bool ism_enable = false; + int ret; if (devargs == NULL) goto null_devargs; kvlist = rte_kvargs_parse(devargs->args, NULL); if (kvlist == NULL) - goto exit; + return -EINVAL; - rte_kvargs_process(kvlist, OTX_ISM_ENABLE, &parse_flag, &ism_enable); - rte_kvargs_process(kvlist, OTX_MAX_RINGS, &parse_flag, &max_rings); + ret = rte_kvargs_process_opt(kvlist, OTX_ISM_ENABLE, rte_kvargs_handle_bool, &ism_enable); + ret |= rte_kvargs_process(kvlist, OTX_MAX_RINGS, rte_kvargs_handle_u8, &max_rings); rte_kvargs_free(kvlist); + if (ret != 0) + return -EINVAL; + null_devargs: otx_epvf->ism_ena = !!ism_enable; otx_epvf->sriov_info.rings_per_vf = max_rings; return 0; - -exit: - return -EINVAL; } static void -- 2.53.0

