All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xie Yongji <xieyongji@bytedance.com>
To: axboe@kernel.dk, hch@lst.de, josef@toxicpanda.com,
	mst@redhat.com, jasowang@redhat.com, stefanha@redhat.com,
	kwolf@redhat.com
Cc: linux-block@vger.kernel.org, nbd@other.debian.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH v3 1/4] block: Add a helper to validate the block size
Date: Tue, 26 Oct 2021 22:40:12 +0800	[thread overview]
Message-ID: <20211026144015.188-2-xieyongji@bytedance.com> (raw)
In-Reply-To: <20211026144015.188-1-xieyongji@bytedance.com>

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>
---
 include/linux/blkdev.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 12b9dbcc980e..805cd02d7914 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -235,6 +235,14 @@ struct request {
 	void *end_io_data;
 };
 
+static inline int blk_validate_block_size(unsigned int bsize)
+{
+	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
+		return -EINVAL;
+
+	return 0;
+}
+
 static inline bool blk_op_is_passthrough(unsigned int op)
 {
 	op &= REQ_OP_MASK;
-- 
2.11.0


  reply	other threads:[~2021-10-26 14:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26 14:40 [PATCH v3 0/4] Add blk_validate_block_size() helper for drivers to validate block size Xie Yongji
2021-10-26 14:40 ` Xie Yongji [this message]
2021-10-26 14:40 ` [PATCH v3 2/4] nbd: Use blk_validate_block_size() " Xie Yongji
2021-10-26 14:40 ` [PATCH v3 3/4] loop: " Xie Yongji
2021-10-26 14:40 ` [PATCH v3 4/4] virtio-blk: " Xie Yongji
2021-10-27 19:58   ` Michael S. Tsirkin
2021-10-27 19:58     ` Michael S. Tsirkin
2021-10-27 20:16 ` [PATCH v3 0/4] Add blk_validate_block_size() helper for drivers " Jens Axboe
2021-10-27 20:16   ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211026144015.188-2-xieyongji@bytedance.com \
    --to=xieyongji@bytedance.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=jasowang@redhat.com \
    --cc=josef@toxicpanda.com \
    --cc=kwolf@redhat.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=nbd@other.debian.org \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.