[03/10] block: loop: use blk_is_valid_logical_block_size
diff mbox series

Message ID 20200721105239.8270-4-mlevitsk@redhat.com
State New
Headers show
Series
  • RFC: move logical block size checking to the block core
Related show

Commit Message

Maxim Levitsky July 21, 2020, 10:52 a.m. UTC
This allows to remove loop's own check for supported block size

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 drivers/block/loop.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

Comments

Damien Le Moal July 21, 2020, 11:08 a.m. UTC | #1
On 2020/07/21 19:54, Maxim Levitsky wrote:
> This allows to remove loop's own check for supported block size
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
>  drivers/block/loop.c | 23 +++++------------------
>  1 file changed, 5 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 475e1a738560d..9984c8f824271 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -228,19 +228,6 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
>  		blk_mq_unfreeze_queue(lo->lo_queue);
>  }
>  
> -/**
> - * loop_validate_block_size() - validates the passed in block size
> - * @bsize: size to validate
> - */
> -static int
> -loop_validate_block_size(unsigned short bsize)
> -{
> -	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
> -		return -EINVAL;
> -
> -	return 0;
> -}
> -
>  /**
>   * loop_set_size() - sets device size and notifies userspace
>   * @lo: struct loop_device to set the size for
> @@ -1119,9 +1106,10 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
>  	}
>  
>  	if (config->block_size) {
> -		error = loop_validate_block_size(config->block_size);
> -		if (error)
> +		if (!blk_is_valid_logical_block_size(config->block_size)) {
> +			error = -EINVAL;
>  			goto out_unlock;
> +		}
>  	}
>  
>  	error = loop_set_status_from_info(lo, &config->info);
> @@ -1607,9 +1595,8 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
>  	if (lo->lo_state != Lo_bound)
>  		return -ENXIO;
>  
> -	err = loop_validate_block_size(arg);
> -	if (err)
> -		return err;
> +	if (!blk_is_valid_logical_block_size(arg))
> +		return -EINVAL;
>  
>  	if (lo->lo_queue->limits.logical_block_size == arg)
>  		return 0;
> 

Looks good to me.

Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>

Patch
diff mbox series

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 475e1a738560d..9984c8f824271 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -228,19 +228,6 @@  static void __loop_update_dio(struct loop_device *lo, bool dio)
 		blk_mq_unfreeze_queue(lo->lo_queue);
 }
 
-/**
- * loop_validate_block_size() - validates the passed in block size
- * @bsize: size to validate
- */
-static int
-loop_validate_block_size(unsigned short bsize)
-{
-	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
-		return -EINVAL;
-
-	return 0;
-}
-
 /**
  * loop_set_size() - sets device size and notifies userspace
  * @lo: struct loop_device to set the size for
@@ -1119,9 +1106,10 @@  static int loop_configure(struct loop_device *lo, fmode_t mode,
 	}
 
 	if (config->block_size) {
-		error = loop_validate_block_size(config->block_size);
-		if (error)
+		if (!blk_is_valid_logical_block_size(config->block_size)) {
+			error = -EINVAL;
 			goto out_unlock;
+		}
 	}
 
 	error = loop_set_status_from_info(lo, &config->info);
@@ -1607,9 +1595,8 @@  static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
 	if (lo->lo_state != Lo_bound)
 		return -ENXIO;
 
-	err = loop_validate_block_size(arg);
-	if (err)
-		return err;
+	if (!blk_is_valid_logical_block_size(arg))
+		return -EINVAL;
 
 	if (lo->lo_queue->limits.logical_block_size == arg)
 		return 0;