diff mbox series

[22/44] block: opencode devcgroup_inode_permission

Message ID 20201126130422.92945-23-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/44] blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats | expand

Commit Message

Christoph Hellwig Nov. 26, 2020, 1:04 p.m. UTC
Just call devcgroup_check_permission to avoid various superflous checks
and a double conversion of the access flags.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Tejun Heo <tj@kernel.org>
---
 fs/block_dev.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Jan Kara Nov. 26, 2020, 3:07 p.m. UTC | #1
On Thu 26-11-20 14:04:00, Christoph Hellwig wrote:
> Just call devcgroup_check_permission to avoid various superflous checks
> and a double conversion of the access flags.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Acked-by: Tejun Heo <tj@kernel.org>

Looks good. You can add:

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

								Honza

> ---
>  fs/block_dev.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index d0783c55a0ce65..b12ab68297baf3 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -1516,15 +1516,13 @@ static int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
>  	struct block_device *claiming;
>  	bool unblock_events = true;
>  	struct gendisk *disk;
> -	int perm = 0;
>  	int partno;
>  	int ret;
>  
> -	if (mode & FMODE_READ)
> -		perm |= MAY_READ;
> -	if (mode & FMODE_WRITE)
> -		perm |= MAY_WRITE;
> -	ret = devcgroup_inode_permission(bdev->bd_inode, perm);
> +	ret = devcgroup_check_permission(DEVCG_DEV_BLOCK,
> +			imajor(bdev->bd_inode), iminor(bdev->bd_inode),
> +			((mode & FMODE_READ) ? DEVCG_ACC_READ : 0) |
> +			((mode & FMODE_WRITE) ? DEVCG_ACC_WRITE : 0));
>  	if (ret)
>  		goto bdput;
>  
> -- 
> 2.29.2
>
diff mbox series

Patch

diff --git a/fs/block_dev.c b/fs/block_dev.c
index d0783c55a0ce65..b12ab68297baf3 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1516,15 +1516,13 @@  static int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
 	struct block_device *claiming;
 	bool unblock_events = true;
 	struct gendisk *disk;
-	int perm = 0;
 	int partno;
 	int ret;
 
-	if (mode & FMODE_READ)
-		perm |= MAY_READ;
-	if (mode & FMODE_WRITE)
-		perm |= MAY_WRITE;
-	ret = devcgroup_inode_permission(bdev->bd_inode, perm);
+	ret = devcgroup_check_permission(DEVCG_DEV_BLOCK,
+			imajor(bdev->bd_inode), iminor(bdev->bd_inode),
+			((mode & FMODE_READ) ? DEVCG_ACC_READ : 0) |
+			((mode & FMODE_WRITE) ? DEVCG_ACC_WRITE : 0));
 	if (ret)
 		goto bdput;