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
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;