mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net/mlx5e: Cleanup error handle in mlx5e_tc_sample_init()
@ 2025-06-25 10:20 Yue Haibing
  2025-07-21  7:33 ` Yue Haibing
  0 siblings, 1 reply; 2+ messages in thread
From: Yue Haibing @ 2025-06-25 10:20 UTC (permalink / raw)
  To: saeedm, leon, tariqt, andrew+netdev, davem, edumazet, kuba,
	pabeni, yuehaibing
  Cc: netdev, linux-rdma, linux-kernel

post_act is initialized in mlx5e_tc_post_act_init(), which never return
NULL. And if it is invalid, no need to alloc tc_psample mem.

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
 .../ethernet/mellanox/mlx5/core/en/tc/sample.c   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
index 5db239cae814..1b083afbe1bc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
@@ -619,26 +619,30 @@ mlx5e_tc_sample_init(struct mlx5_eswitch *esw, struct mlx5e_post_act *post_act)
 	struct mlx5e_tc_psample *tc_psample;
 	int err;
 
-	tc_psample = kzalloc(sizeof(*tc_psample), GFP_KERNEL);
-	if (!tc_psample)
-		return ERR_PTR(-ENOMEM);
-	if (IS_ERR_OR_NULL(post_act)) {
+	if (IS_ERR(post_act)) {
 		err = PTR_ERR(post_act);
 		goto err_post_act;
 	}
+
+	tc_psample = kzalloc(sizeof(*tc_psample), GFP_KERNEL);
+	if (!tc_psample) {
+		err = -ENOMEM;
+		goto err_post_act;
+	}
 	tc_psample->post_act = post_act;
 	tc_psample->esw = esw;
 	err = sampler_termtbl_create(tc_psample);
 	if (err)
-		goto err_post_act;
+		goto err_create;
 
 	mutex_init(&tc_psample->ht_lock);
 	mutex_init(&tc_psample->restore_lock);
 
 	return tc_psample;
 
-err_post_act:
+err_create:
 	kfree(tc_psample);
+err_post_act:
 	return ERR_PTR(err);
 }
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net/mlx5e: Cleanup error handle in mlx5e_tc_sample_init()
  2025-06-25 10:20 [PATCH net-next] net/mlx5e: Cleanup error handle in mlx5e_tc_sample_init() Yue Haibing
@ 2025-07-21  7:33 ` Yue Haibing
  0 siblings, 0 replies; 2+ messages in thread
From: Yue Haibing @ 2025-07-21  7:33 UTC (permalink / raw)
  To: saeedm, leon, tariqt, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-rdma, linux-kernel

ping...

On 2025/6/25 18:20, Yue Haibing wrote:
> post_act is initialized in mlx5e_tc_post_act_init(), which never return
> NULL. And if it is invalid, no need to alloc tc_psample mem.
> 
> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
> ---
>  .../ethernet/mellanox/mlx5/core/en/tc/sample.c   | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
> index 5db239cae814..1b083afbe1bc 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
> @@ -619,26 +619,30 @@ mlx5e_tc_sample_init(struct mlx5_eswitch *esw, struct mlx5e_post_act *post_act)
>  	struct mlx5e_tc_psample *tc_psample;
>  	int err;
>  
> -	tc_psample = kzalloc(sizeof(*tc_psample), GFP_KERNEL);
> -	if (!tc_psample)
> -		return ERR_PTR(-ENOMEM);
> -	if (IS_ERR_OR_NULL(post_act)) {
> +	if (IS_ERR(post_act)) {
>  		err = PTR_ERR(post_act);
>  		goto err_post_act;
>  	}
> +
> +	tc_psample = kzalloc(sizeof(*tc_psample), GFP_KERNEL);
> +	if (!tc_psample) {
> +		err = -ENOMEM;
> +		goto err_post_act;
> +	}
>  	tc_psample->post_act = post_act;
>  	tc_psample->esw = esw;
>  	err = sampler_termtbl_create(tc_psample);
>  	if (err)
> -		goto err_post_act;
> +		goto err_create;
>  
>  	mutex_init(&tc_psample->ht_lock);
>  	mutex_init(&tc_psample->restore_lock);
>  
>  	return tc_psample;
>  
> -err_post_act:
> +err_create:
>  	kfree(tc_psample);
> +err_post_act:
>  	return ERR_PTR(err);
>  }
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-21  7:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-25 10:20 [PATCH net-next] net/mlx5e: Cleanup error handle in mlx5e_tc_sample_init() Yue Haibing
2025-07-21  7:33 ` Yue Haibing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®