parse_bool() only tested errno for ERANGE and ignored the end pointer, so
"1junk" was accepted.
It also stored through an int pointer, but both device arguments are bool
fields, so parsing either wrote four bytes into a one byte object.
The handler did nothing beyond a range checked store of a boolean, so
drop it and pass rte_kvargs_handle_bool() directly, which stores a bool
and also accepts the usual spellings such as "on" and "true".
The booleans use rte_kvargs_process_opt(), so that a bare key with no
value enables the option.
Bugzilla ID: 2042
Fixes: 549343c25db8 ("net/idpf: support device initialization")
Signed-off-by: Stephen Hemminger <[email protected]>
---
drivers/net/intel/idpf/idpf_ethdev.c | 26 +++-----------------------
1 file changed, 3 insertions(+), 23 deletions(-)
diff --git a/drivers/net/intel/idpf/idpf_ethdev.c
b/drivers/net/intel/idpf/idpf_ethdev.c
index c13505416a..6aad5c5008 100644
--- a/drivers/net/intel/idpf/idpf_ethdev.c
+++ b/drivers/net/intel/idpf/idpf_ethdev.c
@@ -3,6 +3,7 @@
*/
#include <rte_atomic.h>
+#include <rte_kvargs.h>
#include <rte_eal.h>
#include <rte_ether.h>
#include <rte_malloc.h>
@@ -1244,27 +1245,6 @@ parse_vport(const char *key, const char *value, void
*args)
return 0;
}
-static int
-parse_bool(const char *key, const char *value, void *args)
-{
- int *i = args;
- char *end;
- int num;
-
- errno = 0;
-
- num = strtoul(value, &end, 10);
-
- if (errno == ERANGE || (num != 0 && num != 1)) {
- PMD_INIT_LOG(ERR, "invalid value:\"%s\" for key:\"%s\", value
must be 0 or 1",
- value, key);
- return -EINVAL;
- }
-
- *i = num;
- return 0;
-}
-
static int
idpf_parse_devargs(struct rte_pci_device *pci_dev, struct idpf_adapter_ext
*adapter,
struct idpf_devargs *idpf_args)
@@ -1307,12 +1287,12 @@ idpf_parse_devargs(struct rte_pci_device *pci_dev,
struct idpf_adapter_ext *adap
if (ret != 0)
goto bail;
- ret = rte_kvargs_process(kvlist, IDPF_TX_SINGLE_Q, &parse_bool,
+ ret = rte_kvargs_process_opt(kvlist, IDPF_TX_SINGLE_Q,
rte_kvargs_handle_bool,
&adapter->base.is_tx_singleq);
if (ret != 0)
goto bail;
- ret = rte_kvargs_process(kvlist, IDPF_RX_SINGLE_Q, &parse_bool,
+ ret = rte_kvargs_process_opt(kvlist, IDPF_RX_SINGLE_Q,
rte_kvargs_handle_bool,
&adapter->base.is_rx_singleq);
if (ret != 0)
goto bail;
--
2.53.0