stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tadeusz Struk <tadeusz.struk@linaro.org>
To: stable@vger.kernel.org
Cc: tadeusz.struk@linaro.org, axboe@kernel.dk, hch@lst.de,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+662448179365dddc1880@syzkaller.appspotmail.com,
	xieyongji@bytedance.com
Subject: [PATCH 5.15] block: Add a helper to validate the block size
Date: Thu, 18 Nov 2021 15:57:38 -0800	[thread overview]
Message-ID: <20211118235738.1128085-1-tadeusz.struk@linaro.org> (raw)
In-Reply-To: <7e6c4c23-f071-f33b-7bd4-da11980d34c6@linaro.org>

From: Xie Yongji <xieyongji@bytedance.com>

From: Xie Yongji <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>
Link: https://lore.kernel.org/r/20211026144015.188-2-xieyongji@bytedance.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org>
---
 include/linux/blkdev.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 683aee365420..5b03795ae33b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -54,6 +54,14 @@ struct blk_keyslot_manager;
  */
 #define BLKCG_MAX_POLS		6
 
+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;
+}
+
 typedef void (rq_end_io_fn)(struct request *, blk_status_t);
 
 /*
-- 
2.33.1


  reply	other threads:[~2021-11-18 23:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 23:08 general protection fault in bdev_read_page Tadeusz Struk
2021-11-18 23:57 ` Tadeusz Struk [this message]
2021-11-19  1:55   ` [PATCH 5.15] block: Add a helper to validate the block size Damien Le Moal
2021-11-19  2:41     ` Tadeusz Struk
2021-11-19  2:53       ` Damien Le Moal
2021-11-18 23:57 ` [PATCH 5.14] " Tadeusz Struk
2021-11-18 23:58 ` [PATCH 5.10] " Tadeusz Struk
2021-11-19 12:45 ` general protection fault in bdev_read_page Greg KH

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=20211118235738.1128085-1-tadeusz.struk@linaro.org \
    --to=tadeusz.struk@linaro.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+662448179365dddc1880@syzkaller.appspotmail.com \
    --cc=xieyongji@bytedance.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).