From: Simon Horman <simon.horman@corigine.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, valex@nvidia.com, kliteyn@nvidia.com,
mbloch@nvidia.com, danielj@nvidia.com, erezsh@mellanox.com,
saeedm@nvidia.com, leon@kernel.org, weiyongjun1@huawei.com,
yuehaibing@huawei.com
Subject: Re: [PATCH net] net/mlx5: DR, fix memory leak in mlx5dr_cmd_create_reformat_ctx
Date: Tue, 4 Jul 2023 15:40:44 +0100 [thread overview]
Message-ID: <ZKQvbCkdeVWWCzEw@corigine.com> (raw)
In-Reply-To: <20230704033308.3773764-1-shaozhengchao@huawei.com>
On Tue, Jul 04, 2023 at 11:33:08AM +0800, Zhengchao Shao wrote:
> when mlx5_cmd_exec failed in mlx5dr_cmd_create_reformat_ctx, the memory
> pointed by 'in' is not released, which will cause memory leak. Move memory
> release after mlx5_cmd_exec.
>
> Fixes: 1d9186476e12 ("net/mlx5: DR, Add direct rule command utilities")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
> index 7491911ebcb5..cf5820744e99 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
> @@ -563,11 +563,11 @@ int mlx5dr_cmd_create_reformat_ctx(struct mlx5_core_dev *mdev,
> memcpy(pdata, reformat_data, reformat_size);
>
> err = mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
> + kvfree(in);
> if (err)
> return err;
>
> *reformat_id = MLX5_GET(alloc_packet_reformat_context_out, out, packet_reformat_id);
> - kvfree(in);
>
> return err;
> }
Hi Zhengchao Shao,
I agree this is a correct fix.
However, I think a more idiomatic approach to this problem
would be to use a goto label. Something like this (completely untested!).
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
index 7491911ebcb5..8c2a34a0d6be 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
@@ -564,11 +564,12 @@ int mlx5dr_cmd_create_reformat_ctx(struct mlx5_core_dev *mdev,
err = mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
if (err)
- return err;
+ goto err_free_in;
*reformat_id = MLX5_GET(alloc_packet_reformat_context_out, out, packet_reformat_id);
- kvfree(in);
+err_free_in:
+ kvfree(in);
return err;
}
next prev parent reply other threads:[~2023-07-04 14:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 3:33 [PATCH net] net/mlx5: DR, fix memory leak in mlx5dr_cmd_create_reformat_ctx Zhengchao Shao
2023-07-04 14:40 ` Simon Horman [this message]
2023-07-05 8:23 ` Leon Romanovsky
2023-07-05 11:51 ` shaozhengchao
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=ZKQvbCkdeVWWCzEw@corigine.com \
--to=simon.horman@corigine.com \
--cc=danielj@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=erezsh@mellanox.com \
--cc=kliteyn@nvidia.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=shaozhengchao@huawei.com \
--cc=valex@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.