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 v2] blk: avoid divide-by-zero with zero granularity
Date: Tue, 12 Jan 2021 23:55:02 +0800 [thread overview]
Message-ID: <20210112155502.426331-1-fengli@smartx.com> (raw)
In-Reply-To: <20210112152951.154024-1-fengli@smartx.com>
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 | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f94ee3089e01..ffffb04ad113 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1485,7 +1485,11 @@ 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);
- unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT)
+ unsigned int alignment;
+ if (granularity >> SECTOR_SHIFT == 0)
+ return 0;
+
+ alignment = sector_div(sector, granularity >> SECTOR_SHIFT)
<< SECTOR_SHIFT;
return (granularity + lim->alignment_offset - alignment) % granularity;
--
2.29.2
next prev parent reply other threads:[~2021-01-12 15:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 15:29 [PATCH] blk: avoid divide-by-zero with zero granularity Li Feng
2021-01-12 15:34 ` Feng Li
2021-01-12 15:55 ` Li Feng [this message]
2021-01-12 17:10 ` [PATCH v2] " 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=20210112155502.426331-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).