From: Li Feng <fengli@smartx.com>
To: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org (open list:BLOCK LAYER),
linux-kernel@vger.kernel.org (open list)
Cc: lifeng1519@gmail.com, Li Feng <fengli@smartx.com>
Subject: [PATCH] blk: avoid divide-by-zero with zero granularity
Date: Tue, 12 Jan 2021 23:29:51 +0800 [thread overview]
Message-ID: <20210112152951.154024-1-fengli@smartx.com> (raw)
If the physical_block_size and io_min is less than a sector, the
'granularity >> SECTOR_SHIFT' will be zero.
Signed-off-by: Li Feng <fengli@smartx.com>
---
include/linux/blkdev.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f94ee3089e01..4d029e95adb4 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1485,6 +1485,10 @@ static inline int queue_alignment_offset(const struct request_queue *q)
static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
{
unsigned int granularity = max(lim->physical_block_size, lim->io_min);
+ granularity = granularity >> SECTOR_SHIFT;
+ if (!granularity)
+ return 0;
+
unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT)
<< SECTOR_SHIFT;
--
2.29.2
next reply other threads:[~2021-01-12 15:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 15:29 Li Feng [this message]
2021-01-12 15:34 ` [PATCH] blk: avoid divide-by-zero with zero granularity Feng Li
2021-01-12 15:55 ` [PATCH v2] " Li Feng
2021-01-12 17:10 ` Martin K. Petersen
2021-01-12 17:27 ` Feng Li
2021-01-12 17:36 ` Johannes Thumshirn
2021-01-12 17:46 ` Martin K. Petersen
2021-01-13 2:42 ` Li Feng
2021-01-12 18:42 ` [PATCH] " kernel test robot
2021-01-12 21:49 ` kernel test robot
2021-01-12 22:57 ` kernel test robot
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=20210112152951.154024-1-fengli@smartx.com \
--to=fengli@smartx.com \
--cc=axboe@kernel.dk \
--cc=lifeng1519@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 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).