From: Paolo Abeni <pabeni@redhat.com>
To: Jianglei Nie <niejianglei2021@163.com>,
saeedm@nvidia.com, leon@kernel.org, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, parav@nvidia.com,
vuhuong@nvidia.com, shayd@nvidia.com
Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/mlx5: Fix memory leak in mlx5_sf_dev_add()
Date: Thu, 26 May 2022 13:14:20 +0200 [thread overview]
Message-ID: <5a7cb5c7c0bf2f9f9540616a2a0e70d36a166a9f.camel@redhat.com> (raw)
In-Reply-To: <20220526084411.480472-1-niejianglei2021@163.com>
On Thu, 2022-05-26 at 16:44 +0800, Jianglei Nie wrote:
> The variable id is allocated by mlx5_adev_idx_alloc(). When some error
> happens, the id should be freed by mlx5_adev_idx_free().But when
> auxiliary_device_add() and xa_insert() fail, the id is not freed,which
> will lead to a potential memory leak.
>
> We can fix it by calling mlx5_sf_dev_add() when auxiliary_device_add()
> and xa_insert() fail.
>
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
> index 7da012ff0d41..9f222061a1c0 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
> @@ -125,13 +125,16 @@ static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u16 fn_id,
>
> err = auxiliary_device_add(&sf_dev->adev);
> if (err) {
> + mlx5_adev_idx_free(id);
> put_device(&sf_dev->adev.dev);
This looks not correct. put_device() -> mlx5_sf_dev_release() -> should
already take care of that.
> goto add_err;
> }
>
> err = xa_insert(&table->devices, sf_index, sf_dev, GFP_KERNEL);
> - if (err)
> + if (err) {
> + mlx5_adev_idx_free(id);
> goto xa_err;
> + }
> return;
>
> xa_err:
next prev parent reply other threads:[~2022-05-26 11:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-26 8:44 Jianglei Nie
2022-05-26 11:14 ` Paolo Abeni [this message]
2022-05-26 12:39 ` Parav Pandit
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=5a7cb5c7c0bf2f9f9540616a2a0e70d36a166a9f.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=niejianglei2021@163.com \
--cc=parav@nvidia.com \
--cc=saeedm@nvidia.com \
--cc=shayd@nvidia.com \
--cc=vuhuong@nvidia.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
all inboxes | Powered by JetHome®