Skip to content

Commit 570b1ca

Browse files
YongjiXieaxboe
authored andcommitted
block: Add a helper to validate the block size
There are some duplicated codes to validate the block size in block drivers. This limitation actually comes from block layer, so this patch tries to add a new block layer helper for that. Signed-off-by: Xie Yongji <xieyongji@bytedance.com> Link: https://lore.kernel.org/r/20211026144015.188-2-xieyongji@bytedance.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c7b84d4 commit 570b1ca

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎include/linux/blkdev.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ struct blk_crypto_profile;
4444
*/
4545
#define BLKCG_MAX_POLS 6
4646

47+
static inline int blk_validate_block_size(unsigned int bsize)
48+
{
49+
if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
50+
return -EINVAL;
51+
52+
return 0;
53+
}
54+
4755
static inline bool blk_op_is_passthrough(unsigned int op)
4856
{
4957
op &= REQ_OP_MASK;

0 commit comments

Comments
 (0)