Skip to content

Commit 2d2f6f1

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: pre-initialize struct block_device in bdev_alloc_inode
bdev_evict_inode and bdev_free_inode are also called for the root inode of bdevfs, for which bdev_alloc is never called. Move the zeroing o f struct block_device and the initialization of the bd_bdi field into bdev_alloc_inode to make sure they are initialized for the root inode as well. Fixes: e6cb538 ("block: initialize struct block_device in bdev_alloc") Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 04b1ecb commit 2d2f6f1

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

fs/block_dev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,11 @@ static struct kmem_cache * bdev_cachep __read_mostly;
776776
static struct inode *bdev_alloc_inode(struct super_block *sb)
777777
{
778778
struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL);
779+
779780
if (!ei)
780781
return NULL;
782+
memset(&ei->bdev, 0, sizeof(ei->bdev));
783+
ei->bdev.bd_bdi = &noop_backing_dev_info;
781784
return &ei->vfs_inode;
782785
}
783786

@@ -871,14 +874,12 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
871874
mapping_set_gfp_mask(&inode->i_data, GFP_USER);
872875

873876
bdev = I_BDEV(inode);
874-
memset(bdev, 0, sizeof(*bdev));
875877
mutex_init(&bdev->bd_mutex);
876878
mutex_init(&bdev->bd_fsfreeze_mutex);
877879
spin_lock_init(&bdev->bd_size_lock);
878880
bdev->bd_disk = disk;
879881
bdev->bd_partno = partno;
880882
bdev->bd_inode = inode;
881-
bdev->bd_bdi = &noop_backing_dev_info;
882883
#ifdef CONFIG_SYSFS
883884
INIT_LIST_HEAD(&bdev->bd_holder_disks);
884885
#endif

0 commit comments

Comments
 (0)