Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: e6cb53827ed6 ("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>

authored by

Christoph Hellwig and committed by
Jens Axboe
2d2f6f1b 04b1ecb6

+3 -2
+3 -2
fs/block_dev.c
··· 776 776 static struct inode *bdev_alloc_inode(struct super_block *sb) 777 777 { 778 778 struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL); 779 + 779 780 if (!ei) 780 781 return NULL; 782 + memset(&ei->bdev, 0, sizeof(ei->bdev)); 783 + ei->bdev.bd_bdi = &noop_backing_dev_info; 781 784 return &ei->vfs_inode; 782 785 } 783 786 ··· 874 871 mapping_set_gfp_mask(&inode->i_data, GFP_USER); 875 872 876 873 bdev = I_BDEV(inode); 877 - memset(bdev, 0, sizeof(*bdev)); 878 874 mutex_init(&bdev->bd_mutex); 879 875 mutex_init(&bdev->bd_fsfreeze_mutex); 880 876 spin_lock_init(&bdev->bd_size_lock); 881 877 bdev->bd_disk = disk; 882 878 bdev->bd_partno = partno; 883 879 bdev->bd_inode = inode; 884 - bdev->bd_bdi = &noop_backing_dev_info; 885 880 #ifdef CONFIG_SYSFS 886 881 INIT_LIST_HEAD(&bdev->bd_holder_disks); 887 882 #endif