History

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.

Xie Yongji committed 5 years ago

Commit 570b1ca1 parent c7b84d41 file · +8 −0Browse files

Showing the changes to include/linux/blkdev.h (1 of 1 file). Show all

Unified · Split

include/linux/blkdev.h+8−0
@@ -44,6 +44,14 @@ struct blk_crypto_profile; · 43 unmodified lines
44 */44 */
45#define BLKCG_MAX_POLS 645#define BLKCG_MAX_POLS 6
46 46
47static 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
47static inline bool blk_op_is_passthrough(unsigned int op)55static inline bool blk_op_is_passthrough(unsigned int op)
48{56{
49 op &= REQ_OP_MASK;57 op &= REQ_OP_MASK;