Skip to contentSkip to conversation

block: blkdev_get() should acess ->bd_disk only after success

PATCH Applied Tejun Heo 2 participants 2 messages May 31, 2011 – Jun 1, 2011 VFS

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 block: blkdev_get() should acess ->bd_disk only after success

d4dc210f69 (block: don't block events on excl write for non-optical devices) added dereferencing of bdev->bd_disk to test GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE; however, bdev->bd_disk can be %NULL if open failed which can lead to an oops.

Test the flag after testing open was successful, not before.

---
 fs/block_dev.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/block_dev.c +2 -2
index 1f2b199..1a2421f 100644
@@ -1272,8 +1272,8 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
 		 * individual writeable reference is too fragile given the
 		 * way @mode is used in blkdev_get/put().
 		 */
-		if ((disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE) &&
-		    !res && (mode & FMODE_WRITE) && !bdev->bd_write_holder) {
+		if (!res && (mode & FMODE_WRITE) && !bdev->bd_write_holder &&
+		    (disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE)) {
 			bdev->bd_write_holder = true;
 			disk_block_events(disk);
 		}
Applied
#1 lore raw
Quoted 6 lines · Tejun Heo

d4dc210f69 (block: don't block events on excl write for non-optical devices) added dereferencing of bdev->bd_disk to test GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE; however, bdev->bd_disk can be %NULL if open failed which can lead to an oops.

Test the flag after testing open was successful, not before.

Thanks, applied.

Signature · 1 line
Jens Axboe