From: Jan Kara <jack@suse.cz>
To: Jens Axboe <axboe@kernel.dk>
Cc: Tejun Heo <tj@kernel.org>,
linux-block@vger.kernel.org,
Dan Williams <dan.j.williams@intel.com>,
Omar Sandoval <osandov@osandov.com>,
Arthur Marsh <arthur.marsh@internode.on.net>,
linux-scsi@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: [PATCH 3/4] block: Make del_gendisk() safer for disks without queues
Date: Thu, 9 Mar 2017 11:16:23 +0100 [thread overview]
Message-ID: <20170309101624.25901-4-jack@suse.cz> (raw)
In-Reply-To: <20170309101624.25901-1-jack@suse.cz>
Commit 165a5e22fafb "block: Move bdi_unregister() to del_gendisk()"
added disk->queue dereference to del_gendisk(). Although del_gendisk()
is not supposed to be called without disk->queue valid and
blk_unregister_queue() warns in that case, this change will make it oops
instead. Return to the old more robust behavior of just warning when
del_gendisk() gets called for gendisk with disk->queue being NULL.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Tested-by: Omar Sandoval <osandov@fb.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
block/genhd.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index b26a5ea115d0..94f323842b52 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -681,12 +681,16 @@ void del_gendisk(struct gendisk *disk)
disk->flags &= ~GENHD_FL_UP;
sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
- /*
- * Unregister bdi before releasing device numbers (as they can get
- * reused and we'd get clashes in sysfs).
- */
- bdi_unregister(disk->queue->backing_dev_info);
- blk_unregister_queue(disk);
+ if (disk->queue) {
+ /*
+ * Unregister bdi before releasing device numbers (as they can
+ * get reused and we'd get clashes in sysfs).
+ */
+ bdi_unregister(disk->queue->backing_dev_info);
+ blk_unregister_queue(disk);
+ } else {
+ WARN_ON(1);
+ }
blk_unregister_region(disk_devt(disk), disk->minors);
part_stat_set_all(&disk->part0, 0);
--
2.10.2
next prev parent reply other threads:[~2017-03-09 10:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 10:16 [PATCH 0/4 v2] block: Fixes for bdi handling Jan Kara
2017-03-09 10:16 ` [PATCH 1/4] block: Allow bdi re-registration Jan Kara
2017-03-09 16:39 ` Tejun Heo
2017-03-09 10:16 ` [PATCH 2/4] bdi: Fix use-after-free in wb_congested_put() Jan Kara
2017-03-09 10:16 ` Jan Kara [this message]
2017-03-09 10:16 ` [PATCH 4/4] Revert "scsi, block: fix duplicate bdi name registration crashes" Jan Kara
2017-03-09 16:41 ` [PATCH 0/4 v2] block: Fixes for bdi handling Jens Axboe
2017-03-10 10:22 ` Jan Kara
2017-03-11 22:27 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2017-03-08 16:48 [PATCH 0/4] " Jan Kara
2017-03-08 16:48 ` [PATCH 3/4] block: Make del_gendisk() safer for disks without queues Jan Kara
2017-03-08 22:57 ` Tejun Heo
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=20170309101624.25901-4-jack@suse.cz \
--to=jack@suse.cz \
--cc=arthur.marsh@internode.on.net \
--cc=axboe@kernel.dk \
--cc=dan.j.williams@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=osandov@osandov.com \
--cc=tj@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