diff mbox series

[net-next,v4,1/3] net/mlx5e: check return value of rhashtable_init

Message ID 20210927033457.1020967-2-shjy180909@gmail.com (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series check return value of rhashtable_init in mlx5e, ipv6, mac80211 | expand

Commit Message

MichelleJin Sept. 27, 2021, 3:34 a.m. UTC
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>
---

v1->v2:
 - change commit message
 - fix unneeded destroying of ht
v2->v3:
 - nothing changed
v3->v4:
 - nothing changed

 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Roi Dayan Sept. 29, 2021, 11 a.m. UTC | #1
On 2021-09-27 6:34 AM, MichelleJin wrote:
> 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>
> ---
> 
> v1->v2:
>   - change commit message
>   - fix unneeded destroying of ht
> v2->v3:
>   - nothing changed
> v3->v4:
>   - nothing changed
> 
>   drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> index 6c949abcd2e1..225748a9e52a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> @@ -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:
> 

Reviewed-by: Roi Dayan <roid@nvidia.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
index 6c949abcd2e1..225748a9e52a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
@@ -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: