[1/2] common/mlx5: fix miss null check in devargs parsing
Checks
Commit Message
The common MLX5 probe function parses first the devargs and save them in
a dictionary.
It gets structure called "devargs" as a member of EAL device containing
all needed information.
When "devargs" structure is invalid, the function avoids parsing it.
However, when it valid but its field "args" is invalid, the function
tries to parse it and dereference to NULL pointer.
This patch adds check to avoid this NULL dereferencing.
Fixes: a729d2f093e9 ("common/mlx5: refactor devargs management")
Cc: michaelba@nvidia.com
Cc: stable@dpdk.org
Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
drivers/common/mlx5/mlx5_common.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
@@ -164,8 +164,9 @@ mlx5_kvargs_prepare(struct mlx5_kvargs_ctrl *mkvlist,
struct rte_kvargs *kvlist;
uint32_t i;
- if (devargs == NULL)
+ if (mkvlist == NULL)
return 0;
+ MLX5_ASSERT(devargs != NULL && devargs->args != NULL);
kvlist = rte_kvargs_parse(devargs->args, NULL);
if (kvlist == NULL) {
rte_errno = EINVAL;
@@ -400,8 +401,9 @@ parse_class_options(const struct rte_devargs *devargs,
{
int ret = 0;
- if (devargs == NULL)
+ if (mkvlist == NULL)
return 0;
+ MLX5_ASSERT(devargs != NULL);
if (devargs->cls != NULL && devargs->cls->name != NULL)
/* Global syntax, only one class type. */
return class_name_to_value(devargs->cls->name);
@@ -965,7 +967,7 @@ mlx5_common_dev_probe(struct rte_device *eal_dev)
int ret;
DRV_LOG(INFO, "probe device \"%s\".", eal_dev->name);
- if (eal_dev->devargs != NULL)
+ if (eal_dev->devargs != NULL && eal_dev->devargs->args != NULL)
mkvlist_p = &mkvlist;
ret = mlx5_kvargs_prepare(mkvlist_p, eal_dev->devargs);
if (ret < 0) {