All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	ZiyangZhang <ZiyangZhang@linux.alibaba.com>,
	Ming Lei <ming.lei@redhat.com>
Subject: [PATCH V4 2/4] ublk_drv: fix ublk device leak in case that add_disk fails
Date: Sat, 30 Jul 2022 17:27:48 +0800	[thread overview]
Message-ID: <20220730092750.1118167-3-ming.lei@redhat.com> (raw)
In-Reply-To: <20220730092750.1118167-1-ming.lei@redhat.com>

->free_disk is only called after disk is added successfully, so
drop ublk device reference in case of add_disk() failure.

Fixes: 6d9e6dfdf3b2 ("ublk: defer disk allocation")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ublk_drv.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 7ece4c2ef062..ae98e81b21ce 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1190,6 +1190,11 @@ static int ublk_ctrl_start_dev(struct io_uring_cmd *cmd)
 	get_device(&ub->cdev_dev);
 	ret = add_disk(disk);
 	if (ret) {
+		/*
+		 * Has to drop the reference since ->free_disk won't be
+		 * called in case of add_disk failure.
+		 */
+		ublk_put_device(ub);
 		put_disk(disk);
 		goto out_unlock;
 	}
-- 
2.31.1


  parent reply	other threads:[~2022-07-30  9:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-30  9:27 [PATCH V4 0/4] ublk_drv: add generic mechanism to get/set parameters Ming Lei
2022-07-30  9:27 ` [PATCH V4 1/4] ublk_drv: cancel device even though disk isn't up Ming Lei
2022-07-30  9:27 ` Ming Lei [this message]
2022-07-30  9:27 ` [PATCH V4 3/4] ublk_drv: add SET_PARAMS/GET_PARAMS control command Ming Lei
2022-07-30  9:27 ` [PATCH V4 4/4] ublk_drv: cleanup ublksrv_ctrl_dev_info Ming Lei
2022-07-30 15:04 ` [PATCH V4 0/4] ublk_drv: add generic mechanism to get/set parameters Jens Axboe
2022-08-01  2:13   ` Ming Lei
2022-07-30 15:04 ` Jens Axboe

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=20220730092750.1118167-3-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=ZiyangZhang@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /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.