hns3_parse_dev_caps_mask() does no validation whatsoever: strtoull() is called with neither errno cleared nor the end pointer checked, so "dev_caps_mask=junk" is silently taken as zero and "dev_caps_mask=-1" wraps around to enable every capability.
The value is documented as a hexadecimal mask, so use rte_kvargs_handle_hex64(), which reads it as hexadecimal with or without a 0x prefix. The documented form "dev_caps_mask=0xF" is unchanged, and so is a bare "F". Note that hns3_parse_devargs() discards the rte_kvargs_process() return value for every argument it parses, so a malformed mask is now reported but still leaves the default of zero in place rather than failing probe. Propagating those errors is a behaviour change per argument and is left for a separate patch. HNS3_CONVERT_TO_HEXADECIMAL loses its last user here, and HNS3_CONVERT_TO_DECIMAL lost its own earlier in this series, so remove both. Signed-off-by: Stephen Hemminger <[email protected]> --- drivers/net/hns3/hns3_common.c | 18 +----------------- drivers/net/hns3/hns3_common.h | 3 --- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c index c21740ba5e..35cc3fca40 100644 --- a/drivers/net/hns3/hns3_common.c +++ b/drivers/net/hns3/hns3_common.c @@ -205,22 +205,6 @@ hns3_get_io_hint_func_name(uint32_t hint) } } -static int -hns3_parse_dev_caps_mask(const char *key, const char *value, void *extra_args) -{ - uint64_t val; - - RTE_SET_USED(key); - - if (value == NULL || extra_args == NULL) - return 0; - - val = strtoull(value, NULL, HNS3_CONVERT_TO_HEXADECIMAL); - *(uint64_t *)extra_args = val; - - return 0; -} - static int hns3_parse_mbx_time_limit(const char *key, const char *value, void *extra_args) { @@ -341,7 +325,7 @@ hns3_parse_devargs(struct rte_eth_dev *dev) (void)rte_kvargs_process(kvlist, HNS3_DEVARG_TX_FUNC_HINT, &hns3_parse_io_hint_func, &tx_func_hint); (void)rte_kvargs_process(kvlist, HNS3_DEVARG_DEV_CAPS_MASK, - &hns3_parse_dev_caps_mask, &dev_caps_mask); + rte_kvargs_handle_hex64, &dev_caps_mask); (void)rte_kvargs_process(kvlist, HNS3_DEVARG_MBX_TIME_LIMIT_MS, &hns3_parse_mbx_time_limit, &mbx_time_limit_ms); if (!hns->is_vf) { diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h index 7b3f96b01a..967cde9e39 100644 --- a/drivers/net/hns3/hns3_common.h +++ b/drivers/net/hns3/hns3_common.h @@ -9,9 +9,6 @@ #include "hns3_ethdev.h" -#define HNS3_CONVERT_TO_DECIMAL 10 -#define HNS3_CONVERT_TO_HEXADECIMAL 16 - enum { HNS3_IO_FUNC_HINT_NONE = 0, HNS3_IO_FUNC_HINT_VEC, -- 2.53.0

