]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/mlx5e: Fix potential null pointer dereference
authorGustavo A. R. Silva <gustavoars@kernel.org>
Fri, 25 Sep 2020 16:49:13 +0000 (11:49 -0500)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 1 Oct 2020 04:26:31 +0000 (21:26 -0700)
Calls to kzalloc() and kvzalloc() should be null-checked
in order to avoid any potential failures. In this case,
a potential null pointer dereference.

Fix this by adding null checks for _parse_attr_ and _flow_
right after allocation.

Addresses-Coverity-ID: 1497154 ("Dereference before null check")
Fixes: a650fb5166d6 ("net/mlx5: Refactor tc flow attributes structure")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

index 186dc29610000f774a57984bd14d520a679a0ca6..a0c356987e1a4d9f235486fe84e3bfc695c5bdab 100644 (file)
@@ -4536,20 +4536,22 @@ mlx5e_alloc_flow(struct mlx5e_priv *priv, int attr_size,
        struct mlx5e_tc_flow_parse_attr *parse_attr;
        struct mlx5_flow_attr *attr;
        struct mlx5e_tc_flow *flow;
-       int out_index, err;
+       int err = -ENOMEM;
+       int out_index;
 
        flow = kzalloc(sizeof(*flow), GFP_KERNEL);
        parse_attr = kvzalloc(sizeof(*parse_attr), GFP_KERNEL);
+       if (!parse_attr || !flow)
+               goto err_free;
 
        flow->flags = flow_flags;
        flow->cookie = f->cookie;
        flow->priv = priv;
 
        attr = mlx5_alloc_flow_attr(get_flow_name_space(flow));
-       if (!parse_attr || !flow || !attr) {
-               err = -ENOMEM;
+       if (!attr)
                goto err_free;
-       }
+
        flow->attr = attr;
 
        for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++)