net/mlx5e: check return value of rhashtable_init
authorMichelleJin <shjy180909@gmail.com>
Mon, 27 Sep 2021 03:34:55 +0000 (03:34 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 28 Sep 2021 11:59:24 +0000 (12:59 +0100)
When rhashtable_init() fails, it returns -EINVAL.
However, since error return value of rhashtable_init is not checked,
it can cause use of uninitialized pointers.
So, fix unhandled errors of rhashtable_init.

Signed-off-by: MichelleJin <shjy180909@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c

index 6c949ab..225748a 100644 (file)
@@ -2127,12 +2127,20 @@ mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
 
        ct_priv->post_act = post_act;
        mutex_init(&ct_priv->control_lock);
-       rhashtable_init(&ct_priv->zone_ht, &zone_params);
-       rhashtable_init(&ct_priv->ct_tuples_ht, &tuples_ht_params);
-       rhashtable_init(&ct_priv->ct_tuples_nat_ht, &tuples_nat_ht_params);
+       if (rhashtable_init(&ct_priv->zone_ht, &zone_params))
+               goto err_ct_zone_ht;
+       if (rhashtable_init(&ct_priv->ct_tuples_ht, &tuples_ht_params))
+               goto err_ct_tuples_ht;
+       if (rhashtable_init(&ct_priv->ct_tuples_nat_ht, &tuples_nat_ht_params))
+               goto err_ct_tuples_nat_ht;
 
        return ct_priv;
 
+err_ct_tuples_nat_ht:
+       rhashtable_destroy(&ct_priv->ct_tuples_ht);
+err_ct_tuples_ht:
+       rhashtable_destroy(&ct_priv->zone_ht);
+err_ct_zone_ht:
 err_ct_nat_tbl:
        mlx5_chains_destroy_global_table(chains, ct_priv->ct);
 err_ct_tbl: