We don't need bdev->bd_inode as we know the layout, they are stored in the same structure and so offset_of is enough. Convert extra dereferencing to offseting starting from the block layer. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- block/fops.c | 10 ++++++---- include/linux/blkdev.h | 15 ++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/block/fops.c b/block/fops.c index 99e699427f31..5438ed9cfcf7 100644 --- a/block/fops.c +++ b/block/fops.c @@ -17,14 +17,16 @@ #include <linux/fs.h> #include "blk.h" -static inline struct inode *bdev_file_inode(struct file *file) +static inline struct block_device *blkdev_get_bdev(struct file *file) { - return file->f_mapping->host; + return file->private_data; } -static inline struct block_device *blkdev_get_bdev(struct file *file) +static inline struct inode *bdev_file_inode(struct file *file) { - return file->private_data; + struct block_device *bdev = blkdev_get_bdev(file); + + return bdev_get_inode(bdev); } static int blkdev_get_block(struct inode *inode, sector_t iblock, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 591f14522f78..a56f3a852206 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1139,11 +1139,6 @@ static inline unsigned int blksize_bits(unsigned int size) return bits; } -static inline unsigned int block_size(struct block_device *bdev) -{ - return 1 << bdev->bd_inode->i_blkbits; -} - int kblockd_schedule_work(struct work_struct *work); int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); @@ -1289,6 +1284,16 @@ static inline struct block_device *I_BDEV(struct inode *inode) return &BDEV_I(inode)->bdev; } +static inline struct inode *bdev_get_inode(struct block_device *bdev) +{ + return &container_of(bdev, struct bdev_inode, bdev)->vfs_inode; +} + +static inline unsigned int block_size(struct block_device *bdev) +{ + return 1 << bdev_get_inode(bdev)->i_blkbits; +} + #ifdef CONFIG_BLOCK void invalidate_bdev(struct block_device *bdev); int sync_blockdev(struct block_device *bdev); -- 2.33.0