public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Rahul Rameshbabu <rrameshbabu@nvidia.com>
To: Zhengchao Shao <shaozhengchao@huawei.com>
Cc: <netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
	<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <richardcochran@gmail.com>,
	<saeedm@nvidia.com>, <leon@kernel.org>, <lkayal@nvidia.com>,
	<tariqt@nvidia.com>, <gal@nvidia.com>, <vadfed@meta.com>,
	<ayal@nvidia.com>, <eranbe@nvidia.com>, <weiyongjun1@huawei.com>,
	<yuehaibing@huawei.com>
Subject: Re: [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create
Date: Thu, 29 Jun 2023 11:18:22 -0700	[thread overview]
Message-ID: <874jmqb09d.fsf@nvidia.com> (raw)
In-Reply-To: <20230629024642.2228767-2-shaozhengchao@huawei.com> (Zhengchao Shao's message of "Thu, 29 Jun 2023 10:46:41 +0800")

On Thu, 29 Jun, 2023 10:46:41 +0800 Zhengchao Shao <shaozhengchao@huawei.com> wrote:
> The memory pointed to by the fs->any pointer is not freed in the error
> path of mlx5e_fs_tt_redirect_any_create, which can lead to a memory leak.
> Fix by freeing the memory in the error path, thereby making the error path
> identical to mlx5e_fs_tt_redirect_any_destroy().
>
> Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> index 03cb79adf912..9cf4ec931b8b 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> @@ -594,7 +594,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
>  
>  	err = fs_any_create_table(fs);
>  	if (err)
> -		return err;
> +		goto err_free_any;
>  
>  	err = fs_any_enable(fs);
>  	if (err)
> @@ -606,7 +606,7 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_flow_steering *fs)
>  
>  err_destroy_table:
>  	fs_any_destroy_table(fs_any);
> -
> +err_free_any:
>  	kfree(fs_any);
>  	mlx5e_fs_set_any(fs, NULL);

We probably should update the 'any' member reference in fs to NULL
*before* free-ing fs_any. Otherwise, there is a period in time where fs
is referring to a dirty pointer value in its any member field. It's not
critical, but it makes logical sense in my opinion. Lets swap these two
lines in this patch.

>  	return err;

Thanks for the patch,

-- Rahul Rameshbabu

  parent reply	other threads:[~2023-06-29 18:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-29  2:46 [PATCH net 0/2] fix two memory leak issues for mlx5en driver Zhengchao Shao
2023-06-29  2:46 ` [PATCH net 1/2] net/mlx5e: fix memory leak in mlx5e_fs_tt_redirect_any_create Zhengchao Shao
2023-06-29 12:05   ` Simon Horman
2023-06-29 18:18   ` Rahul Rameshbabu [this message]
2023-06-30  1:27     ` shaozhengchao
2023-06-29  2:46 ` [PATCH net 2/2] net/mlx5e: fix memory leak in mlx5e_ptp_open Zhengchao Shao
2023-06-29  6:08   ` Gal Pressman
2023-06-29  6:23   ` Rahul Rameshbabu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jmqb09d.fsf@nvidia.com \
    --to=rrameshbabu@nvidia.com \
    --cc=ayal@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eranbe@nvidia.com \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lkayal@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=shaozhengchao@huawei.com \
    --cc=tariqt@nvidia.com \
    --cc=vadfed@meta.com \
    --cc=weiyongjun1@huawei.com \
    --cc=yuehaibing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox