Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sagi Grimberg <sagi@grimberg.me>
To: Keith Busch <kbusch@kernel.org>
Cc: Maurizio Lombardi <mlombard@redhat.com>,
	Yi Zhang <yi.zhang@redhat.com>,
	"open list:NVM EXPRESS DRIVER" <linux-nvme@lists.infradead.org>,
	Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
	Hannes Reinecke <hare@suse.de>
Subject: Re: blktests nvme 041,042 leak memory
Date: Thu, 30 May 2024 09:59:21 +0300	[thread overview]
Message-ID: <93883147-490d-4065-a741-3e49288ea3af@grimberg.me> (raw)
In-Reply-To: <ZldW7nNrqHCTYTEF@kbusch-mbp.dhcp.thefacebook.com>



On 29/05/2024 19:25, Keith Busch wrote:
> On Wed, May 29, 2024 at 03:51:09PM +0300, Sagi Grimberg wrote:
>> But this is ugly...
> I agree. Could we not work around the device model instead? Once we call
> device_add successfully, we really need to pair that with a device_del.
>
> I see two ways we might be able to do this.
>
> First suggestion: move the device_add to the end so we don't have to
> worry about cleaning up if subsequence actions fail. And auth_init_ctrl
> doesn't appear to have any dependency on the ctrl->device anyway.
>
> ---
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index f5d150c62955d..d86db6a193fcb 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -4675,12 +4675,16 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
>   	if (ret)
>   		goto out_release_instance;
>   
> +	ret = nvme_auth_init_ctrl(ctrl);
> +	if (ret)
> +		goto out_free_name;
> +
>   	nvme_get_ctrl(ctrl);
>   	cdev_init(&ctrl->cdev, &nvme_dev_fops);
>   	ctrl->cdev.owner = ops->module;
>   	ret = cdev_device_add(&ctrl->cdev, ctrl->device);
>   	if (ret)
> -		goto out_free_name;
> +		goto auth_free;
>   
>   	/*
>   	 * Initialize latency tolerance controls.  The sysfs files won't
> @@ -4692,15 +4696,10 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
>   
>   	nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
>   	nvme_mpath_init_ctrl(ctrl);
> -	ret = nvme_auth_init_ctrl(ctrl);
> -	if (ret)
> -		goto out_free_cdev;
>   
>   	return 0;
> -out_free_cdev:
> -	nvme_fault_inject_fini(&ctrl->fault_inject);
> -	dev_pm_qos_hide_latency_tolerance(ctrl->device);
> -	cdev_device_del(&ctrl->cdev, ctrl->device);
> +auth_free:
> +	nvme_auth_free(ctrl);
>   out_free_name:
>   	nvme_put_ctrl(ctrl);
>   	kfree_const(ctrl->device->kobj.name);
> --

Lets just do that... and add a comment that we don't want to add
function calls that can fail post cdev_device_add() because we have a
cleanup problem (with a short explanation), so this is less likely to 
come back...


  parent reply	other threads:[~2024-05-30  6:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-26 19:47 blktests nvme 041,042 leak memory Sagi Grimberg
2024-05-27  1:11 ` Yi Zhang
2024-05-28  9:44   ` Maurizio Lombardi
2024-05-29  9:08     ` Maurizio Lombardi
2024-05-29 12:51       ` Sagi Grimberg
2024-05-29 13:45         ` Maurizio Lombardi
2024-05-29 16:25         ` Keith Busch
2024-05-29 16:48           ` Keith Busch
2024-05-30  6:59           ` Sagi Grimberg [this message]
2024-05-30  7:25             ` Maurizio Lombardi
2024-05-30 16:29               ` Keith Busch
2024-05-30 17:40                 ` Maurizio Lombardi
2024-05-31 11:55                   ` Maurizio Lombardi
2024-05-31 14:37                     ` Maurizio Lombardi
2024-06-03  8:37                       ` Hannes Reinecke
2024-06-03  8:52                         ` Maurizio Lombardi
2024-06-03  9:33                           ` Hannes Reinecke
2024-06-03  9:38                             ` Maurizio Lombardi
2024-06-03  9:35                         ` Maurizio Lombardi

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=93883147-490d-4065-a741-3e49288ea3af@grimberg.me \
    --to=sagi@grimberg.me \
    --cc=hare@suse.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mlombard@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=yi.zhang@redhat.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