public inbox for linux-block@vger.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, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 1/2] ublk_drv: move destroying device out of ublk_add_dev
Date: Fri, 22 Jul 2022 10:36:37 +0800	[thread overview]
Message-ID: <20220722023638.601667-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20220722023638.601667-1-ming.lei@redhat.com>

ublk_device is allocated in ublk_ctrl_add_dev(), so code will become more
readable by just letting ublk_ctrl_add_dev() destroy ublk_device in case
of ublk_add_dev() failure.

Meantime ub->mutex is destroyed in __ublk_destroy_dev(), but it may
not be initialized when ublk_add_dev() fails, so fix it by moving
mutex_init(ub->mutex) before any failure path.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ublk_drv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index f058f40b639c..d03563286c76 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1106,9 +1106,10 @@ static int ublk_add_dev(struct ublk_device *ub)
 
 	INIT_WORK(&ub->stop_work, ublk_stop_work_fn);
 	INIT_DELAYED_WORK(&ub->monitor_work, ublk_daemon_monitor_work);
+	mutex_init(&ub->mutex);
 
 	if (ublk_init_queues(ub))
-		goto out_destroy_dev;
+		return err;
 
 	ub->tag_set.ops = &ublk_mq_ops;
 	ub->tag_set.nr_hw_queues = ub->dev_info.nr_hw_queues;
@@ -1122,7 +1123,6 @@ static int ublk_add_dev(struct ublk_device *ub)
 		goto out_deinit_queues;
 
 	ublk_align_max_io_size(ub);
-	mutex_init(&ub->mutex);
 	spin_lock_init(&ub->mm_lock);
 
 	/* add char dev so that ublksrv daemon can be setup */
@@ -1130,8 +1130,6 @@ static int ublk_add_dev(struct ublk_device *ub)
 
 out_deinit_queues:
 	ublk_deinit_queues(ub);
-out_destroy_dev:
-	__ublk_destroy_dev(ub);
 	return err;
 }
 
@@ -1331,8 +1329,10 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
 	ub->dev_info.dev_id = ub->ub_number;
 
 	ret = ublk_add_dev(ub);
-	if (ret)
+	if (ret) {
+		__ublk_destroy_dev(ub);
 		goto out_unlock;
+	}
 
 	if (copy_to_user(argp, &ub->dev_info, sizeof(info))) {
 		ublk_remove(ub);
-- 
2.31.1


  reply	other threads:[~2022-07-22  2:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22  2:36 [PATCH 0/2] ublk_drv: make sure that correct flags(features) returned to userspace Ming Lei
2022-07-22  2:36 ` Ming Lei [this message]
2022-07-22  2:58   ` [PATCH 1/2] ublk_drv: move destroying device out of ublk_add_dev Ziyang Zhang
2022-07-22  3:28     ` Ming Lei
2022-07-22  2:36 ` [PATCH 2/2] ublk_drv: make sure that correct flags(features) returned to userspace Ming Lei
2022-07-22  3:04   ` Ziyang Zhang

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=20220722023638.601667-2-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox