diff options
author | Yu Kuai <yukuai3@huawei.com> | 2024-04-11 16:53:46 +0200 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2024-05-03 08:36:21 +0200 |
commit | c9600c63a694249100e2bdcbb604c30d8fee2dc7 (patch) | |
tree | 8548a92f890b53042aa18b7c95d1aec783b1725a /drivers/mtd | |
parent | dm-vdo: use bdev_nr_bytes(bdev) instead of i_size_read(bdev->bd_inode) (diff) | |
download | linux-c9600c63a694249100e2bdcbb604c30d8fee2dc7.tar.xz linux-c9600c63a694249100e2bdcbb604c30d8fee2dc7.zip |
block2mtd: prevent direct access of bd_inode
All we need is size, and that can be obtained via bdev_nr_bytes()
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/r/20240411145346.2516848-11-viro@zeniv.linux.org.uk
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/devices/block2mtd.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index caacdc0a3819..b06c8dd51562 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -265,6 +265,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, struct file *bdev_file; struct block_device *bdev; struct block2mtd_dev *dev; + loff_t size; char *name; if (!devname) @@ -291,7 +292,8 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, goto err_free_block2mtd; } - if ((long)bdev->bd_inode->i_size % erase_size) { + size = bdev_nr_bytes(bdev); + if ((long)size % erase_size) { pr_err("erasesize must be a divisor of device size\n"); goto err_free_block2mtd; } @@ -309,7 +311,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, dev->mtd.name = name; - dev->mtd.size = bdev->bd_inode->i_size & PAGE_MASK; + dev->mtd.size = size & PAGE_MASK; dev->mtd.erasesize = erase_size; dev->mtd.writesize = 1; dev->mtd.writebufsize = PAGE_SIZE; |