[07/10] block: mspro_blk: use blk_is_valid_logical_block_size
diff mbox series

Message ID 20200721105239.8270-8-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
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 drivers/memstick/core/mspro_block.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Damien Le Moal July 21, 2020, 11:17 a.m. UTC | #1
On 2020/07/21 19:55, Maxim Levitsky wrote:
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
>  drivers/memstick/core/mspro_block.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
> index cd6b8d4f23350..86c9eb0aef512 100644
> --- a/drivers/memstick/core/mspro_block.c
> +++ b/drivers/memstick/core/mspro_block.c
> @@ -1199,6 +1199,12 @@ static int mspro_block_init_disk(struct memstick_dev *card)
>  
>  	msb->page_size = be16_to_cpu(sys_info->unit_size);
>  
> +	if (!(blk_is_valid_logical_block_size(msb->page_size))) {
> +		dev_warn(&card->dev,
> +			 "unsupported block size %d", msb->page_size);
> +		return -EINVAL;
> +	}
> +
>  	mutex_lock(&mspro_block_disk_lock);
>  	disk_id = idr_alloc(&mspro_block_disk_idr, card, 0, 256, GFP_KERNEL);
>  	mutex_unlock(&mspro_block_disk_lock);
> 

Looks good to me.

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

Patch
diff mbox series

diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index cd6b8d4f23350..86c9eb0aef512 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -1199,6 +1199,12 @@  static int mspro_block_init_disk(struct memstick_dev *card)
 
 	msb->page_size = be16_to_cpu(sys_info->unit_size);
 
+	if (!(blk_is_valid_logical_block_size(msb->page_size))) {
+		dev_warn(&card->dev,
+			 "unsupported block size %d", msb->page_size);
+		return -EINVAL;
+	}
+
 	mutex_lock(&mspro_block_disk_lock);
 	disk_id = idr_alloc(&mspro_block_disk_idr, card, 0, 256, GFP_KERNEL);
 	mutex_unlock(&mspro_block_disk_lock);