diff mbox series

[RFC,v4,linux-next,16/19] block2mtd: prevent direct access of bd_inode

Message ID 20240222124555.2049140-17-yukuai1@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series fs & block: remove bdev->bd_inode | expand

Commit Message

Yu Kuai Feb. 22, 2024, 12:45 p.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

Now that block2mtd stash the file of opened bdev, it's ok to get inode
from the file.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/mtd/devices/block2mtd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Jan Kara March 15, 2024, 3:12 p.m. UTC | #1
On Thu 22-02-24 20:45:52, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Now that block2mtd stash the file of opened bdev, it's ok to get inode
> from the file.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  drivers/mtd/devices/block2mtd.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
> index 97a00ec9a4d4..e9ecb3286dcb 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 = i_size_read(file_inode(bdev_file));
> +	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;
> -- 
> 2.39.2
>
Christoph Hellwig March 17, 2024, 9:36 p.m. UTC | #2
On Thu, Feb 22, 2024 at 08:45:52PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Now that block2mtd stash the file of opened bdev, it's ok to get inode
> from the file.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

(not that block2mtd would also significantly benefit from using the
normal file based APIs for accessing the underlying block device.  No
need to do that in this series, though)
diff mbox series

Patch

diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 97a00ec9a4d4..e9ecb3286dcb 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 = i_size_read(file_inode(bdev_file));
+	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;