Skip to content

Commit 340e845

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: delay freeing the gendisk
blkdev_get_no_open acquires a reference to the block_device through the block device inode and then tries to acquire a device model reference to the gendisk. But at this point the disk migh already be freed (although the race is free). Fix this by only freeing the gendisk from the whole device bdevs ->free_inode callback as well. Fixes: 22ae8ce ("block: simplify bdev/disk lookup in blkdev_get") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 5ab189c commit 340e845

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

block/genhd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,10 +1079,9 @@ static void disk_release(struct device *dev)
10791079
disk_release_events(disk);
10801080
kfree(disk->random);
10811081
xa_destroy(&disk->part_tbl);
1082-
bdput(disk->part0);
10831082
if (test_bit(GD_QUEUE_REF, &disk->state) && disk->queue)
10841083
blk_put_queue(disk->queue);
1085-
kfree(disk);
1084+
bdput(disk->part0); /* frees the disk */
10861085
}
10871086
struct class block_class = {
10881087
.name = "block",

fs/block_dev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ static void bdev_free_inode(struct inode *inode)
812812
free_percpu(bdev->bd_stats);
813813
kfree(bdev->bd_meta_info);
814814

815+
if (!bdev_is_partition(bdev))
816+
kfree(bdev->bd_disk);
815817
kmem_cache_free(bdev_cachep, BDEV_I(inode));
816818
}
817819

0 commit comments

Comments
 (0)