mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wu Bo <wubo40@huawei.com>
To: <axboe@kernel.dk>
Cc: <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linfeilong@huawei.com>, <wubo40@huawei.com>
Subject: [PATCH 1/2] brd: add error handling support for add_disk()
Date: Thu, 4 Nov 2021 16:33:18 +0800	[thread overview]
Message-ID: <1636014799-20156-2-git-send-email-wubo40@huawei.com> (raw)
In-Reply-To: <1636014799-20156-1-git-send-email-wubo40@huawei.com>

We never checked for errors on add_disk() as this function
returned void. Now that is fixed. 

So add error handling support for add_disk().

Signed-off-by: Wu Bo <wubo40@huawei.com>
---
 drivers/block/brd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index aa04727..34a0d9c 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -370,6 +370,7 @@ static int brd_alloc(int i)
 	struct brd_device *brd;
 	struct gendisk *disk;
 	char buf[DISK_NAME_LEN];
+	int err;
 
 	mutex_lock(&brd_devices_mutex);
 	list_for_each_entry(brd, &brd_devices, brd_list) {
@@ -420,10 +421,14 @@ static int brd_alloc(int i)
 	/* Tell the block layer that this is not a rotational device */
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
 	blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue);
-	add_disk(disk);
+	err = add_disk(disk);
+	if (err)
+		goto out_cleanup_disk;
 
 	return 0;
 
+out_cleanup_disk:
+	blk_cleanup_disk(disk);
 out_free_dev:
 	mutex_lock(&brd_devices_mutex);
 	list_del(&brd->brd_list);
-- 
1.8.3.1


  reply	other threads:[~2021-11-04  8:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04  8:33 [PATCH 0/2] " Wu Bo
2021-11-04  8:33 ` Wu Bo [this message]
2021-11-04  8:33 ` [PATCH 2/2] z2ram: " Wu Bo
2021-11-04  8:45 ` [PATCH 0/2] " Christoph Hellwig
2021-11-05  2:06   ` Wu Bo

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=1636014799-20156-2-git-send-email-wubo40@huawei.com \
    --to=wubo40@huawei.com \
    --cc=axboe@kernel.dk \
    --cc=linfeilong@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®