linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Sagi Grimberg <sagi@grimberg.me>
Cc: linux-nvme@lists.infradead.org, Christoph Hellwig <hch@lst.de>,
	Keith Busch <kbusch@kernel.org>,
	Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>,
	Irvin Cote <irvincoteg@gmail.com>
Subject: Re: [PATCH] nvme: Fix memory leak in nvme_init_ctrl error path
Date: Fri, 12 May 2023 17:07:09 +0200	[thread overview]
Message-ID: <20230512150709.GC6005@lst.de> (raw)
In-Reply-To: <20230503150925.863308-1-sagi@grimberg.me>

On Wed, May 03, 2023 at 06:09:25PM +0300, Sagi Grimberg wrote:
> -	if (!ctrl->discard_page) {
> -		ret = -ENOMEM;
> -		goto out;
> -	}
> +	if (!ctrl->discard_page)
> +		return -ENOMEM;

Can we please pre-load these cleanups in a separate patch?

> -out:
> -	if (ctrl->discard_page)
> -		__free_page(ctrl->discard_page);
> +	ctrl->instance = NVME_CTRL_INSTANCE_UNINITIALIZED;
> +	/* pairs with device_initialize .release method will cleanup */
> +	nvme_put_ctrl(ctrl);

Err, no.  We should not go through .release with a partial 
initialization.  Please do proper unwinding before the device
is added, and make sure everything is in a proper state by the
time ->release can be called.

>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(nvme_init_ctrl);
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index bf46f122e9e1..920403589670 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -255,6 +255,7 @@ struct nvme_ctrl {
>  	struct request_queue *connect_q;
>  	struct request_queue *fabrics_q;
>  	struct device *dev;
> +#define NVME_CTRL_INSTANCE_UNINITIALIZED (-1)
>  	int instance;
>  	int numa_node;
>  	struct blk_mq_tag_set *tagset;
> -- 
> 2.34.1
---end quoted text---


  parent reply	other threads:[~2023-05-12 15:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-03 15:09 [PATCH] nvme: Fix memory leak in nvme_init_ctrl error path Sagi Grimberg
2023-05-04  5:23 ` Chaitanya Kulkarni
2023-05-04  8:18   ` Sagi Grimberg
2023-05-05  1:17     ` Chaitanya Kulkarni
2023-05-06  3:12 ` Yi Zhang
2023-05-12 15:07 ` Christoph Hellwig [this message]
2023-05-17  7:08   ` Sagi Grimberg

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=20230512150709.GC6005@lst.de \
    --to=hch@lst.de \
    --cc=Chaitanya.Kulkarni@wdc.com \
    --cc=irvincoteg@gmail.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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;
as well as URLs for NNTP newsgroup(s).