parse_bool() checks errno without resetting it first, and rejects a
value above one with -1 rather than a negative errno. Both arguments
are booleans already stored in a bool, so the local handler adds
nothing over rte_kvargs_handle_bool().

Use rte_kvargs_process_opt(), so that a bare key with no value enables
the option.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 drivers/vdpa/ifc/ifcvf_vdpa.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c
index 508174ad39..8ba011dfed 100644
--- a/drivers/vdpa/ifc/ifcvf_vdpa.c
+++ b/drivers/vdpa/ifc/ifcvf_vdpa.c
@@ -1454,22 +1454,6 @@ static struct rte_vdpa_dev_ops ifcvf_net_ops = {
        .get_dev_type = ifcvf_get_device_type,
 };
 
-static int
-parse_bool(const char *key __rte_unused, const char *value, void *extra_args)
-{
-       char *endp = NULL;
-
-       if (value == NULL || extra_args == NULL || value[0] == '\0')
-               return -EINVAL;
-
-       unsigned long n = strtoul(value, &endp, 0);
-       if (*endp != '\0' || n > 1)
-               return -1;
-
-       *(bool *)extra_args = (n == 1);
-       return 0;
-}
-
 static int16_t
 ifcvf_pci_get_device_type(struct rte_pci_device *pci_dev)
 {
@@ -1636,8 +1620,8 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv 
__rte_unused,
                return 1;
        }
 
-       ret = rte_kvargs_process(kvlist, IFCVF_VDPA_MODE, &parse_bool,
-                       &vdpa_mode);
+       ret = rte_kvargs_process_opt(kvlist, IFCVF_VDPA_MODE,
+                       rte_kvargs_handle_bool, &vdpa_mode);
        if (ret < 0 || !vdpa_mode) {
                rte_kvargs_free(kvlist);
                return 1;
@@ -1730,8 +1714,8 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv 
__rte_unused,
        list->internal = internal;
 
        if (rte_kvargs_count(kvlist, IFCVF_SW_FALLBACK_LM)) {
-               ret = rte_kvargs_process(kvlist, IFCVF_SW_FALLBACK_LM,
-                               &parse_bool, &sw_fallback_lm);
+               ret = rte_kvargs_process_opt(kvlist, IFCVF_SW_FALLBACK_LM,
+                               rte_kvargs_handle_bool, &sw_fallback_lm);
                if (ret < 0)
                        goto error;
        }
-- 
2.53.0

Reply via email to